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); }
internal static void BuildDialogBlock(Genero4glParser parser, 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) { if (parser.PeekToken(TokenKind.AttributeKeyword) || parser.PeekToken(TokenKind.AttributesKeyword)) { parser.NextToken(); if (parser.PeekToken(TokenKind.LeftParenthesis)) { parser.NextToken(); // get the list of display or control attributes DialogAttribute attrib; while (DialogAttribute.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 dialog attributes section."); } } else { parser.ReportSyntaxError("Expecting left-paren in dialog attributes section."); } } // parse input, construct, display or SUBDIALOG bool moreBlocks = true; List <ContextStatementFactory> csfs = new List <ContextStatementFactory>(); if (contextStatementFactories != null) { csfs.AddRange(contextStatementFactories); } csfs.Add((x) => { DialogStatement testNode; DialogStatementFactory.TryGetDialogStatement(x, out testNode, true); return(testNode); }); prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier); while (moreBlocks) { switch (parser.PeekToken().Kind) { case TokenKind.InputKeyword: { InputBlock inputBlock; if (InputBlock.TryParseNode(parser, out inputBlock, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, validExitKeywords, csfs, endKeywords) && inputBlock != null) { node.Children.Add(inputBlock.StartIndex, inputBlock); } else { parser.ReportSyntaxError("Invalid input block found in dialog statement."); } break; } case TokenKind.ConstructKeyword: { ConstructBlock constructBlock; if (ConstructBlock.TryParseNode(parser, out constructBlock, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, validExitKeywords, csfs, endKeywords) && constructBlock != null) { node.Children.Add(constructBlock.StartIndex, constructBlock); } else { parser.ReportSyntaxError("Invalid construct block found in dialog statement."); } break; } case TokenKind.DisplayKeyword: { DisplayBlock dispBlock; if (DisplayBlock.TryParseNode(parser, out dispBlock, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, validExitKeywords, csfs, endKeywords) && dispBlock != null) { node.Children.Add(dispBlock.StartIndex, dispBlock); } else { parser.ReportSyntaxError("Invalid display block found in dialog statement."); } break; } case TokenKind.SubdialogKeyword: { parser.NextToken(); FglNameExpression nameExpr; if (FglNameExpression.TryParseNode(parser, out nameExpr)) { node.Subdialogs.Add(nameExpr); } else { parser.ReportSyntaxError("Invalid subdialog name found in dialog statement."); } break; } default: moreBlocks = false; break; } } prepStatementBinders.RemoveAt(0); List <TokenKind> validExits = new List <TokenKind>(); if (validExitKeywords != null) { validExits.AddRange(validExits); } validExits.Add(TokenKind.DialogKeyword); HashSet <TokenKind> newEndKeywords = new HashSet <TokenKind>(); if (endKeywords != null) { newEndKeywords.AddRange(endKeywords); } newEndKeywords.Add(TokenKind.DialogKeyword); // get the dialog control blocks prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier); while (!parser.PeekToken(TokenKind.EndOfFile) && !(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.DialogKeyword, 2))) { DialogControlBlock icb; if (DialogControlBlock.TryParseNode(parser, out icb, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, validExits, contextStatementFactories, newEndKeywords) && icb != null) { if (icb.StartIndex < 0) { continue; } node.Children.Add(icb.StartIndex, icb); } else if (parser.PeekToken(TokenKind.EndKeyword) && endKeywords != null && endKeywords.Contains(parser.PeekToken(2).Kind)) { break; } else { parser.NextToken(); } } prepStatementBinders.RemoveAt(0); }