protected static Node_FunctionDecl ExecuteClosureRemover(string code) { AntlrInputStream inputStream = new AntlrInputStream(code); LikeJavaScriptLexer lexer = new LikeJavaScriptLexer(inputStream); CommonTokenStream commonTokenStream = new CommonTokenStream(lexer); LikeJavaScriptParser parser = new LikeJavaScriptParser(commonTokenStream); var astBuilder = new CstToAstVisitor(); var ast = astBuilder.Visit(parser.compileUnit()) as Node_FunctionDecl; var closureRemover = new ClosureRemover.ClosureRemover(); closureRemover.RemoveClosures(ast); return(ast); }
static void RemoveClosures(StreamReader codeReader, StreamWriter codeWriter) { AntlrInputStream inputStream = new AntlrInputStream(codeReader); LikeJavaScriptLexer lexer = new LikeJavaScriptLexer(inputStream); CommonTokenStream commonTokenStream = new CommonTokenStream(lexer); LikeJavaScriptParser parser = new LikeJavaScriptParser(commonTokenStream); parser.RemoveErrorListeners(); parser.AddErrorListener(ThrowingErrorListener.INSTANCE); var astBuilder = new CstToAstVisitor(); var ast = astBuilder.Visit(parser.compileUnit()) as Node_FunctionDecl; var closureRemover = new ClosureRemover.ClosureRemover(); closureRemover.RemoveClosures(ast); var printer = new AstVisitor_Print(); printer.Print(codeWriter, ast); }