예제 #1
0
        public static bool TryParseNode(Genero4glParser parser, out DisplayControlBlock node, IModuleResult containingModule, bool allowNonControlBlocks,
                                        bool isArray,
                                        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 = new DisplayControlBlock();
            bool result = true;

            node.KeyNameList = new List <VirtualKey>();

            bool isDragAndDrop = false;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.Ampersand:
            {
                // handle include file
                PreprocessorNode preNode;
                PreprocessorNode.TryParseNode(parser, out preNode);
                node.StartIndex = -1;
                break;
            }

            case TokenKind.BeforeKeyword:
            case TokenKind.AfterKeyword:
            {
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                if (parser.PeekToken(TokenKind.DisplayKeyword))
                {
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Display;
                }
                else if (parser.PeekToken(TokenKind.RowKeyword))
                {
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Row;
                }
                else
                {
                    parser.ReportSyntaxError("Unexpected keyword found in display control block.");
                    result = false;
                }
                break;
            }

            case TokenKind.OnKeyword:
            {
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                switch (parser.PeekToken().Kind)
                {
                case TokenKind.IdleKeyword:
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Idle;
                    // get the idle seconds
                    ExpressionNode idleExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out idleExpr))
                    {
                        node.IdleSeconds = idleExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid idle-seconds found in display array statement.");
                    }
                    break;

                case TokenKind.TimerKeyword:
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Timer;
                    // get the timer seconds
                    ExpressionNode timerExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out timerExpr))
                    {
                        node.TimerSeconds = timerExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid timer-seconds found in display array statement.");
                    }
                    break;

                case TokenKind.ActionKeyword:
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Action;
                    // get the action name
                    FglNameExpression actionName;
                    if (FglNameExpression.TryParseNode(parser, out actionName))
                    {
                        node.ActionName = actionName;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid action-name found in display array statement.");
                    }
                    GetActionAttributesDisplayArray(parser);
                    break;

                case TokenKind.KeyKeyword:
                    parser.NextToken();
                    node.Type = DisplayControlBlockType.Key;
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        // get the list of key names
                        VirtualKey keyName;
                        while (VirtualKey.TryGetKey(parser, out keyName))
                        {
                            node.KeyNameList.Add(keyName);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }
                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in display array block.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in display array block.");
                    }
                    break;

                case TokenKind.AppendKeyword:
                    node.Type = DisplayControlBlockType.Append;
                    parser.NextToken();
                    GetActionAttributesListmodTriggers(parser);
                    break;

                case TokenKind.InsertKeyword:
                    node.Type = DisplayControlBlockType.Insert;
                    parser.NextToken();
                    GetActionAttributesListmodTriggers(parser);
                    break;

                case TokenKind.UpdateKeyword:
                    node.Type = DisplayControlBlockType.Update;
                    parser.NextToken();
                    GetActionAttributesListmodTriggers(parser);
                    break;

                case TokenKind.DeleteKeyword:
                    node.Type = DisplayControlBlockType.Delete;
                    parser.NextToken();
                    GetActionAttributesListmodTriggers(parser);
                    break;

                case TokenKind.ExpandKeyword:
                    node.Type = DisplayControlBlockType.Expand;
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        FglNameExpression rowInd;
                        if (FglNameExpression.TryParseNode(parser, out rowInd))
                        {
                            node.RowIndex = rowInd;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid row-index found in display array statement.");
                        }

                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in display array statement.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in display array statement.");
                    }
                    break;

                case TokenKind.CollapseKeyword:
                    node.Type = DisplayControlBlockType.Collapse;
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        FglNameExpression rowInd1;
                        if (FglNameExpression.TryParseNode(parser, out rowInd1))
                        {
                            node.RowIndex = rowInd1;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid row-index found in display array statement.");
                        }
                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in display array statement.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in display array statement.");
                    }
                    break;

                case TokenKind.Drag_EnterKeyword:
                    node.Type = DisplayControlBlockType.DragEnter;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                case TokenKind.Drag_FinishKeyword:
                case TokenKind.Drag_FinishedKeyword:
                    node.Type = DisplayControlBlockType.DragFinish;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                case TokenKind.Drag_OverKeyword:
                    node.Type = DisplayControlBlockType.DragOver;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                case TokenKind.Drag_StartKeyword:
                    node.Type = DisplayControlBlockType.DragStart;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                case TokenKind.DropKeyword:
                    node.Type = DisplayControlBlockType.Drop;
                    parser.NextToken();
                    isDragAndDrop = true;
                    break;

                default:
                    parser.ReportSyntaxError("Unexpected token found in input control block.");
                    result = false;
                    break;
                }
                break;
            }

            default:
                if (!allowNonControlBlocks)
                {
                    result = false;
                }
                else
                {
                    node.StartIndex = parser.Token.Span.Start;
                }
                break;
            }

            if (result && node.StartIndex >= 0)
            {
                node.DecoratorEnd = parser.Token.Span.End;
                if (isDragAndDrop)
                {
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        FglNameExpression keyName;
                        if (FglNameExpression.TryParseNode(parser, out keyName))
                        {
                            node.DragAndDropObject = keyName;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid drag-and-drop object name found in display array statement.");
                        }

                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in input control block.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in input control block.");
                    }
                }

                // get the dialog statements
                FglStatement dispStmt;
                prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                while (DisplayStatementFactory.TryGetStatement(parser, out dispStmt, isArray, containingModule, prepStatementBinders, returnStatementBinder,
                                                               limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords) && dispStmt != null)
                {
                    node.Children.Add(dispStmt.StartIndex, dispStmt);
                    node.EndIndex = dispStmt.EndIndex;
                }
                prepStatementBinders.RemoveAt(0);

                if (node.Type == DisplayControlBlockType.None && node.Children.Count == 0)
                {
                    result = false;
                }
            }

            return(result);
        }
예제 #2
0
        public static bool TryParseNode(Genero4glParser parser, out DialogControlBlock 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            = new DialogControlBlock();
            node.StartIndex = parser.Token.Span.Start;
            node.KeyNames   = new List <VirtualKey>();
            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.Ampersand:
            {
                // handle include file
                PreprocessorNode preNode;
                PreprocessorNode.TryParseNode(parser, out preNode);
                node.StartIndex = -1;
                break;
            }

            case TokenKind.BeforeKeyword:
            case TokenKind.AfterKeyword:
                parser.NextToken();
                if (parser.PeekToken(TokenKind.DialogKeyword))
                {
                    parser.NextToken();
                    node.Type = DialogControlBlockType.Dialog;
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"dialog\" keyword in dialog statement.");
                }
                break;

            case TokenKind.CommandKeyword:
            {
                parser.NextToken();
                node.Type = DialogControlBlockType.Command;

                if (parser.PeekToken(TokenKind.KeyKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        VirtualKey vKey;
                        while (VirtualKey.TryGetKey(parser, out vKey))
                        {
                            node.KeyNames.Add(vKey);
                            if (parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting left-paren in dialog statement.");
                    }
                }

                ExpressionNode FglNameExpression;
                if (FglExpressionNode.TryGetExpressionNode(parser, out FglNameExpression))
                {
                    node.OptionName = FglNameExpression;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid expression found in dialog statement.");
                }

                if (!parser.PeekToken(TokenKind.HelpKeyword) && parser.PeekToken(TokenCategory.StringLiteral))
                {
                    ExpressionNode commentExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out commentExpr, new List <TokenKind> {
                            TokenKind.HelpKeyword
                        }))
                    {
                        node.OptionComment = commentExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid expression found in dialog statement.");
                    }
                }

                if (parser.PeekToken(TokenKind.HelpKeyword))
                {
                    parser.NextToken();
                    ExpressionNode optionNumber;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                    {
                        node.HelpNumber = optionNumber;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid expression found in dialog statement.");
                    }
                }

                break;
            }

            case TokenKind.OnKeyword:
            {
                parser.NextToken();
                switch (parser.PeekToken().Kind)
                {
                case TokenKind.ActionKeyword:
                    parser.NextToken();
                    node.Type = DialogControlBlockType.Action;
                    FglNameExpression nameExpr;
                    if (FglNameExpression.TryParseNode(parser, out nameExpr))
                    {
                        node.ActionName = nameExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid name found in dialog statement.");
                    }
                    break;

                case TokenKind.KeyKeyword:
                    parser.NextToken();
                    node.Type = DialogControlBlockType.Key;
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        VirtualKey vKey;
                        while (VirtualKey.TryGetKey(parser, out vKey))
                        {
                            node.KeyNames.Add(vKey);
                            if (parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting left-paren in dialog statement.");
                    }
                    break;

                case TokenKind.IdleKeyword:
                    parser.NextToken();
                    node.Type = DialogControlBlockType.Idle;
                    // get the idle seconds
                    ExpressionNode idleExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out idleExpr))
                    {
                        node.IdleSeconds = idleExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid idle-seconds found in dialog statement.");
                    }
                    break;

                default:
                    parser.ReportSyntaxError("Unexpected token found in dialog control block.");
                    break;
                }
                break;
            }

            default:
                break;
            }

            if (result && node.StartIndex >= 0)
            {
                // get the dialog statements
                FglStatement inputStmt;
                prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                while (DialogStatementFactory.TryGetStatement(parser, out inputStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                              limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords) && inputStmt != null)
                {
                    node.Children.Add(inputStmt.StartIndex, inputStmt);
                }
                prepStatementBinders.RemoveAt(0);

                if (node.Type == DialogControlBlockType.None && node.Children.Count == 0)
                {
                    result = false;
                }
            }

            return(result);
        }
예제 #3
0
        public static bool TryParseNode(Genero4glParser parser, out ConstructControlBlock 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 = new ConstructControlBlock();
            bool result = true;

            node.StartIndex    = parser.Token.Span.Start;
            node.FieldSpecList = new List <FglNameExpression>();
            node.KeyNameList   = new List <VirtualKey>();

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.Ampersand:
            {
                // handle include file
                PreprocessorNode preNode;
                PreprocessorNode.TryParseNode(parser, out preNode);
                node.StartIndex = -1;
                break;
            }

            case TokenKind.BeforeKeyword:
            case TokenKind.AfterKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.FieldKeyword))
                {
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Field;
                    // get the list of field specs
                    FglNameExpression fieldSpec;
                    while (FglNameExpression.TryParseNode(parser, out fieldSpec))
                    {
                        node.FieldSpecList.Add(fieldSpec);
                        if (!parser.PeekToken(TokenKind.Comma))
                        {
                            break;
                        }
                        parser.NextToken();
                    }
                }
                else if (parser.PeekToken(TokenKind.ConstructKeyword))
                {
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Construct;
                }
                else
                {
                    parser.ReportSyntaxError("Unexpected token found in construct control block.");
                    result = false;
                }
                break;
            }

            case TokenKind.OnKeyword:
            {
                parser.NextToken();
                switch (parser.PeekToken().Kind)
                {
                case TokenKind.IdleKeyword:
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Idle;
                    // get the idle seconds
                    ExpressionNode idleExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out idleExpr))
                    {
                        node.IdleSeconds = idleExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid idle-seconds found in construct statement.");
                    }
                    break;

                case TokenKind.ActionKeyword:
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Action;
                    // get the action name
                    FglNameExpression actionName;
                    if (FglNameExpression.TryParseNode(parser, out actionName))
                    {
                        node.ActionName = actionName;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid action-name found in construct statement.");
                    }
                    if (parser.PeekToken(TokenKind.InfieldKeyword))
                    {
                        parser.NextToken();
                        // get the field-spec
                        if (FglNameExpression.TryParseNode(parser, out actionName))
                        {
                            node.ActionField = actionName;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid field-spec found in construct statement.");
                        }
                    }
                    break;

                case TokenKind.KeyKeyword:
                    parser.NextToken();
                    node.Type = ConstructControlBlockType.Key;
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        // get the list of key names
                        VirtualKey keyName;
                        while (VirtualKey.TryGetKey(parser, out keyName))
                        {
                            node.KeyNameList.Add(keyName);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }
                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in construct control block.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in construct control block.");
                    }
                    break;

                default:
                    parser.ReportSyntaxError("Unexpected token found in input control block.");
                    //result = false;
                    break;
                }
                break;
            }

            default:
                result = false;
                break;
            }

            if (result && node.StartIndex >= 0)
            {
                // get the dialog statements
                FglStatement inputStmt;
                prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                while (ConstructDialogStatementFactory.TryGetStatement(parser, out inputStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                                       limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords) && inputStmt != null)
                {
                    node.Children.Add(inputStmt.StartIndex, inputStmt);
                }
                prepStatementBinders.RemoveAt(0);

                if (node.Type == ConstructControlBlockType.None && node.Children.Count == 0)
                {
                    result = false;
                }
            }

            return(result);
        }
예제 #4
0
        public static bool TryParseNode(IParser parser, out MenuAttribute node, MenuComponent component)
        {
            node = null;
            bool result = false;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.AcceleratorKeyword:
            {
                if (component == MenuComponent.Command)
                {
                    parser.NextToken();
                    result          = true;
                    node            = new MenuAttribute();
                    node.StartIndex = parser.Token.Span.Start;

                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        parser.NextToken();
                        VirtualKey vKey;
                        if (VirtualKey.TryGetKey(parser, out vKey))
                        {
                            node.Children.Add(vKey.StartIndex, vKey);
                            node.EndIndex = parser.Token.Span.End;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid accelerator key specified.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected equals token for menu attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Menu attribute \"ACCELERATOR\" is only allowed within a command block.");
                }
            }
            break;

            case TokenKind.StyleKeyword:
            case TokenKind.TagKeyword:
            {
                parser.NextToken();
                result          = true;
                node            = new MenuAttribute();
                node.StartIndex = parser.Token.Span.Start;

                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenCategory.StringLiteral))
                    {
                        parser.NextToken();
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid option found. Expecting string literal.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token for menu attribute.");
                }
            }
            break;

            case TokenKind.CommentKeyword:
            case TokenKind.ImageKeyword:
            case TokenKind.TextKeyword:
            {
                if (component == MenuComponent.Group ||
                    component == MenuComponent.Command)
                {
                    parser.NextToken();
                    result          = true;
                    node            = new MenuAttribute();
                    node.StartIndex = parser.Token.Span.Start;

                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenCategory.StringLiteral))
                        {
                            parser.NextToken();
                            node.EndIndex = parser.Token.Span.End;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid option found. Expecting string literal.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected equals token for menu attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Menu attribute not allowed for this block.");
                }
            }
            break;

            case TokenKind.HiddenKeyword:
            {
                if (component == MenuComponent.Group ||
                    component == MenuComponent.Command ||
                    component == MenuComponent.Separator)
                {
                    parser.NextToken();
                    result          = true;
                    node            = new MenuAttribute();
                    node.StartIndex = parser.Token.Span.Start;

                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        if (parser.PeekToken(TokenKind.UserKeyword))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid token found. Expecting \"USER\".");
                        }
                    }

                    node.EndIndex = parser.Token.Span.End;
                }
                else
                {
                    parser.ReportSyntaxError("Menu attribute \"HIDDEN\" not allowed for the current menu block.");
                }
            }
            break;
            }

            return(result);
        }
예제 #5
0
        public static bool TryParseNode(Genero4glParser parser, out MenuOption 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 = new MenuOption();
            bool result = true;

            prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.Ampersand:
            {
                PreprocessorNode preNode;
                PreprocessorNode.TryParseNode(parser, out preNode);
                node.StartIndex = -1;
                break;
            }

            case TokenKind.CommandKeyword:
            {
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                bool getOptionName = false;
                if (parser.PeekToken(TokenKind.KeyKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        VirtualKey keyName;
                        if (VirtualKey.TryGetKey(parser, out keyName))
                        {
                            node.KeyName = keyName;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid key-name found in menu command option.");
                        }

                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expecting right-paren in menu command option.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting left-paren in menu command option.");
                    }
                    node.DecoratorEnd = parser.Token.Span.End;
                }
                else
                {
                    getOptionName = true;
                }


                // at this point we need to try to get a menu-statement. If it doesn't work, we have some other stuff to gather
                FglStatement menuStmt = null;
                if (getOptionName || !MenuStatementFactory.TryGetStatement(parser, out menuStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                                           limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords))
                {
                    ExpressionNode optionName;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out optionName))
                    {
                        node.OptionName = optionName;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid option-name found in menu command option.");
                    }

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

                    if (parser.PeekToken(TokenCategory.StringLiteral) ||
                        parser.PeekToken(TokenCategory.Identifier))
                    {
                        ExpressionNode optionComment;
                        if (FglExpressionNode.TryGetExpressionNode(parser, out optionComment))
                        {
                            node.OptionComment = optionComment;
                        }
                    }
                    if (parser.PeekToken(TokenKind.HelpKeyword))
                    {
                        parser.NextToken();

                        ExpressionNode optionNumber;
                        if (FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                        {
                            node.HelpNumber = optionNumber;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid help-number found in menu command option.");
                        }
                    }
                }
                else if (menuStmt != null)
                {
                    node.Children.Add(menuStmt.StartIndex, menuStmt);
                }

                while (MenuStatementFactory.TryGetStatement(parser, out menuStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                            limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords))
                {
                    if (menuStmt != null && !node.Children.ContainsKey(menuStmt.StartIndex))
                    {
                        node.Children.Add(menuStmt.StartIndex, menuStmt);
                    }
                }

                break;
            }

            case TokenKind.OnKeyword:
            {
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                if (parser.PeekToken(TokenKind.ActionKeyword))
                {
                    parser.NextToken();
                    FglNameExpression action;
                    if (FglNameExpression.TryParseNode(parser, out action))
                    {
                        node.ActionName = action;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid action-name found in menu option.");
                    }
                    node.DecoratorEnd = parser.Token.Span.End;
                    FglStatement menuStmt = null;
                    while (MenuStatementFactory.TryGetStatement(parser, out menuStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                                limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords) && menuStmt != null)
                    {
                        node.Children.Add(menuStmt.StartIndex, menuStmt);
                    }
                }
                else if (parser.PeekToken(TokenKind.IdleKeyword))
                {
                    parser.NextToken();
                    ExpressionNode idleExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out idleExpr))
                    {
                        node.IdleSeconds = idleExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid idle-seconds found in menu block.");
                    }
                    node.DecoratorEnd = parser.Token.Span.End;
                    FglStatement menuStmt = null;
                    while (MenuStatementFactory.TryGetStatement(parser, out menuStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                                limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, endKeywords) && menuStmt != null)
                    {
                        node.Children.Add(menuStmt.StartIndex, menuStmt);
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expecting \"action\" or \"idle\" keyword in menu option.");
                }
                break;
            }

            default:
                result = false;
                break;
            }
            prepStatementBinders.RemoveAt(0);

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

            return(result);
        }
예제 #6
0
        public static bool TryParseNode(Genero4glParser parser, out PromptControlBlock 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 = new PromptControlBlock();
            bool result = true;

            node.KeyNameList = new List <VirtualKey>();

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.OnKeyword:
            {
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                switch (parser.PeekToken().Kind)
                {
                case TokenKind.IdleKeyword:
                    parser.NextToken();
                    node.Type = PromptControlBlockType.Idle;
                    // get the idle seconds
                    ExpressionNode idleExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out idleExpr))
                    {
                        node.IdleSeconds = idleExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid idle-seconds found in prompt statement.");
                    }
                    break;

                case TokenKind.ActionKeyword:
                    parser.NextToken();
                    node.Type = PromptControlBlockType.Action;
                    // get the action name
                    FglNameExpression actionName;
                    if (FglNameExpression.TryParseNode(parser, out actionName))
                    {
                        node.ActionName = actionName;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid action-name found in prompt statement.");
                    }
                    break;

                case TokenKind.KeyKeyword:
                    parser.NextToken();
                    node.Type = PromptControlBlockType.Key;
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        // get the list of key names
                        VirtualKey keyName;
                        while (VirtualKey.TryGetKey(parser, out keyName))
                        {
                            node.KeyNameList.Add(keyName);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }
                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected right-paren in prompt block.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected left-paren in prompt block.");
                    }
                    break;

                default:
                    parser.ReportSyntaxError("Unexpected token found in prompt block.");
                    result = false;
                    break;
                }
                break;
            }

            default:
                result = false;
                break;
            }

            if (result)
            {
                // get the dialog statements
                FglStatement dispStmt;
                prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                while (parser.StatementFactory.TryParseNode(parser, out dispStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                            limitedScopeVariableAdder, false, validExitKeywords, contextStatementFactories, null, endKeywords) && dispStmt != null)
                {
                    node.Children.Add(dispStmt.StartIndex, dispStmt);
                    node.EndIndex = dispStmt.EndIndex;
                }
                prepStatementBinders.RemoveAt(0);

                if (node.Type == PromptControlBlockType.None && node.Children.Count == 0)
                {
                    result = false;
                }
            }
            return(result);
        }
예제 #7
0
        public static bool TryParseNode(Genero4glParser parser, out OptionsStatement node)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.OptionsKeyword))
            {
                result = true;
                node   = new OptionsStatement();
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;

                while (true)
                {
                    switch (parser.PeekToken().Kind)
                    {
                    case TokenKind.SqlKeyword:
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.InterruptKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.OnKeyword) || parser.PeekToken(TokenKind.OffKeyword))
                            {
                                parser.NextToken();
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid token found in options sql interrupt statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid token found in options sql statement.");
                        }
                        break;
                    }

                    case TokenKind.InputKeyword:
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.NoKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.WrapKeyword))
                            {
                                parser.NextToken();
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid token found in options input statement.");
                            }
                        }
                        else if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                if (parser.PeekToken(TokenKind.LeftParenthesis))
                                {
                                    while (!parser.PeekToken(TokenKind.EndOfFile) && !parser.PeekToken(TokenKind.RightParenthesis))
                                    {
                                        parser.NextToken();
                                    }
                                    if (parser.PeekToken(TokenKind.RightParenthesis))
                                    {
                                        parser.NextToken();
                                    }
                                    else
                                    {
                                        parser.ReportSyntaxError("Expected rigt-paren in options input statement.");
                                    }
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Expected left-paren in options input statement.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expected left-paren in options input statement.");
                            }
                        }
                        break;
                    }

                    case TokenKind.DisplayKeyword:
                    {
                        if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                while (!parser.PeekToken(TokenKind.EndOfFile) && !parser.PeekToken(TokenKind.RightParenthesis))
                                {
                                    parser.NextToken();
                                }
                                if (parser.PeekToken(TokenKind.RightParenthesis))
                                {
                                    parser.NextToken();
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Expected rigt-paren in options input statement.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expected left-paren in options input statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid token found in options input statement.");
                        }
                        break;
                    }

                    case TokenKind.FieldKeyword:
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.OrderKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.ConstrainedKeyword) ||
                                parser.PeekToken(TokenKind.UnconstrainedKeyword) ||
                                parser.PeekToken(TokenKind.FormKeyword))
                            {
                                parser.NextToken();
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expected one of keywords \"constrained\", \"unconstrained\", or \"form\" in options field statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected keyword \"order\" in options field statement.");
                        }
                        break;
                    }

                    case TokenKind.InsertKeyword:
                    case TokenKind.DeleteKeyword:
                    case TokenKind.NextKeyword:
                    case TokenKind.PreviousKeyword:
                    case TokenKind.AcceptKeyword:
                    case TokenKind.HelpKeyword:
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.KeyKeyword))
                        {
                            parser.NextToken();
                            VirtualKey vKey;
                            if (!VirtualKey.TryGetKey(parser, out vKey))
                            {
                                parser.ReportSyntaxError("Invalid virtual key found in options statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected keyword \"key\" in options statement.");
                        }
                        break;
                    }

                    case TokenKind.OnKeyword:
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.TerminateKeyword) &&
                            parser.PeekToken(TokenKind.SignalKeyword, 2) &&
                            parser.PeekToken(TokenKind.CallKeyword, 3))
                        {
                            parser.NextToken();
                            parser.NextToken();
                            parser.NextToken();
                            FglNameExpression funcName;
                            if (!FglNameExpression.TryParseNode(parser, out funcName))
                            {
                                parser.ReportSyntaxError("Invalid function name found in options statement.");
                            }
                        }
                        else if (parser.PeekToken(TokenKind.CloseKeyword) &&
                                 parser.PeekToken(TokenKind.ApplicationKeyword, 2) &&
                                 parser.PeekToken(TokenKind.CallKeyword, 3))
                        {
                            parser.NextToken();
                            parser.NextToken();
                            parser.NextToken();
                            FglNameExpression funcName;
                            if (!FglNameExpression.TryParseNode(parser, out funcName))
                            {
                                parser.ReportSyntaxError("Invalid function name found in options statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid token found in options statement.");
                        }
                        break;
                    }

                    default:
                    {
                        parser.ReportSyntaxError("Unsupported options statement found.");
                        break;
                    }
                    }

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

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

            return(result);
        }
예제 #8
0
        public static bool TryParseNode(IParser parser, out ActionAttribute node)
        {
            bool result = false;

            node = null;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.AcceleratorKeyword:
            case TokenKind.Accelerator2Keyword:
            case TokenKind.Accelerator3Keyword:
            case TokenKind.Accelerator4Keyword:
            {
                parser.NextToken();
                result          = true;
                node            = new ActionAttribute();
                node.StartIndex = parser.Token.Span.Start;

                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    VirtualKey vKey;
                    if (VirtualKey.TryGetKey(parser, out vKey))
                    {
                        node.Children.Add(vKey.StartIndex, vKey);
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid accelerator key specified.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token for action attribute.");
                }
            }
            break;

            case TokenKind.DefaultViewKeyword:
            case TokenKind.ContextMenuKeyword:
            {
                parser.NextToken();
                result          = true;
                node            = new ActionAttribute();
                node.StartIndex = parser.Token.Span.Start;

                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.AutoKeyword) ||
                        parser.PeekToken(TokenKind.YesKeyword) ||
                        parser.PeekToken(TokenKind.NoKeyword))
                    {
                        parser.NextToken();
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid option specified. Allowed values are Auto, Yes, or No.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token for action attribute.");
                }
            }
            break;

            case TokenKind.CommentKeyword:
            case TokenKind.ImageKeyword:
            case TokenKind.TextKeyword:
            {
                parser.NextToken();
                result          = true;
                node            = new ActionAttribute();
                node.StartIndex = parser.Token.Span.Start;

                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenCategory.StringLiteral))
                    {
                        parser.NextToken();
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid option found. Expecting string literal.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token for action attribute.");
                }
            }
            break;

            case TokenKind.ValidateKeyword:
            {
                parser.NextToken();
                result          = true;
                node            = new ActionAttribute();
                node.StartIndex = parser.Token.Span.Start;

                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.NoKeyword))
                    {
                        parser.NextToken();
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid validate value specified. Allowed values is No.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token for action attribute.");
                }
            }
            break;
            }

            return(result);
        }