Пример #1
0
        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);
        }
Пример #2
0
        public static bool TryParseNode(Genero4glParser parser, out DisplayBlock 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.DisplayKeyword))
            {
                result = true;
                node   = new DisplayBlock();
                parser.NextToken();
                node.StartIndex   = parser.Token.Span.Start;
                node.Attributes   = new List <DisplayAttribute>();
                node.ByNameFields = new List <FglNameExpression>();
                node.FieldSpecs   = new List <FglNameExpression>();
                node.DecoratorEnd = parser.Token.Span.End;

                if (parser.PeekToken(TokenKind.ByKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.NameKeyword))
                    {
                        parser.NextToken();

                        // get the bynamefields
                        FglNameExpression nameExpr;
                        while (FglNameExpression.TryParseNode(parser, out nameExpr))
                        {
                            node.ByNameFields.Add(nameExpr);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }

                        node.DecoratorEnd = parser.Token.Span.End;

                        // get the optional attributes
                        if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                DisplayAttribute attrib;
                                while (DisplayAttribute.TryParseNode(parser, out attrib, node.IsArray))
                                {
                                    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 display attributes section.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expecting left-paren in display attributes section.");
                            }
                        }
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"name\" keyword in display statement.");
                    }
                }
                else if (parser.PeekToken(TokenKind.ArrayKeyword))
                {
                    parser.NextToken();
                    node.IsArray = true;

                    FglNameExpression arrName;
                    if (FglNameExpression.TryParseNode(parser, out arrName))
                    {
                        node.ArrayName = arrName;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid array name found in display array statement.");
                    }

                    node.DecoratorEnd = parser.Token.Span.End;

                    if (parser.PeekToken(TokenKind.ToKeyword))
                    {
                        parser.NextToken();
                        if (FglNameExpression.TryParseNode(parser, out arrName))
                        {
                            node.ScreenArrayName = arrName;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid array name found in display array statement.");
                        }

                        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 input statement.");
                            }
                        }

                        // get the optional attributes
                        if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                DisplayAttribute attrib;
                                while (DisplayAttribute.TryParseNode(parser, out attrib, node.IsArray))
                                {
                                    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 display attributes section.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expecting left-paren in display attributes section.");
                            }
                        }

                        List <TokenKind> validExits = new List <TokenKind>();
                        if (validExitKeywords != null)
                        {
                            validExits.AddRange(validExitKeywords);
                        }
                        validExits.Add(TokenKind.DisplayKeyword);

                        HashSet <TokenKind> newEndKeywords = new HashSet <TokenKind>();
                        if (endKeywords != null)
                        {
                            newEndKeywords.AddRange(endKeywords);
                        }
                        newEndKeywords.Add(TokenKind.DisplayKeyword);

                        bool hasControlBlocks = false;
                        DisplayControlBlock icb;
                        prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                        while (DisplayControlBlock.TryParseNode(parser, out icb, containingModule, hasControlBlocks, node.IsArray, prepStatementBinders,
                                                                returnStatementBinder, limitedScopeVariableAdder, validExits, contextStatementFactories, newEndKeywords) && icb != null)
                        {
                            // check for include file sign
                            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.DisplayKeyword, 2)))
                            {
                                break;
                            }
                        }
                        prepStatementBinders.RemoveAt(0);

                        if (hasControlBlocks ||
                            (parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.DisplayKeyword, 2)))
                        {
                            if (!(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.DisplayKeyword, 2)))
                            {
                                parser.ReportSyntaxError("A display block must be terminated with \"end display\".");
                            }
                            else
                            {
                                parser.NextToken(); // advance to the 'end' token
                                parser.NextToken(); // advance to the 'display' token
                                node.EndIndex = parser.Token.Span.End;
                            }
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"to\" keyword in display array statement.");
                    }
                }
                else
                {
                    // get the expression(s)
                    ExpressionNode mainExpression = null;
                    while (true)
                    {
                        ExpressionNode expr;
                        if (!FglExpressionNode.TryGetExpressionNode(parser, out expr, new List <TokenKind> {
                            TokenKind.ToKeyword, TokenKind.AttributeKeyword, TokenKind.AttributesKeyword
                        }))
                        {
                            parser.ReportSyntaxError("Display statement must have one or more comma-separated expressions.");
                            break;
                        }
                        if (mainExpression == null)
                        {
                            mainExpression = expr;
                        }
                        else
                        {
                            mainExpression.AppendExpression(expr);
                        }

                        if (!parser.PeekToken(TokenKind.Comma))
                        {
                            break;
                        }
                        parser.NextToken();
                    }

                    if (mainExpression != null)
                    {
                        node.Expression = mainExpression;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid expression found in display statement.");
                    }

                    if (parser.PeekToken(TokenKind.ToKeyword))
                    {
                        parser.NextToken();

                        // get the field specs
                        FglNameExpression nameExpr;
                        while (FglNameExpression.TryParseNode(parser, out nameExpr))
                        {
                            node.FieldSpecs.Add(nameExpr);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }

                        // get the optional attributes
                        if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                DisplayAttribute attrib;
                                while (DisplayAttribute.TryParseNode(parser, out attrib, node.IsArray))
                                {
                                    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 input attributes section.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expecting left-paren in display attributes section.");
                            }
                        }
                    }

                    node.EndIndex = parser.Token.Span.End;
                }
            }

            return(result);
        }
Пример #3
0
        public bool TryParseNode(Genero4glParser parser,
                                 out FglStatement node,
                                 IModuleResult containingModule,
                                 List <Func <PrepareStatement, bool> > prepStatementBinders,
                                 Func <ReturnStatement, ParserResult> returnStatementBinder   = null,
                                 Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null,
                                 bool returnStatementsOnly          = false,
                                 List <TokenKind> validExitKeywords = null,
                                 IEnumerable <ContextStatementFactory> contextStatementFactories = null,
                                 ExpressionParsingOptions expressionOptions = null,
                                 HashSet <TokenKind> endKeywords            = null)
        {
            node = null;
            bool result = false;

            if (returnStatementsOnly)
            {
                if (parser.PeekToken(TokenKind.ReturnKeyword))
                {
                    ReturnStatement retStmt;
                    if ((result = ReturnStatement.TryParseNode(parser, out retStmt)))
                    {
                        node = retStmt;
                    }
                }
                return(result);
            }

            if (contextStatementFactories != null)
            {
                foreach (var context in contextStatementFactories)
                {
                    node = context(parser);
                    if (node != null)
                    {
                        break;
                    }
                }
                if (node != null)
                {
                    return(true);
                }
            }

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.LetKeyword:
            {
                LetStatement letStmt;
                if ((result = LetStatement.TryParseNode(parser, out letStmt, expressionOptions)))
                {
                    node = letStmt;
                }
                break;
            }

            case TokenKind.DeclareKeyword:
            {
                DeclareStatement declStmt;
                if ((result = DeclareStatement.TryParseNode(parser, out declStmt, containingModule)))
                {
                    node = declStmt;
                }
                break;
            }

            case TokenKind.DeferKeyword:
            {
                DeferStatementNode deferStmt;
                if ((result = DeferStatementNode.TryParseNode(parser, out deferStmt)))
                {
                    node = deferStmt;
                }
                break;
            }

            case TokenKind.PrepareKeyword:
            {
                PrepareStatement prepStmt;
                if ((result = PrepareStatement.TryParseNode(parser, out prepStmt, containingModule)))
                {
                    node = prepStmt;
                    foreach (var binder in prepStatementBinders)
                    {
                        if (binder(prepStmt))
                        {
                            break;
                        }
                    }
                }
                break;
            }

            case TokenKind.SqlKeyword:
            {
                SqlBlockNode sqlStmt;
                if ((result = SqlBlockNode.TryParseSqlNode(parser, out sqlStmt)))
                {
                    node = sqlStmt;
                }
                break;
            }

            case TokenKind.ReturnKeyword:
            {
                ReturnStatement retStmt;
                if ((result = ReturnStatement.TryParseNode(parser, out retStmt)))
                {
                    if (returnStatementBinder != null)
                    {
                        var parseResult = returnStatementBinder(retStmt);
                        if (!parseResult.Success && !string.IsNullOrWhiteSpace(parseResult.ErrorMessage))
                        {
                            parser.ReportSyntaxError(parseResult.ErrorMessage);
                        }
                    }
                    node = retStmt;
                }
                break;
            }

            case TokenKind.CallKeyword:
            {
                CallStatement callStmt;
                if ((result = CallStatement.TryParseNode(parser, out callStmt)))
                {
                    node = callStmt;
                }
                break;
            }

            case TokenKind.IfKeyword:
            {
                IfStatement ifStmt;
                if ((result = IfStatement.TryParseNode(parser, out ifStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                       limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, expressionOptions, endKeywords)))
                {
                    node = ifStmt;
                }
                break;
            }

            case TokenKind.WhileKeyword:
            {
                WhileStatement whileStmt;
                if ((result = WhileStatement.TryParseNode(parser, out whileStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                          limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, expressionOptions, endKeywords)))
                {
                    node = whileStmt;
                }
                break;
            }

            case TokenKind.ExitKeyword:
            {
                ExitStatement exitStatement;
                if ((result = ExitStatement.TryParseNode(parser, out exitStatement)))
                {
                    node = exitStatement;
                }
                break;
            }

            case TokenKind.ContinueKeyword:
            {
                ContinueStatement contStmt;
                if ((result = ContinueStatement.TryParseNode(parser, out contStmt)))
                {
                    node = contStmt;
                }
                break;
            }

            case TokenKind.WheneverKeyword:
            {
                WheneverStatement wheneverStmt;
                if ((result = WheneverStatement.TryParseNode(parser, out wheneverStmt)))
                {
                    node = wheneverStmt;
                }
                break;
            }

            case TokenKind.ForKeyword:
            {
                ForStatement forStmt;
                if ((result = ForStatement.TryParserNode(parser, out forStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                         limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, expressionOptions, endKeywords)))
                {
                    node = forStmt;
                }
                break;
            }

            case TokenKind.CaseKeyword:
            {
                CaseStatement caseStmt;
                if ((result = CaseStatement.TryParseNode(parser, out caseStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                         limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, expressionOptions, endKeywords)))
                {
                    node = caseStmt;
                }
                break;
            }

            case TokenKind.InitializeKeyword:
            {
                InitializeStatement initStmt;
                if ((result = InitializeStatement.TryParseNode(parser, out initStmt)))
                {
                    node = initStmt;
                }
                break;
            }

            case TokenKind.LocateKeyword:
            {
                LocateStatement locateStmt;
                if ((result = LocateStatement.TryParseNode(parser, out locateStmt)))
                {
                    node = locateStmt;
                }
                break;
            }

            case TokenKind.FreeKeyword:
            {
                FreeStatement freeStmt;
                if ((result = FreeStatement.TryParseNode(parser, out freeStmt)))
                {
                    node = freeStmt;
                }
                break;
            }

            case TokenKind.GotoKeyword:
            {
                GotoStatement gotoStmt;
                if ((result = GotoStatement.TryParseNode(parser, out gotoStmt)))
                {
                    node = gotoStmt;
                }
                break;
            }

            case TokenKind.LabelKeyword:
            {
                LabelStatement labelStmt;
                if ((result = LabelStatement.TryParseNode(parser, out labelStmt)))
                {
                    node = labelStmt;
                }
                break;
            }

            case TokenKind.SleepKeyword:
            {
                SleepStatement sleepStmt;
                if ((result = SleepStatement.TryParseNode(parser, out sleepStmt)))
                {
                    node = sleepStmt;
                }
                break;
            }

            case TokenKind.TryKeyword:
            {
                TryCatchStatement tryStmt;
                if ((result = TryCatchStatement.TryParseNode(parser, out tryStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                             limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords)))
                {
                    node = tryStmt;
                }
                break;
            }

            case TokenKind.ValidateKeyword:
            {
                ValidateStatement validateStmt;
                if ((result = ValidateStatement.TryParseNode(parser, out validateStmt)))
                {
                    node = validateStmt;
                }
                break;
            }

            case TokenKind.OptionsKeyword:
            {
                OptionsStatement optionsStmt;
                if ((result = OptionsStatement.TryParseNode(parser, out optionsStmt)))
                {
                    node = optionsStmt;
                }
                break;
            }

            case TokenKind.ExecuteKeyword:
            {
                ExecuteStatement exeStmt;
                if ((result = ExecuteStatement.TryParseNode(parser, out exeStmt)))
                {
                    node = exeStmt;
                }
                break;
            }

            case TokenKind.OpenKeyword:
            {
                OpenStatement openStmt;
                if ((result = OpenStatement.TryParseNode(parser, out openStmt)))
                {
                    node = openStmt;
                }
                break;
            }

            case TokenKind.FetchKeyword:
            {
                FetchStatement fetchStmt;
                if ((result = FetchStatement.TryParseNode(parser, out fetchStmt)))
                {
                    node = fetchStmt;
                }
                break;
            }

            case TokenKind.CloseKeyword:
            {
                CloseStatement closeStmt;
                if ((result = CloseStatement.TryParseNode(parser, out closeStmt)))
                {
                    node = closeStmt;
                }
                break;
            }

            case TokenKind.ClearKeyword:
            {
                ClearStatement clearStmt;
                if ((result = ClearStatement.TryParseNode(parser, out clearStmt)))
                {
                    node = clearStmt;
                }
                break;
            }

            case TokenKind.ForeachKeyword:
            {
                ForeachStatement foreachStmt;
                if ((result = ForeachStatement.TryParseNode(parser, out foreachStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                            limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords)))
                {
                    node = foreachStmt;
                }
                break;
            }

            case TokenKind.MessageKeyword:
            {
                MessageStatement msgStmt;
                if ((result = MessageStatement.TryParseNode(parser, out msgStmt)))
                {
                    node = msgStmt;
                }
                break;
            }

            case TokenKind.MenuKeyword:
            {
                MenuBlock menuStmt;
                if ((result = MenuBlock.TryParseNode(parser, out menuStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                     limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords)))
                {
                    node = menuStmt;
                    if (limitedScopeVariableAdder != null)
                    {
                        limitedScopeVariableAdder(Genero4glAst.DialogVariable, node.StartIndex, node.EndIndex);
                    }
                }
                break;
            }

            case TokenKind.InputKeyword:
            {
                InputBlock inputStmt;
                if ((result = InputBlock.TryParseNode(parser, out inputStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                      limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords)))
                {
                    node = inputStmt;
                    if (limitedScopeVariableAdder != null)
                    {
                        limitedScopeVariableAdder(Genero4glAst.DialogVariable, node.StartIndex, node.EndIndex);
                    }
                }
                break;
            }

            case TokenKind.ConstructKeyword:
            {
                ConstructBlock constructStmt;
                if ((result = ConstructBlock.TryParseNode(parser, out constructStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                          limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords)))
                {
                    node = constructStmt;
                    if (limitedScopeVariableAdder != null)
                    {
                        limitedScopeVariableAdder(Genero4glAst.DialogVariable, node.StartIndex, node.EndIndex);
                    }
                }
                break;
            }

            case TokenKind.FlushKeyword:
            {
                FlushStatement flushStmt;
                if ((result = FlushStatement.TryParseNode(parser, out flushStmt)))
                {
                    node = flushStmt;
                }
                break;
            }

            case TokenKind.DisplayKeyword:
            {
                DisplayBlock dispStmt;
                if ((result = DisplayBlock.TryParseNode(parser, out dispStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                        limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords)))
                {
                    node = dispStmt;
                    if (limitedScopeVariableAdder != null)
                    {
                        limitedScopeVariableAdder(Genero4glAst.DialogVariable, node.StartIndex, node.EndIndex);
                    }
                }
                break;
            }

            case TokenKind.PromptKeyword:
            {
                PromptStatement promptStmt;
                if ((result = PromptStatement.TryParseNode(parser, out promptStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                           limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords)))
                {
                    node = promptStmt;
                    if (limitedScopeVariableAdder != null)
                    {
                        limitedScopeVariableAdder(Genero4glAst.DialogVariable, node.StartIndex, node.EndIndex);
                    }
                }
                break;
            }

            case TokenKind.DialogKeyword:
            {
                DialogBlock dialogBlock;
                if ((result = DialogBlock.TryParseNode(parser, out dialogBlock, containingModule, prepStatementBinders, returnStatementBinder,
                                                       limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords)))
                {
                    node = dialogBlock;
                    if (limitedScopeVariableAdder != null)
                    {
                        limitedScopeVariableAdder(Genero4glAst.DialogVariable, node.StartIndex, node.EndIndex);
                    }
                }
                break;
            }

            case TokenKind.AcceptKeyword:
            {
                AcceptStatement acceptStmt;
                if ((result = AcceptStatement.TryParseNode(parser, out acceptStmt)))
                {
                    node = acceptStmt;
                }
                break;
            }

            case TokenKind.LoadKeyword:
            {
                LoadStatement loadStmt;
                if ((result = LoadStatement.TryParseNode(parser, out loadStmt)))
                {
                    node = loadStmt;
                }
                break;
            }

            case TokenKind.CreateKeyword:
            {
                CreateStatement createStmt;
                if ((result = CreateStatement.TryParseNode(parser, out createStmt, containingModule)))
                {
                    node = createStmt;
                }
                break;
            }

            case TokenKind.BreakpointKeyword:
            {
                BreakpointStatement brkStmt;
                if ((result = BreakpointStatement.TryParseNode(parser, out brkStmt)))
                {
                    node = brkStmt;
                }
                break;
            }

            case TokenKind.OutputKeyword:
            {
                OutputToReportStatement outRpt;
                if ((result = OutputToReportStatement.TryParseNode(parser, out outRpt)))
                {
                    node = outRpt;
                }
                break;
            }

            case TokenKind.StartKeyword:
            {
                StartReportStatement startRpt;
                if ((result = StartReportStatement.TryParseNode(parser, out startRpt)))
                {
                    node = startRpt;
                }
                break;
            }

            case TokenKind.FinishKeyword:
            {
                FinishReportStatement finRpt;
                if ((result = FinishReportStatement.TryParseNode(parser, out finRpt)))
                {
                    node = finRpt;
                }
                break;
            }

            case TokenKind.TerminateKeyword:
            {
                TerminateReportStatement termRpt;
                if ((result = TerminateReportStatement.TryParseNode(parser, out termRpt)))
                {
                    node = termRpt;
                }
                break;
            }

            default:
            {
                if (SqlStatementFactory.IsValidStatementStart(parser.PeekToken().Kind))
                {
                    bool dummy;
                    result = SqlStatementFactory.TryParseSqlStatement(parser, out node, out dummy);
                }
                break;
            }
            }

            if (result)
            {
                // check for semicolon
                if (parser.PeekToken(TokenKind.Semicolon))
                {
                    parser.NextToken();
                }
            }

            return(result);
        }