@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
41 lines (33 loc) • 1.09 kB
text/typescript
import { Parser, Grammar } from "nearley";
import grammar from "../../ts/nasl";
import { toNaslAST } from "../../ts/toAST/to-nasl-ast";
const call1 = `
declare logic logic1(x: Integer, y: Integer, z: Integer);
logic namedUnnamedMixed ( ) {
let x = logic1(x = 3, y, z = 2);
}
`
const call2 = `
declare logic logic2(x: Integer, y: Integer);
declare logic logic5(x: Integer);
declare logic logic6(x: Integer);
logic simpleLamArg ( ) {
let x = logic2(x = 3, { (e1, e2) => e1});
let y = logic5(x = { e4 => e4 });
let z = logic6({ e5 => e5 });
}
`
describe('Test Logical Call', () => {
test('Named and unnamed arguments', async () => {
const parser = new Parser(Grammar.fromCompiled(grammar));
parser.feed(call1);
expect(parser.results.length).toBe(1);
toNaslAST(parser.results[0].nasl);
});
test('Simple lambda arguments', async () => {
const parser = new Parser(Grammar.fromCompiled(grammar));
parser.feed(call2);
expect(parser.results.length).toBe(1);
toNaslAST(parser.results[0].nasl);
});
});