@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
21 lines • 842 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = parse;
const nearley_1 = require("nearley");
const nasl_1 = __importDefault(require("./nasl"));
const to_nasl_ast_1 = require("./toAST/to-nasl-ast");
function parse(code) {
const parser = new nearley_1.Parser(nearley_1.Grammar.fromCompiled(nasl_1.default));
parser.feed(code);
if (parser.results?.length === 0) {
throw new Error('Failed to parse');
}
if (parser.results?.length > 1) {
throw new Error('Grammar may be ambiguous. Choose the first result.');
}
return (0, to_nasl_ast_1.toNaslAST)(parser.results?.[0]?.nasl).toJSON();
}
//# sourceMappingURL=index.js.map