Beispiel #1
0
        private static bool TryGetInputDialogStatement(Genero4glParser parser, out InputDialogStatement node, bool isArray, bool returnFalseInsteadOfErrors = false)
        {
            bool result = false;

            node = null;

            InputDialogStatement inputStmt;

            if ((result = InputDialogStatement.TryParseNode(parser, out inputStmt, isArray, returnFalseInsteadOfErrors)))
            {
                node = inputStmt;
            }

            return(result);
        }
Beispiel #2
0
        public static bool TryParseNode(Genero4glParser parser, out InputDialogStatement node, bool isArray, bool returnFalseInsteadOfErrors = false)
        {
            node = new InputDialogStatement();
            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.AcceptKeyword:
            case TokenKind.ContinueKeyword:
            case TokenKind.ExitKeyword:
            {
                if (parser.PeekToken(TokenKind.InputKeyword, 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 input statement.");
                        }
                        break;
                    }
                    }
                }
                else
                {
                    if (!returnFalseInsteadOfErrors)
                    {
                        parser.ReportSyntaxError("Expecting \"field\" keyword in input statement.");
                    }
                    else
                    {
                        return(false);
                    }
                }
                break;
            }

            case TokenKind.CancelKeyword:
            {
                if (isArray)
                {
                    parser.NextToken();
                    node.StartIndex = parser.Token.Span.Start;
                    if (parser.PeekToken(TokenKind.DeleteKeyword) || parser.PeekToken(TokenKind.InsertKeyword))
                    {
                        parser.NextToken();
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"delete\" or \"insert\" keyword in input statement.");
                    }
                }
                else
                {
                    if (!returnFalseInsteadOfErrors)
                    {
                        parser.ReportSyntaxError("Keyword \"cancel\" can only exist in an input array statement.");
                    }
                    else
                    {
                        return(false);
                    }
                }
                break;
            }

            default:
            {
                result = false;
                break;
            }
            }

            if (result && node != null)
            {
                node.EndIndex = parser.Token.Span.End;
            }

            return(result);
        }