@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
41 lines (30 loc) • 953 B
text/typescript
import { Parser, Grammar } from "nearley";
import grammar from "../../ts/nasl";
const call1 = `
declare logic logic3() => Integer;
logic trailingSubLogic() {
let x = logic3() { e3 => 1 + 2 }
}
`
const call2 = `
declare logic logic1(x: Integer);
declare logic logic2();
declare logic logic4();
logic lambdaInTrailingSubLogic () {
let x = logic1(100) { e1 => 1 };
let y = logic2() { e2 => { e2 => 1 + 2 } };
let z = logic4() { e3 => { e2 => { e1 => true && false } } };
}
`
describe('Test Lambda and Call Suffix Syntax', () => {
test('Trailing SubLogic', async () => {
const parser = new Parser(Grammar.fromCompiled(grammar));
parser.feed(call1);
expect(parser.results.length).toBe(1);
});
test('Lambda in trailing SubLogic', async () => {
const parser = new Parser(Grammar.fromCompiled(grammar));
parser.feed(call2);
expect(parser.results.length).toBe(1);
});
});