Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }