public JavaScriptAst Create() { CreateTokenStream(); var parser = new ES3Parser(tokenStream); programReturn = parser.program(); return(new JavaScriptAst(tokenStream, programReturn.Tree as CommonTree)); }
public static IList <JsStatement> ParseProgram(string source) { var lex = new ES3Lexer(new ANTLRStringStream(source)); CommonTokenStream tokens = new CommonTokenStream(lex); var parser = new ES3Parser(tokens); var r = parser.program(); var tree = new ES3Walker(new CommonTreeNodeStream(r.Tree)); return(tree.program()); }
public static JsStatement ParseStatement(string source) { var lex = new ES3Lexer(new ANTLRStringStream(source.Trim())); CommonTokenStream tokens = new CommonTokenStream(lex); var parser = new ES3Parser(tokens); var r = parser.sourceElement(); var tree = new ES3Walker(new CommonTreeNodeStream(r.Tree)); return(tree.statement()); }
public static JsExpression ParseExpression(string source) { var lex = new ES3Lexer(new ANTLRStringStream(source)); CommonTokenStream tokens = new CommonTokenStream(lex); var parser = new ES3Parser(tokens); var r = parser.expression(); var tree = new ES3Walker(new CommonTreeNodeStream(r.Tree)); return(tree.expression()); }
public static JsStatement ParseStatement(string source, bool allowCustomKeywords = false) { var lex = new ES3Lexer(new ANTLRStringStream(source.Trim())) { AllowCustomKeywords = allowCustomKeywords }; var tokens = new CommonTokenStream(lex); var parser = new ES3Parser(tokens); var r = parser.sourceElement(); var tree = new ES3Walker(new CommonTreeNodeStream(r.Tree)); return(tree.statement()); }
public static JsExpression ParseExpression(string source, bool allowCustomKeywords = false) { var lex = new ES3Lexer(new ANTLRStringStream(source)) { AllowCustomKeywords = allowCustomKeywords }; var tokens = new CommonTokenStream(lex); var parser = new ES3Parser(tokens); var r = parser.expressionOnly(); var tree = new ES3Walker(new CommonTreeNodeStream(r.Tree)); return(tree.expression()); }
public static Program Compile(string source, bool debugInformation) { Program program = null; if (!string.IsNullOrEmpty(source)) { var lexer = new ES3Lexer(new ANTLRStringStream(source)); var parser = new ES3Parser(new CommonTokenStream(lexer)) { DebugMode = debugInformation }; program = parser.program().value; if (parser.Errors != null && parser.Errors.Count > 0) { throw new JintException(String.Join(Environment.NewLine, parser.Errors.ToArray())); } } return program; }
public static Program Compile(string source, bool debugInformation) { Program program = (Program)null; if (!string.IsNullOrEmpty(source)) { ES3Parser es3Parser = new ES3Parser((ITokenStream) new CommonTokenStream((ITokenSource) new ES3Lexer((ICharStream) new ANTLRStringStream(source)))) { DebugMode = debugInformation }; program = es3Parser.program().value; if (es3Parser.Errors != null && es3Parser.Errors.Count > 0) { throw new JintException(string.Join(Environment.NewLine, es3Parser.Errors.ToArray())); } } return(program); }
internal void Analyze(List<string> Codes) { RawLines.Clear(); StringBuilder CodeBuilder = new StringBuilder(); foreach (string C in Codes) { RawLines.AddRange(C.Split(new string[] { "\r\n" }, StringSplitOptions.None)); CodeBuilder.Append(C); } string Code = CodeBuilder.ToString(); if (Code.Length == 0) return; JintEngine Eng = new JintEngine(Options.Ecmascript3); ES3Lexer Lexer = new ES3Lexer(new ANTLRStringStream(Code)); ES3Parser Parser = new ES3Parser(new CommonTokenStream(Lexer)) { DebugMode = true }; Jint.Expressions.Program Prog = Parser.program().value; JintStack.Clear(); Analyze(Prog.Statements); }
internal static LinkedList<Statement> GetStatementsFromCode(List<string> Codes, bool IgnoreErrors) { StringBuilder CodeBuilder = new StringBuilder(); foreach (string C in Codes) { CodeBuilder.Append(C); if (!C.EndsWith("\n")) { CodeBuilder.Append("\r\n"); } } string Code = CodeBuilder.ToString(); if (Code.Length == 0) return new LinkedList<Statement>(); JintEngine Eng = new JintEngine(Options.Ecmascript3); ES3Lexer Lexer = new ES3Lexer(new ANTLRStringStream(Code)); ES3Parser Parser = new ES3Parser(new CommonTokenStream(Lexer)) { DebugMode = true }; Jint.Expressions.Program Prog = Parser.program().value; if (Parser.Errors != null && Parser.Errors.Count > 0 && !IgnoreErrors) { throw new Exception("Invalid JavaScript Syntax"); } return Prog.Statements; }