/// <summary> /// Parses the source text into an abstract syntax tree. /// </summary> public override void Parse() { using (var lexer = new Lexer(this.Engine, this.Source)) { var parser = new Parser(this.Engine, lexer, this.InitialScope, this.Options, CodeContext.Global); this.AbstractSyntaxTree = parser.Parse(); this.StrictMode = parser.StrictMode; this.MethodOptimizationHints = parser.MethodOptimizationHints; } }
/// <summary> /// Parses the source text into an abstract syntax tree. /// </summary> public override void Parse() { var lexer = new Lexer(this.Engine, this.Source); var parser = new Parser(this.Engine, lexer, this.InitialScope, this.Options, CodeContext.Eval); // If the eval() is running strict mode, create a new scope. parser.DirectivePrologueProcessedCallback = parser2 => { if (parser2.StrictMode == true) parser2.InitialScope = parser2.Scope = DeclarativeScope.CreateEvalScope(parser2.Scope); }; this.AbstractSyntaxTree = parser.Parse(); this.StrictMode = parser.StrictMode; this.InitialScope = parser.Scope; this.MethodOptimizationHints = parser.MethodOptimizationHints; }
// INITIALIZATION //_________________________________________________________________________________________ /// <summary> /// Creates a Parser instance with the given lexer supplying the tokens. /// </summary> /// <param name="engine"> The associated script engine. </param> /// <param name="lexer"> The lexical analyser that provides the tokens. </param> /// <param name="initialScope"> The initial variable scope. </param> /// <param name="options"> Options that influence the compiler. </param> /// <param name="context"> The context of the code (global, function or eval). </param> public Parser(ScriptEngine engine, Lexer lexer, Scope initialScope, CompilerOptions options, CodeContext context) { if (engine == null) throw new ArgumentNullException("engine"); if (lexer == null) throw new ArgumentNullException("lexer"); if (initialScope == null) throw new ArgumentNullException("initialScope"); this.engine = engine; this.lexer = lexer; this.lexer.ParserExpressionState = ParserExpressionState.Literal; this.currentScope = this.initialScope = initialScope; this.methodOptimizationHints = new MethodOptimizationHints(); this.options = options; this.context = context; this.StrictMode = options.ForceStrictMode; this.Consume(); }
/// <summary> /// Validates the given string is a valid identifier and returns the identifier name after /// escape sequences have been processed. /// </summary> /// <param name="engine"> The associated script engine. </param> /// <param name="str"> The string to resolve into an identifier. </param> /// <returns> The identifier name after escape sequences have been processed, or /// <c>null</c> if the string is not an identifier. </returns> internal static string ResolveIdentifier(ScriptEngine engine, string str) { var lexer = new Lexer(engine, new StringScriptSource(str)); var argumentToken = lexer.NextToken(); if ((argumentToken is IdentifierToken) == false || lexer.NextToken() != null) return null; return ((Compiler.IdentifierToken)argumentToken).Name; }
public LexerReader(Lexer lexer) { this.lexer = lexer; }
/// <summary> /// Parses the source text into an abstract syntax tree. /// </summary> /// <returns> The root node of the abstract syntax tree. </returns> public override void Parse() { if (this.BodyRoot != null) { this.AbstractSyntaxTree = this.BodyRoot; } else { using (var lexer = new Lexer(this.Engine, this.Source)) { var parser = new Parser(this.Engine, lexer, this.InitialScope, this.Options, CodeContext.Function); this.AbstractSyntaxTree = parser.Parse(); this.StrictMode = parser.StrictMode; this.MethodOptimizationHints = parser.MethodOptimizationHints; } Validate(); } }