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 DialogStatement node, bool returnFalseInsteadOfErrors = false) { node = new DialogStatement(); bool result = true; switch (parser.PeekToken().Kind) { case TokenKind.AcceptKeyword: case TokenKind.ContinueKeyword: case TokenKind.ExitKeyword: { if (parser.PeekToken(TokenKind.DialogKeyword, 2)) { parser.NextToken(); node.StartIndex = parser.Token.Span.Start; parser.NextToken(); } else { result = false; } break; } case TokenKind.NextKeyword: { parser.NextToken(); node.StartIndex = parser.Token.Span.Start; if (parser.PeekToken(TokenKind.FieldKeyword)) { parser.NextToken(); switch (parser.PeekToken().Kind) { case TokenKind.CurrentKeyword: case TokenKind.NextKeyword: case TokenKind.PreviousKeyword: parser.NextToken(); break; default: { // get the field-spec FglNameExpression fieldSpec; if (FglNameExpression.TryParseNode(parser, out fieldSpec)) { node.FieldSpec = fieldSpec; } else { parser.ReportSyntaxError("Invalid field-spec found in dialog statement."); } break; } } } else { if (!returnFalseInsteadOfErrors) { parser.ReportSyntaxError("Expecting \"field\" keyword in dialog statement."); } else { return(false); } } break; } default: { result = false; break; } } if (result) { node.EndIndex = parser.Token.Span.End; } return(result); }