Added default utility wrapper function

This commit is contained in:
Benjamin Bädorf 2020-11-25 03:57:10 +01:00
parent 3caad78015
commit b78122ac70
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C

View file

@ -1,3 +1,30 @@
export { default as Lexer } from "./Lexer.mjs";
export { default as Parser } from "./Parser.mjs";
export { default as visitorCreator } from "./visitor.mjs";
import Parser from "./Parser.mjs";
import Lexer from "./Lexer.mjs";
import visitorCreator from "./visitor.mjs";
export default (input) => {
const parser = new Parser([], { outputCst: true });
const lexingresult = Lexer.tokenize(input);
if (lexingresult.errors.length > 0) {
console.dir(lexingresult, { depth: Infinity });
throw new Error("Lexing errors detected")
}
parser.input = lexingresult.tokens;
const cst = parser.unitFile();
if (parser.errors.length > 0) {
console.dir(parser.errors, { depth: Infinity });
throw new Error("Parsing errors detected")
}
const Visitor = visitorCreator(parser);
const visitor = new Visitor();
const ast = visitor.visit(cst);
return ast;
}