public static bool TryParseNode(Genero4glParser parser, out PromptDisplayAttribute node) { node = new PromptDisplayAttribute(); node.StartIndex = parser.Token.Span.Start; bool result = true; switch (parser.PeekToken().Kind) { case TokenKind.BlackKeyword: case TokenKind.BlueKeyword: case TokenKind.CyanKeyword: case TokenKind.GreenKeyword: case TokenKind.MagentaKeyword: case TokenKind.RedKeyword: case TokenKind.WhiteKeyword: case TokenKind.YellowKeyword: case TokenKind.BoldKeyword: case TokenKind.DimKeyword: case TokenKind.InvisibleKeyword: case TokenKind.NormalKeyword: case TokenKind.ReverseKeyword: case TokenKind.BlinkKeyword: case TokenKind.UnderlineKeyword: parser.NextToken(); break; default: result = false; break; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out CloseStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.CloseKeyword)) { result = true; node = new CloseStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; FglNameExpression cid; if (FglNameExpression.TryParseNode(parser, out cid)) { node.CursorId = cid; } else { parser.ReportSyntaxError("Invalid declared cursor id found in close statement."); } node.EndIndex = parser.Token.Span.End; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out ActionAttributesListmodTriggers node) { node = new ActionAttributesListmodTriggers(); node.StartIndex = parser.Token.Span.Start; bool result = true; switch (parser.PeekToken().Kind) { case TokenKind.TextKeyword: case TokenKind.CommentKeyword: case TokenKind.ImageKeyword: case TokenKind.AcceleratorKeyword: { parser.NextToken(); if (parser.PeekToken(TokenKind.Equals)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expected equals token in display attribute."); } // get the help number StringExpressionNode stringExpressionNode; if (!StringExpressionNode.TryGetExpressionNode(parser, out stringExpressionNode)) { parser.ReportSyntaxError("Invalid string expression found in action attribute."); } } break; case TokenKind.DefaultViewKeyword: case TokenKind.ContextMenuKeyword: { parser.NextToken(); if (parser.PeekToken(TokenKind.Equals)) { var tokKind = parser.NextToken().Kind; if (tokKind != TokenKind.YesKeyword || tokKind != TokenKind.NoKeyword || tokKind != TokenKind.AutoKeyword) { parser.ReportSyntaxError("Invalid token found in action attribute."); } } else { parser.ReportSyntaxError("Expected equals token in display attribute."); } } break; default: result = false; break; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out AcceptStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.AcceptKeyword)) { result = true; node = new AcceptStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; TokenKind tokKind = parser.PeekToken().Kind; switch (tokKind) { case TokenKind.ConstructKeyword: case TokenKind.InputKeyword: case TokenKind.DialogKeyword: case TokenKind.DisplayKeyword: node.AcceptType = tokKind; parser.NextToken(); node.EndIndex = parser.Token.Span.End; break; default: parser.ReportSyntaxError("Accept statement must be of form: accept { CONSTRUCT | INPUT | DIALOG | DISPLAY }"); break; } } return(result); }
public static bool TryParseNode(Genero4glParser parser, out GotoStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.GotoKeyword)) { result = true; node = new GotoStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; // colon is optional if (parser.PeekToken(TokenKind.Colon)) { parser.NextToken(); } FglNameExpression expr; if (!FglNameExpression.TryParseNode(parser, out expr)) { parser.ReportSyntaxError("Invalid name found in goto statement."); } else { node.LabelId = expr; } node.EndIndex = parser.Token.Span.End; } return(result); }
public static bool CheckForPreprocessorNode(Genero4glParser parser, AstNode4gl node) { PreprocessorNode preNode; if (PreprocessorNode.TryParseNode(parser, out preNode) && node != null) { // TODO: determine context of the preprocessor via containingNode if (preNode.Type == PreprocessorType.Include && !string.IsNullOrWhiteSpace(preNode.IncludeFile)) { if (node.IncludeFiles.ContainsKey(preNode.IncludeFile)) { node.IncludeFiles[preNode.IncludeFile].Add(preNode); } else { node.IncludeFiles.Add(preNode.IncludeFile, new List <PreprocessorNode>() { preNode }); } } return(true); } return(false); }
public static bool TryParseNode(Genero4glParser parser, out SleepStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.SleepKeyword)) { result = true; node = new SleepStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; ExpressionNode expr; if (!FglExpressionNode.TryGetExpressionNode(parser, out expr, Genero4glAst.ValidStatementKeywords.ToList())) { parser.ReportSyntaxError("Invalid expression found in sleep statement."); } else { node.SleepSeconds = expr; } node.EndIndex = parser.Token.Span.End; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out CreateStatement node, IModuleResult containingModule) { node = null; bool result = true; if (parser.PeekToken(TokenKind.CreateKeyword)) { parser.NextToken(); switch (parser.PeekToken().Kind) { case TokenKind.SequenceKeyword: CreateSequenceStatement sequenceNode; result = CreateSequenceStatement.TryParseNode(parser, out sequenceNode); node = sequenceNode; break; case TokenKind.TableKeyword: case TokenKind.TempKeyword: CreateTableStatement tableNode; result = CreateTableStatement.TryParseNode(parser, out tableNode, containingModule); node = tableNode; break; default: result = false; break; } } return(result); }
public static bool TryParseNode(Genero4glParser parser, out DeferStatementNode defNode) { defNode = null; bool result = false; if (parser.PeekToken(TokenKind.DeferKeyword)) { result = true; defNode = new DeferStatementNode(); parser.NextToken(); defNode.StartIndex = parser.Token.Span.Start; if (parser.PeekToken(TokenKind.InterruptKeyword)) { parser.NextToken(); } else if (parser.PeekToken(TokenKind.QuitKeyword)) { parser.NextToken(); } else { parser.ReportSyntaxError("Invalid token found in defer statement."); } defNode.EndIndex = parser.Token.Span.End; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out DisplayStatement node, bool isArray, List <TokenKind> validExitKeywords = null, bool returnFalseInsteadOfErrors = false) { node = new DisplayStatement(); bool result = true; switch (parser.PeekToken().Kind) { case TokenKind.AcceptKeyword: case TokenKind.ContinueKeyword: case TokenKind.ExitKeyword: { if (parser.PeekToken(TokenKind.DisplayKeyword, 2)) { parser.NextToken(); node.StartIndex = parser.Token.Span.Start; parser.NextToken(); } else { result = false; } break; } default: { result = false; break; } } return(result); }
public static bool TryParseNode(Genero4glParser parser, out FreeStatement defNode) { defNode = null; bool result = false; if (parser.PeekToken(TokenKind.FreeKeyword)) { result = true; defNode = new FreeStatement(); parser.NextToken(); defNode.StartIndex = parser.Token.Span.Start; FglNameExpression expr; if (!FglNameExpression.TryParseNode(parser, out expr)) { parser.ReportSyntaxError("Invalid name found in free statement."); } else { defNode.Target = expr; } defNode.EndIndex = parser.Token.Span.End; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out ClearStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.ClearKeyword)) { result = true; node = new ClearStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; node.FieldList = new List <FglNameExpression>(); // get the bynamefields FglNameExpression nameExpr; while (FglNameExpression.TryParseNode(parser, out nameExpr)) { node.FieldList.Add(nameExpr); if (!parser.PeekToken(TokenKind.Comma)) { break; } parser.NextToken(); } if (node.FieldList.Count == 0) { parser.ReportSyntaxError("Incomplete clear statement found."); } node.EndIndex = parser.Token.Span.End; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out CompilerOptionsNode defNode) { defNode = null; if (parser.PeekToken(TokenKind.OptionsKeyword)) { parser.NextToken(); defNode = new CompilerOptionsNode(); defNode.StartIndex = parser.Token.Span.Start; // read options if (parser.PeekToken(TokenKind.ShortKeyword)) { parser.NextToken(); if (parser.PeekToken(TokenKind.CircuitKeyword)) { parser.NextToken(); } else { parser.ReportSyntaxError("The only compiler options are: short circuit"); } } else { parser.ReportSyntaxError("The only compiler options are: short circuit"); } defNode.EndIndex = parser.Token.Span.End; defNode.IsComplete = true; return(true); } return(false); }
public static bool TryParseNode(Genero4glParser parser, out OtherwiseStatement node, IModuleResult containingModule, List <Func <PrepareStatement, bool> > prepStatementBinders, Func <ReturnStatement, ParserResult> returnStatementBinder = null, Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null, List <TokenKind> validExitKeywords = null, IEnumerable <ContextStatementFactory> contextStatementFactories = null, ExpressionParsingOptions expressionOptions = null, HashSet <TokenKind> endKeywords = null) { node = null; bool result = false; if (parser.PeekToken(TokenKind.OtherwiseKeyword)) { result = true; node = new OtherwiseStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; node.DecoratorEnd = parser.Token.Span.End; prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier); while (!parser.PeekToken(TokenKind.EndOfFile) && !parser.PeekToken(TokenKind.WhenKeyword) && !parser.PeekToken(TokenKind.OtherwiseKeyword) && !(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.CaseKeyword, 2))) { FglStatement statement; if (parser.StatementFactory.TryParseNode(parser, out statement, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, false, validExitKeywords, contextStatementFactories, expressionOptions) && statement != null) { AstNode4gl stmtNode = statement as AstNode4gl; node.Children.Add(stmtNode.StartIndex, stmtNode); if (statement is ExitStatement && (statement as ExitStatement).ExitType != TokenKind.CaseKeyword) { if (validExitKeywords != null && !validExitKeywords.Contains((statement as ExitStatement).ExitType)) { parser.ReportSyntaxError("Invalid exit statement for case statement block detected."); } } } else if (parser.PeekToken(TokenKind.EndKeyword) && endKeywords != null && endKeywords.Contains(parser.PeekToken(2).Kind)) { break; } else { parser.NextToken(); } } prepStatementBinders.RemoveAt(0); node.EndIndex = parser.Token.Span.End; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out LocateStatement defNode) { defNode = null; bool result = false; if (parser.PeekToken(TokenKind.LocateKeyword)) { result = true; defNode = new LocateStatement(); parser.NextToken(); defNode.StartIndex = parser.Token.Span.Start; defNode.TargetVariables = new List <FglNameExpression>(); FglNameExpression name; while (FglNameExpression.TryParseNode(parser, out name)) { defNode.TargetVariables.Add(name); if (!parser.PeekToken(TokenKind.Comma)) { break; } parser.NextToken(); } if (parser.PeekToken(TokenKind.InKeyword)) { parser.NextToken(); if (parser.PeekToken(TokenKind.MemoryKeyword)) { parser.NextToken(); defNode.Location = LocateLocation.Memory; } else if (parser.PeekToken(TokenKind.FileKeyword)) { parser.NextToken(); defNode.Location = LocateLocation.File; ExpressionNode filename; if (FglExpressionNode.TryGetExpressionNode(parser, out filename, Genero4glAst.ValidStatementKeywords.ToList())) { defNode.Filename = filename; } } else { parser.ReportSyntaxError("Locate statement can only specify memory or a file."); } } else { parser.ReportSyntaxError("Locate statement missing \"in\" keyword."); } defNode.EndIndex = parser.Token.Span.End; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out ExitStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.ExitKeyword)) { result = true; node = new ExitStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; TokenKind tokKind = parser.PeekToken().Kind; switch (tokKind) { case TokenKind.ForKeyword: case TokenKind.ForeachKeyword: case TokenKind.WhileKeyword: case TokenKind.MenuKeyword: case TokenKind.ConstructKeyword: case TokenKind.ReportKeyword: case TokenKind.DisplayKeyword: case TokenKind.InputKeyword: case TokenKind.DialogKeyword: case TokenKind.CaseKeyword: node.ExitType = tokKind; parser.NextToken(); node.EndIndex = parser.Token.Span.End; break; case TokenKind.ProgramKeyword: node.ExitType = tokKind; parser.NextToken(); bool requireCode = false; if (parser.PeekToken(TokenKind.Subtract)) { parser.NextToken(); requireCode = true; } if (parser.PeekToken(TokenCategory.NumericLiteral)) { parser.NextToken(); } else if (requireCode) { parser.ReportSyntaxError("Exit program statement is missing an exit code."); } node.EndIndex = parser.Token.Span.End; break; default: parser.ReportSyntaxError("Exit statement must be of form: exit { FOR | FOREACH | WHILE | MENU | CONSTRUCT | REPORT | DISPLAY | INPUT | DIALOG | CASE | PROGRAM }"); break; } } return(result); }
public static bool TryParseNode(Genero4glParser parser, out ValidateStatement defNode) { defNode = null; bool result = false; if (parser.PeekToken(TokenKind.ValidateKeyword)) { result = true; defNode = new ValidateStatement(); parser.NextToken(); defNode.StartIndex = parser.Token.Span.Start; FglNameExpression name; while (FglNameExpression.TryParseNode(parser, out name)) { defNode.TargetVariables.Add(name); if (!parser.PeekToken(TokenKind.Comma)) { break; } parser.NextToken(); } if (parser.PeekToken(TokenKind.LikeKeyword)) { parser.NextToken(); defNode.TableName = parser.Token.Token.Value.ToString(); parser.NextToken(); // advance to the dot if (parser.Token.Token.Kind == TokenKind.Dot) { if (parser.PeekToken(TokenKind.Multiply) || parser.PeekToken(TokenCategory.Identifier) || parser.PeekToken(TokenCategory.Keyword)) { parser.NextToken(); // advance to the column name defNode.ColumnName = parser.Token.Token.Value.ToString(); defNode.IsComplete = true; defNode.EndIndex = parser.Token.Span.End; } else { parser.ReportSyntaxError("Invalid validation form detected."); } } else { parser.ReportSyntaxError("Invalid validation form detected."); } } else { parser.ReportSyntaxError("Variables can only be validated against a database table spec."); } defNode.EndIndex = parser.Token.Span.End; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out DialogAttribute node) { node = new DialogAttribute(); node.StartIndex = parser.Token.Span.Start; bool result = true; switch (parser.PeekToken().Kind) { case TokenKind.FieldKeyword: { parser.NextToken(); if (parser.PeekToken(TokenKind.OrderKeyword)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expected \"order\" keyword in dialog attribute."); } if (parser.PeekToken(TokenKind.FormKeyword)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expected \"form\" keyword in dialog attribute."); } break; } case TokenKind.UnbufferedKeyword: { parser.NextToken(); if (parser.PeekToken(TokenKind.Equals)) { parser.NextToken(); ExpressionNode boolExpr; if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> { TokenKind.Comma, TokenKind.RightParenthesis })) { parser.ReportSyntaxError("Invalid boolean expression found in dialog attribute."); } } break; } default: result = false; break; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out MessageAttribute node) { node = new MessageAttribute(); node.StartIndex = parser.Token.Span.Start; bool result = true; switch (parser.PeekToken().Kind) { case TokenKind.BlackKeyword: case TokenKind.BlueKeyword: case TokenKind.CyanKeyword: case TokenKind.GreenKeyword: case TokenKind.MagentaKeyword: case TokenKind.RedKeyword: case TokenKind.WhiteKeyword: case TokenKind.YellowKeyword: case TokenKind.BoldKeyword: case TokenKind.DimKeyword: case TokenKind.InvisibleKeyword: case TokenKind.NormalKeyword: case TokenKind.ReverseKeyword: case TokenKind.BlinkKeyword: case TokenKind.UnderlineKeyword: parser.NextToken(); break; case TokenKind.StyleKeyword: { parser.NextToken(); if (parser.PeekToken(TokenKind.Equals)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expected equals token in message attribute."); } // get the style name ExpressionNode styleName; if (!FglExpressionNode.TryGetExpressionNode(parser, out styleName)) { parser.ReportSyntaxError("Invalid style name found in message attribute."); } break; } default: result = false; break; } return(result); }
internal static bool TryGetDialogStatement(Genero4glParser parser, out DialogStatement node, bool returnFalseInsteadOfErrors = false) { bool result = false; node = null; DialogStatement inputStmt; if ((result = DialogStatement.TryParseNode(parser, out inputStmt, returnFalseInsteadOfErrors))) { node = inputStmt; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out BreakpointStatement node) { node = null; if (parser.PeekToken(TokenKind.BreakpointKeyword)) { node = new BreakpointStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; node.EndIndex = parser.Token.Span.End; return(true); } return(false); }
public static bool TryParseNode(Genero4glParser parser, out CallStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.CallKeyword)) { result = true; node = new CallStatement(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; // get the function name FunctionCallExpressionNode functionCall; FglNameExpression dummy; if (!FunctionCallExpressionNode.TryParseExpression(parser, out functionCall, out dummy, true)) { parser.ReportSyntaxError("Unexpected token found in call statement, expecting name expression."); } else { node.Function = functionCall; if (parser.PeekToken(TokenKind.ReturningKeyword)) { parser.NextToken(); FglNameExpression name; // get return values while (FglNameExpression.TryParseNode(parser, out name, TokenKind.Comma)) { node.Returns.Add(name); if (!parser.PeekToken(TokenKind.Comma)) { break; } parser.NextToken(); } if (node.Returns.Count == 0) { parser.ReportSyntaxError("One or more return variables must be specified."); } } node.EndIndex = parser.Token.Span.End; } } return(result); }
private static bool TryGetDisplayStatement(Genero4glParser parser, out DisplayStatement node, bool isArray, bool returnFalseInsteadOfErrors = false) { bool result = false; node = null; DisplayStatement inputStmt; if ((result = DisplayStatement.TryParseNode(parser, out inputStmt, isArray, null, returnFalseInsteadOfErrors))) { node = inputStmt; } return(result); }
private static bool TryGetConstructStatement(Genero4glParser parser, out ConstructDialogStatement node, bool returnFalseInsteadOfErrors = false) { bool result = false; node = null; ConstructDialogStatement constStmt; if ((result = ConstructDialogStatement.TryParseNode(parser, out constStmt, returnFalseInsteadOfErrors))) { node = constStmt; } return(result); }
private static bool TryGetMenuStatement(Genero4glParser parser, out MenuStatement node, bool returnFalseInsteadOfErrors = false) { bool result = false; node = null; MenuStatement menuStmt; if ((result = MenuStatement.TryParseNode(parser, out menuStmt, returnFalseInsteadOfErrors))) { node = menuStmt; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out PrepareStatement defNode, IModuleResult containingModule) { defNode = null; bool result = false; if (parser.PeekToken(TokenKind.PrepareKeyword)) { result = true; defNode = new PrepareStatement(); parser.NextToken(); defNode.StartIndex = parser.Token.Span.Start; if (parser.PeekToken(TokenCategory.Identifier) || parser.PeekToken(TokenCategory.Keyword)) { parser.NextToken(); defNode.Identifier = parser.Token.Token.Value.ToString(); if (parser.PeekToken(TokenKind.FromKeyword)) { parser.NextToken(); ExpressionNode exprNode; if (FglExpressionNode.TryGetExpressionNode(parser, out exprNode) && exprNode != null) { defNode.Children.Add(exprNode.StartIndex, exprNode); defNode.EndIndex = exprNode.EndIndex; defNode.IsComplete = true; containingModule.BindCursorResult(defNode, parser); } else { parser.ReportSyntaxError("SQL prepare statement must specify an expression to prepare."); } } else { parser.ReportSyntaxError("SQL prepare statement is missing keyword \"from\"."); } } else { parser.ReportSyntaxError("SQL prepare statement must specify an identifier to prepare."); } } return(result); }
internal static bool TryParseNode(Genero4glParser parser, out CreateSequenceStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.SequenceKeyword)) { result = true; node = new CreateSequenceStatement(); node.StartIndex = parser.Token.Span.Start; // want to get the start of the create token parser.NextToken(); if (parser.PeekToken(TokenKind.IfKeyword)) { parser.NextToken(); if (parser.PeekToken(TokenKind.NotKeyword)) { parser.NextToken(); if (parser.PeekToken(TokenKind.ExistsKeyword)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expecting \"exists\" keyword in create sequence statement."); } } else { parser.ReportSyntaxError("Expecting \"not\" keyword in create sequence statement."); } } FglNameExpression nameExpr; if (FglNameExpression.TryParseNode(parser, out nameExpr)) { node.SequenceName = nameExpr; } else { parser.ReportSyntaxError("Invalid name found for create sequence statement."); } // TODO: finish getting the modifiers } return(result); }
public static bool TryParseNode(Genero4glParser parser, out IfBlockContentsNode node, IModuleResult containingModule, List <Func <PrepareStatement, bool> > prepStatementBinders, Func <ReturnStatement, ParserResult> returnStatementBinder = null, Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null, List <TokenKind> validExitKeywords = null, IEnumerable <ContextStatementFactory> contextStatementFactories = null, ExpressionParsingOptions expressionOptions = null, HashSet <TokenKind> endKeywords = null) { node = new IfBlockContentsNode(); node.StartIndex = parser.Token.Span.Start; prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier); while (!parser.PeekToken(TokenKind.EndOfFile) && !parser.PeekToken(TokenKind.ElseKeyword) && !(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.IfKeyword, 2))) { FglStatement statement; if (parser.StatementFactory.TryParseNode(parser, out statement, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, false, validExitKeywords, contextStatementFactories, expressionOptions, endKeywords)) { AstNode4gl stmtNode = statement as AstNode4gl; if (stmtNode != null && !node.Children.ContainsKey(stmtNode.StartIndex)) { node.Children.Add(stmtNode.StartIndex, stmtNode); } } else if (parser.PeekToken(TokenKind.EndKeyword) && endKeywords != null && endKeywords.Contains(parser.PeekToken(2).Kind)) { break; } else { parser.NextToken(); } } prepStatementBinders.RemoveAt(0); node.EndIndex = parser.Token.Span.End; return(true); }
public static bool TryParseNode(Genero4glParser parser, out ReturnStatement node) { node = null; bool result = false; if (parser.PeekToken(TokenKind.ReturnKeyword)) { parser.NextToken(); result = true; node = new ReturnStatement(); node.StartIndex = parser.Token.Span.Start; while (true) { // TODO: not sure about this....it was in here for a reason, right? var tok = parser.PeekToken(); if (Genero4glAst.ValidStatementKeywords.Contains(tok.Kind) && !Genero4glAst.Acceptable_ReturnVariableName_StatementKeywords.Contains(tok.Kind)) { // TODO: need to check and see if there are any variables defined with the same name as the statement keyword? break; } ExpressionNode expr; if (!FglExpressionNode.TryGetExpressionNode(parser, out expr)) { break; } node.Returns.Add(expr); if (!parser.PeekToken(TokenKind.Comma)) { break; } parser.NextToken(); } } return(result); }
public static bool TryParseNode(Genero4glParser parser, out DialogBlock node, IModuleResult containingModule, List <Func <PrepareStatement, bool> > prepStatementBinders, Func <ReturnStatement, ParserResult> returnStatementBinder = null, Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null, List <TokenKind> validExitKeywords = null, IEnumerable <ContextStatementFactory> contextStatementFactories = null, HashSet <TokenKind> endKeywords = null) { node = null; bool result = false; if (parser.PeekToken(TokenKind.DialogKeyword)) { result = true; node = new DialogBlock(true); node.Attributes = new List <DialogAttribute>(); node.Subdialogs = new List <FglNameExpression>(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; node.DecoratorEnd = parser.Token.Span.End; BuildDialogBlock(parser, node, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords); if (!(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.DialogKeyword, 2))) { parser.ReportSyntaxError("A dialog block must be terminated with \"end dialog\"."); } else { parser.NextToken(); // advance to the 'end' token parser.NextToken(); // advance to the 'dialog' token node.EndIndex = parser.Token.Span.End; } } return(result); }