Beispiel #1
0
        public static bool TryParseNode(IParser parser, out ActionNode node)
        {
            bool result = false;

            node = null;

            if (parser.PeekToken(TokenKind.ActionKeyword))
            {
                node   = new ActionNode();
                result = true;
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                node.Attributes = new List <ActionAttribute>();


                // TODO: get the action id and attributes
                NameExpression nameExpr;
                if (NameExpression.TryParseNode(parser, out nameExpr))
                {
                    node.ActionIdentifier = nameExpr;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid action identifier found.");
                }

                if (parser.PeekToken(TokenKind.LeftParenthesis))
                {
                    parser.NextToken();
                    ActionAttribute attrib;
                    while (ActionAttribute.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 action attributes section.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected left-paren in action attributes section.");
                }

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

            return(result);
        }
Beispiel #2
0
        public static bool TrParseNode(IParser parser, out TopMenuSeparator node)
        {
            bool result = false;

            node = null;

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

                NameExpression nameExpr;
                if (NameExpression.TryParseNode(parser, out nameExpr))
                {
                    node.Identifier = nameExpr;

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

                        MenuAttribute attrib;
                        while (MenuAttribute.TryParseNode(parser, out attrib, MenuComponent.Separator))
                        {
                            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 group attributes section.");
                        }
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Invalid COMMAND name found.");
                }
            }

            return(result);
        }
Beispiel #3
0
        public static bool TryParseNode(IParser parser, out TopMenuNode node)
        {
            node = null;
            bool result = false;

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

                NameExpression nameExpr;
                if (NameExpression.TryParseNode(parser, out nameExpr))
                {
                    node.MenuName = nameExpr;
                }

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

                    MenuAttribute attrib;
                    while (MenuAttribute.TryParseNode(parser, out attrib, MenuComponent.Menu))
                    {
                        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 menu attributes section.");
                    }
                }

                TopMenuGroup group;
                while (TopMenuGroup.TryParseNode(parser, out group))
                {
                    node.Children.Add(group.StartIndex, group);
                }

                if (parser.PeekToken(TokenKind.EndKeyword))
                {
                    parser.NextToken();
                    node.EndIndex = parser.Token.Span.End;
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"end\" token.");
                }

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

            return(result);
        }
Beispiel #4
0
        public static bool TryParseNode(IParser parser, out TopMenuGroup node)
        {
            bool result = false;

            node = null;

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

                NameExpression nameExpr;
                if (NameExpression.TryParseNode(parser, out nameExpr))
                {
                    node.Identifier = nameExpr;

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

                        MenuAttribute attrib;
                        while (MenuAttribute.TryParseNode(parser, out attrib, MenuComponent.Group))
                        {
                            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 group attributes section.");
                        }
                    }

                    bool continueGroup = true;
                    while (continueGroup)
                    {
                        switch (parser.PeekToken().Kind)
                        {
                        case TokenKind.CommandKeyword:
                        {
                            TopMenuCommand cmd;
                            if (TopMenuCommand.TrParseNode(parser, out cmd))
                            {
                                node.Children.Add(cmd.StartIndex, cmd);
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid top menu command block found.");
                            }
                        }
                        break;

                        case TokenKind.SeparatorKeyword:
                        {
                            TopMenuSeparator sep;
                            if (TopMenuSeparator.TrParseNode(parser, out sep))
                            {
                                node.Children.Add(sep.StartIndex, sep);
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid top menu separator block found.");
                            }
                        }
                        break;

                        case TokenKind.GroupKeyword:
                        {
                            TopMenuGroup grp;
                            if (TryParseNode(parser, out grp))
                            {
                                node.Children.Add(grp.StartIndex, grp);
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid top menu group block found.");
                            }
                        }
                        break;

                        default:
                            continueGroup = false;
                            break;
                        }
                    }

                    if (parser.PeekToken(TokenKind.EndKeyword))
                    {
                        parser.NextToken();
                        node.EndIndex = parser.Token.Span.Start;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid token found, expected \"end\".");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Invalid GROUP name found.");
                }
            }

            return(result);
        }
Beispiel #5
0
        public static bool TryParseNode(IParser parser, out ToolbarNode node)
        {
            bool result = false;

            node = null;

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

                NameExpression nameExpr;
                if (NameExpression.TryParseNode(parser, out nameExpr))
                {
                    node.Identifier = nameExpr;

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

                        ToolbarAttribute attrib;
                        while (ToolbarAttribute.TryParseNode(parser, out attrib, ToolbarComponent.Toolbar))
                        {
                            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 toolbar attributes section.");
                        }
                    }

                    bool             continueToolbar = true;
                    ToolbarItem      item;
                    ToolbarSeparator sep;
                    while (continueToolbar)
                    {
                        if (ToolbarItem.TryParseNode(parser, out item))
                        {
                            node.Children.Add(item.StartIndex, item);
                            continue;
                        }
                        else if (ToolbarSeparator.TryParseNode(parser, out sep))
                        {
                            node.Children.Add(sep.StartIndex, sep);
                            continue;
                        }
                        else
                        {
                            continueToolbar = false;
                        }
                    }

                    if (parser.PeekToken(TokenKind.EndKeyword))
                    {
                        parser.NextToken();
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"end\" token.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Invalid toolbar identifier found.");
                }
            }

            return(result);
        }
Beispiel #6
0
        public static bool TryParseNode(IParser parser, out ToolbarItem node)
        {
            bool result = false;

            node = null;

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

                NameExpression nameExpr;
                if (NameExpression.TryParseNode(parser, out nameExpr))
                {
                    node.Identifier = nameExpr;

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

                        ToolbarAttribute attrib;
                        while (ToolbarAttribute.TryParseNode(parser, out attrib, ToolbarComponent.Item))
                        {
                            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 toolbar item attributes section.");
                        }
                    }

                    if (parser.PeekToken(TokenKind.EndKeyword))
                    {
                        parser.NextToken();
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"end\" token.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Invalid toolbar item identifier found.");
                }
            }

            return(result);
        }
Beispiel #7
0
        public static bool TryParseNode(IParser parser, out SchemaSpecificationNode node)
        {
            node = null;
            bool result = false;

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

                if (parser.PeekToken(TokenKind.FormonlyKeyword) ||
                    parser.PeekToken(TokenCategory.StringLiteral))
                {
                    node.AlternateSchema = parser.NextToken();
                }
                else
                {
                    NameExpression nameExp;
                    if (NameExpression.TryParseNode(parser, out nameExp))
                    {
                        node.SchemaName = nameExp;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid schema name found.");
                    }
                }

                node.EndIndex = parser.Token.Span.End;
            }
            else if (parser.PeekToken(TokenKind.DatabaseKeyword))
            {
                node            = new SchemaSpecificationNode();
                node.StartIndex = parser.Token.Span.Start;
                parser.NextToken();
                result = true;

                if (parser.PeekToken(TokenKind.FormonlyKeyword) ||
                    parser.PeekToken(TokenCategory.StringLiteral))
                {
                    node.AlternateSchema = parser.NextToken();
                }
                else
                {
                    NameExpression nameExp;
                    if (NameExpression.TryParseNode(parser, out nameExp))
                    {
                        node.SchemaName = nameExp;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid schema name found.");
                    }
                }

                if (parser.PeekToken(TokenKind.WithoutKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.NullKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.InputKeyword))
                        {
                            parser.NextToken();
                            node.WithoutNullInput = true;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expecting \"without null input\".");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting \"without null input\".");
                    }
                }

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

            return(result);
        }