UNPKG

@lcap/nasl-parser

Version:

Take Nasl text to Nasl AST with the help of generalized parsing.

30 lines (24 loc) 665 B
import { Parser, Grammar } from "nearley"; import grammar from "../../ts/nasl"; // [ ] 语法歧义,需语义阶段重解析 const testStructCtor =` namespace app { struct TestSuit() { let juede: Integer; let zheyang: String; let haowanma: Boolean; } } using app; logic AAA() { let x = '1'; let y = TestSuit(juede = x.length, zheyang = 'hehe', haowanma = false); } ` describe('Struct Constructor...', () => { test('Struct Constructor 1', async () => { const parser = new Parser(Grammar.fromCompiled(grammar)); parser.feed(testStructCtor); expect(parser.results.length).toBe(1); }); });