UNPKG

@lcap/nasl-parser

Version:

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

21 lines (17 loc) 490 B
import { Parser, Grammar } from "nearley"; import grammar from "../../ts/nasl"; const testWhile = ` logic testWhile() { while (true && true && false) { x = 100 } } ` describe('Test While', () => { test('test while', async () => { const parser = new Parser(Grammar.fromCompiled(grammar)); parser.feed(testWhile); expect(parser.results.length).toBe(1); expect(parser.results[0].cst[0].body.stmts[0]['__type']).toBe('While'); }); });