/// <summary> /// Scans for a function entry. /// </summary> /// <param name="engine">The current parse engine.</param> /// <returns>The created expression.</returns> public override Expression Scan(ParseEngine engine) { var start = engine.Pointer; var kw = new FunctionKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query); engine.Advance(Token.Length).Skip(); if (engine.Pointer == engine.Characters.Length) { kw.Length = engine.Pointer - start; engine.AddError(new YAMPFunctionNameMissing(engine), kw); return kw; } kw.name = engine.Elements.FindExpression<SymbolExpression>().Scan(engine) as SymbolExpression; if (kw.name == null) { engine.AddError(new YAMPFunctionNameMissing(engine), kw); return kw; } engine.Skip(); if (engine.Pointer == engine.Characters.Length) { kw.Length = engine.Pointer - start; engine.AddError(new YAMPFunctionArgumentsMissing(engine), kw); return kw; } kw.arguments = engine.Elements.FindExpression<BracketExpression>().Scan(engine) as BracketExpression; if (engine.Pointer == engine.Characters.Length) { kw.Length = engine.Pointer - start; engine.AddError(new YAMPFunctionBodyMissing(engine), kw.arguments); return kw; } kw.Body = engine.ParseStatement(); kw.Length = engine.Pointer - start; if (kw.Body.Container.Expressions.Length == 1 && kw.Body.Container.Expressions[0] is GroupExpression) { var container = (GroupExpression)kw.Body.Container.Expressions[0]; var context = new ParseContext(engine.Context.Parent); var input = container.Scope.Input; container.Scope = new QueryContext(context, input); } else { engine.AddError(new YAMPFunctionBodyMissing(engine), kw.arguments); return kw; } if (kw.arguments == null) { engine.AddError(new YAMPFunctionArgumentsMissing(engine), kw); return kw; } else if (kw.arguments.HasContent && !kw.arguments.IsSymbolList) { engine.AddError(new YAMPFunctionArgumentsSymbols(engine), kw.arguments); return kw; } return kw; }
/// <summary> /// Scans for a function entry. /// </summary> /// <param name="engine">The current parse engine.</param> /// <returns>The created expression.</returns> public override Expression Scan(ParseEngine engine) { var start = engine.Pointer; var kw = new FunctionKeyword(engine.CurrentLine, engine.CurrentColumn, engine.Query); engine.Advance(Token.Length).Skip(); if (engine.Pointer == engine.Characters.Length) { kw.Length = engine.Pointer - start; engine.AddError(new YAMPFunctionNameMissing(engine), kw); return(kw); } kw.name = engine.Elements.FindExpression <SymbolExpression>().Scan(engine) as SymbolExpression; if (kw.name == null) { engine.AddError(new YAMPFunctionNameMissing(engine), kw); return(kw); } engine.Skip(); if (engine.Pointer == engine.Characters.Length) { kw.Length = engine.Pointer - start; engine.AddError(new YAMPFunctionArgumentsMissing(engine), kw); return(kw); } kw.arguments = engine.Elements.FindExpression <BracketExpression>().Scan(engine) as BracketExpression; if (engine.Pointer == engine.Characters.Length) { kw.Length = engine.Pointer - start; engine.AddError(new YAMPFunctionBodyMissing(engine), kw.arguments); return(kw); } kw.Body = engine.ParseStatement(); kw.Length = engine.Pointer - start; if (kw.Body.Container.Expressions.Length == 1 && kw.Body.Container.Expressions[0] is GroupExpression) { var container = (GroupExpression)kw.Body.Container.Expressions[0]; var context = new ParseContext(engine.Context.Parent); var input = container.Scope.Input; container.Scope = new QueryContext(context, input); } else { engine.AddError(new YAMPFunctionBodyMissing(engine), kw.arguments); return(kw); } if (kw.arguments == null) { engine.AddError(new YAMPFunctionArgumentsMissing(engine), kw); return(kw); } else if (kw.arguments.HasContent && !kw.arguments.IsSymbolList) { engine.AddError(new YAMPFunctionArgumentsSymbols(engine), kw.arguments); return(kw); } return(kw); }