/// <summary> /// Parses a block by first pushing symbol scope and then popping after completion. /// </summary> public virtual void ParseBlock(IBlockExpr stmt) { this.Ctx.Symbols.Push(new SymbolsNested(string.Empty), true); stmt.SymScope = this.Ctx.Symbols.Current; _parser.ParseBlock(stmt); this.Ctx.Symbols.Pop(); }
/// <summary> /// Parses a block by first pushing symbol scope and then popping after completion. /// </summary> public override void ParseBlock(IBlockExpr stmt) { var fs = stmt as FunctionExpr; // 1. Define the function in global symbol scope var funcSymbol = new SymbolFunction(fs.Meta); funcSymbol.FuncExpr = stmt; // 2. Push the current scope. stmt.SymScope = this.Ctx.Symbols.Current; this.Ctx.Symbols.Push(new SymbolsFunction(string.Empty), true); // 3. Parse the function block _parser.ParseBlock(stmt); // 4. Pop the symbols scope. this.Ctx.Symbols.Pop(); }
/// <summary> /// Parses a block by first pushing symbol scope and then popping after completion. /// </summary> public override void ParseBlock(IBlockExpr stmt) { var fs = stmt as FunctionExpr; var funcName = fs.Meta.Name; // 1. Define the function in global symbol scope var funcSymbol = new SymbolFunction(fs.Meta) { FuncExpr = stmt }; Ctx.Symbols.Define(funcSymbol); // 2. Define the aliases. if (fs.Meta.Aliases?.Count > 0) { foreach (var alias in fs.Meta.Aliases) { Ctx.Symbols.DefineAlias(alias, fs.Meta.Name); } } // 3. Push the current scope. stmt.SymScope = Ctx.Symbols.Current; Ctx.Symbols.Push(new SymbolsFunction(fs.Meta.Name), true); // 4. Register the parameter names in the symbol scope. if (fs.Meta.Arguments?.Count > 0) { foreach (var arg in fs.Meta.Arguments) { Ctx.Symbols.DefineVariable(arg.Name, LTypes.Object); } } _parser.ParseBlock(stmt); Ctx.Symbols.Pop(); }
/// <summary> /// Parses a block by first pushing symbol scope and then popping after completion. /// </summary> public void ParseBlock(IBlockExpr expr) { this._parser.Context.Symbols.Push(new SymbolsNested(string.Empty), true); expr.SymScope = this._parser.Context.Symbols.Current; var withPush = false; if (expr is ForEachExpr) { var foreachExpr = expr as ForEachExpr; if (foreachExpr.EnableAutoVariable) { var name = foreachExpr.VarName; Exprs.WithPush(name); withPush = true; } } this._parser.ParseBlock(expr); this._parser.Context.Symbols.Pop(); if (withPush) { Exprs.WithPop(); } }
/// <summary> /// Barses a block of code. /// </summary> /// <param name="block"></param> /// <returns></returns> public IBlockExpr ParseBlock(IBlockExpr block) { // { statemnt1; statement2; } bool isMultiLine = false; // Check for single line block if (_tokenIt.NextToken.Token == Tokens.NewLine) _tokenIt.Advance(); if (_tokenIt.NextToken.Token == Tokens.LeftBrace) isMultiLine = true; if (block == null) block = new BlockExpr(); // Case 1: Single line block. if (!isMultiLine) { var stmt = ParseStatement(); stmt.Parent = block as AstNode; block.Statements.Add(stmt); return block; } // Case 2: Multi-line block _tokenIt.Expect(Tokens.LeftBrace); while (true) { // Check for end of statment or invalid end of script. if (IsEndOfStatementOrEndOfScript(Tokens.RightBrace)) break; // New line? if (_tokenIt.NextToken.Token == Tokens.NewLine) { _tokenIt.Advance(); continue; } var stmt = ParseStatement(); if (stmt != null) { stmt.Parent = block as AstNode; block.Statements.Add(stmt); } } Expect(Tokens.RightBrace); return block; }
/// <summary> /// Parses a block by first pushing symbol scope and then popping after completion. /// </summary> public void ParseBlock(IBlockExpr expr) { this._parser.Context.Symbols.Push(new SymbolsNested(string.Empty), true); expr.SymScope = this._parser.Context.Symbols.Current; this._parser.ParseBlock(expr); this._parser.Context.Symbols.Pop(); }
/// <summary> /// Parses a block by first pushing symbol scope and then popping after completion. /// </summary> public void ParseBlock(IBlockExpr expr) { this._parser.Context.Symbols.Push(new SymbolsNested(string.Empty), true); expr.SymScope = this._parser.Context.Symbols.Current; var withPush = false; if (expr is ForEachExpr) { var foreachExpr = expr as ForEachExpr; if (foreachExpr.EnableAutoVariable) { var name = foreachExpr.VarName; Exprs.WithPush(name); withPush = true; } } this._parser.ParseBlock(expr); this._parser.Context.Symbols.Pop(); if (withPush) Exprs.WithPop(); }