@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
40 lines (35 loc) • 1.08 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() { }
}
}
logic logic1() {
let aaa: List<app::dataSources::defaultDS::entities::LCAPUserDeptMapping>
let bbb: List<app::structures::LCAPUserDeptMapping>
let ccc: app::dataSources::myDS::entities::AAAA
}
`
describe('Test qualified name resolution', () => {
test('qualified 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');
});
});