@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
50 lines (44 loc) • 1.3 kB
text/typescript
import { Parser, Grammar } from "nearley";
import grammar from "../../ts/nasl";
import { toNaslAST } from "../../ts/toAST/to-nasl-ast";
const testStr = `
namespace app {
namespace dataSources {
namespace defaultDS {
namespace entities {
entity LCAPUserDeptMapping() { }
}
}
namespace myDS {
namespace entities {
entity AAAA() { }
}
}
}
namespace structures {
struct LCAPUserDeptMapping() { }
}
}
using app::dataSources;
using defaultDS::entities;
using myDS::entities;
using structures;
logic logic1() {
let aaa: List<app::dataSources::defaultDS::entities::LCAPUserDeptMapping>
let bbb: List<app::structures::LCAPUserDeptMapping>
let ccc: app::dataSources::myDS::entities::AAAA
}
logic logic2() {
let aaa: List<LCAPUserDeptMapping>
let bbb: List<LCAPUserDeptMapping>
let ccc: AAAA
}
`
describe('Test using namespace and name resolution', () => {
test('using namespace and type name resolution', async () => {
const parser = new Parser(Grammar.fromCompiled(grammar));
parser.feed(testStr);
expect(parser.results.length).toBe(1);
expect(toNaslAST(parser.results[0].nasl)?.concept).toBe('App');
});
});