public static bool TryParseNode(Genero4glParser parser, out ConstructAttribute node) { node = new ConstructAttribute(); 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.AcceptKeyword: case TokenKind.CancelKeyword: { 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 construct attribute."); } } break; } case TokenKind.HelpKeyword: { parser.NextToken(); if (parser.PeekToken(TokenKind.Equals)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expected equals token in construct attribute."); } // get the help number ExpressionNode optionNumber; if (!FglExpressionNode.TryGetExpressionNode(parser, out optionNumber)) { parser.ReportSyntaxError("Invalid help-number found in construct attribute."); } break; } case TokenKind.NameKeyword: { parser.NextToken(); if (parser.PeekToken(TokenKind.Equals)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expected equals token in construct attribute."); } // get the help number ExpressionNode optionNumber; if (!FglExpressionNode.TryGetExpressionNode(parser, out optionNumber)) { parser.ReportSyntaxError("Invalid dialog name found in construct attribute."); } break; } case TokenKind.FieldKeyword: { parser.NextToken(); if (parser.PeekToken(TokenKind.OrderKeyword)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expected \"order\" keyword in input attribute."); } if (parser.PeekToken(TokenKind.FormKeyword)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expected \"form\" keyword in input attribute."); } break; } default: result = false; break; } return(result); }
public static bool TryParseNode(Genero4glParser parser, out ConstructBlock 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.ConstructKeyword)) { result = true; node = new ConstructBlock(); parser.NextToken(); node.StartIndex = parser.Token.Span.Start; node.ColumnList = new List <FglNameExpression>(); node.FieldList = new List <FglNameExpression>(); node.Attributes = new List <ConstructAttribute>(); if (parser.PeekToken(TokenKind.ByKeyword)) { parser.NextToken(); if (parser.PeekToken(TokenKind.NameKeyword)) { parser.NextToken(); // Implicit field mapping node.IsImplicitMapping = true; } else { parser.ReportSyntaxError("Expected \"name\" token in construct statement."); } } FglNameExpression varName; if (FglNameExpression.TryParseNode(parser, out varName)) { node.Variable = varName; } else { parser.ReportSyntaxError("Invalid variable name found in construct statement."); } node.DecoratorEnd = parser.Token.Span.End; if (parser.PeekToken(TokenKind.OnKeyword)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expecting \"on\" keyword in construct statement."); } FglNameExpression colName; while (FglNameExpression.TryParseNode(parser, out colName)) { node.ColumnList.Add(colName); if (!parser.PeekToken(TokenKind.Comma)) { break; } parser.NextToken(); } if (!node.IsImplicitMapping) { if (parser.PeekToken(TokenKind.FromKeyword)) { parser.NextToken(); // read the field list FglNameExpression nameExpr; while (FglNameExpression.TryParseNode(parser, out nameExpr)) { node.FieldList.Add(nameExpr); if (!parser.PeekToken(TokenKind.Comma)) { break; } parser.NextToken(); } } else { parser.ReportSyntaxError("Expected \"from\" token in construct statement."); } } if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword)) { parser.NextToken(); if (parser.PeekToken(TokenKind.LeftParenthesis)) { parser.NextToken(); // get the list of display or control attributes ConstructAttribute attrib; while (ConstructAttribute.TryParseNode(parser, out attrib)) { node.Attributes.Add(attrib); if (!parser.PeekToken(TokenKind.Comma)) { break; } parser.NextToken(); } if (parser.PeekToken(TokenKind.RightParenthesis)) { parser.NextToken(); } else { parser.ReportSyntaxError("Expecting right-paren in construct attributes section."); } } else { parser.ReportSyntaxError("Expecting left-paren in construct attributes section."); } } if (parser.PeekToken(TokenKind.HelpKeyword)) { parser.NextToken(); // get the help number ExpressionNode optionNumber; if (FglExpressionNode.TryGetExpressionNode(parser, out optionNumber)) { node.HelpNumber = optionNumber; } else { parser.ReportSyntaxError("Invalid help-number found in construct statement."); } } List <TokenKind> validExits = new List <TokenKind>(); if (validExitKeywords != null) { validExits.AddRange(validExitKeywords); } validExits.Add(TokenKind.ConstructKeyword); HashSet <TokenKind> newEndKeywords = new HashSet <TokenKind>(); if (endKeywords != null) { newEndKeywords.AddRange(endKeywords); } newEndKeywords.Add(TokenKind.ConstructKeyword); bool hasControlBlocks = false; ConstructControlBlock icb; prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier); while (ConstructControlBlock.TryParseNode(parser, out icb, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, validExits, contextStatementFactories, newEndKeywords) && icb != null) { if (icb.StartIndex < 0) { continue; } node.Children.Add(icb.StartIndex, icb); hasControlBlocks = true; if (parser.PeekToken(TokenKind.EndOfFile) || (parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.ConstructKeyword, 2))) { break; } } prepStatementBinders.RemoveAt(0); if (hasControlBlocks || (parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.ConstructKeyword, 2))) { if (!(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.ConstructKeyword, 2))) { parser.ReportSyntaxError("A construct block must be terminated with \"end construct\"."); } else { parser.NextToken(); // advance to the 'end' token parser.NextToken(); // advance to the 'construct' token node.EndIndex = parser.Token.Span.End; } } } return(result); }