Skip to content

Instantly share code, notes, and snippets.

@amazzalel-habib
Last active May 11, 2020 01:19
Show Gist options
  • Save amazzalel-habib/6fe31ff798012fc8c136080bc39c4a78 to your computer and use it in GitHub Desktop.
Save amazzalel-habib/6fe31ff798012fc8c136080bc39c4a78 to your computer and use it in GitHub Desktop.
import { TodoLangGrammarParser, TodoExpressionsContext } from "../ANTLR/TodoLangGrammarParser";
import { TodoLangGrammarLexer } from "../ANTLR/TodoLangGrammarLexer";
import { ANTLRInputStream, CommonTokenStream } from "antlr4ts";
export default function parseAndGetASTRoot(code: string): TodoExpressionsContext {
const inputStream = new ANTLRInputStream(code);
const lexer = new TodoLangGrammarLexer(inputStream);
const tokenStream = new CommonTokenStream(lexer);
const parser = new TodoLangGrammarParser(tokenStream);
// Parse the input, where `compilationUnit` is whatever entry point you defined
return parser.todoExpressions();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment