Ejemplo n.º 1
0
        public static bool TryParseNode(Genero4glParser parser, out ActionAttributesListmodTriggers node)
        {
            node            = new ActionAttributesListmodTriggers();
            node.StartIndex = parser.Token.Span.Start;
            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.TextKeyword:
            case TokenKind.CommentKeyword:
            case TokenKind.ImageKeyword:
            case TokenKind.AcceleratorKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in display attribute.");
                }

                // get the help number
                StringExpressionNode stringExpressionNode;
                if (!StringExpressionNode.TryGetExpressionNode(parser, out stringExpressionNode))
                {
                    parser.ReportSyntaxError("Invalid string expression found in action attribute.");
                }
            }
            break;

            case TokenKind.DefaultViewKeyword:
            case TokenKind.ContextMenuKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    var tokKind = parser.NextToken().Kind;
                    if (tokKind != TokenKind.YesKeyword ||
                        tokKind != TokenKind.NoKeyword ||
                        tokKind != TokenKind.AutoKeyword)
                    {
                        parser.ReportSyntaxError("Invalid token found in action attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in display attribute.");
                }
            }
            break;

            default:
                result = false;
                break;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static bool TryParseNode(IParser parser, out FormClause node)
        {
            node = null;
            bool result = false;

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

                StringExpressionNode expr;
                if (StringExpressionNode.TryGetExpressionNode(parser, out expr))
                {
                    node.FormFile = expr;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid token found, expecting string literal.");
                }

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

            return(result);
        }
Ejemplo n.º 3
0
        public static bool TryParseDefine(Genero4glParser parser, out SchemaSpecificationNode defNode)
        {
            defNode = null;
            bool result = false;

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

                FglNameExpression nameExp;
                if (FglNameExpression.TryParseNode(parser, out nameExp))
                {
                    defNode.SchemaName = nameExp;
                    defNode.EndIndex   = parser.Token.Span.End;
                }
                else
                {
                    StringExpressionNode strExp;
                    if (StringExpressionNode.TryGetExpressionNode(parser, out strExp))
                    {
                        defNode.SchemaName = nameExp;
                        defNode.EndIndex   = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError(defNode.StartIndex, parser.Token.Span.End, "Invalid token type found.");
                    }
                }
            }
            else
            {
                if (parser.PeekToken(TokenKind.DescribeKeyword))
                {
                    defNode            = new SchemaSpecificationNode();
                    defNode.StartIndex = parser.Token.Span.Start;
                    parser.NextToken();
                    result = true;
                }

                if (parser.PeekToken(TokenKind.DatabaseKeyword))
                {
                    if (defNode == null)
                    {
                        defNode            = new SchemaSpecificationNode();
                        defNode.StartIndex = parser.Token.Span.Start;
                        parser.NextToken();
                        result = true;
                    }

                    parser.NextToken();
                    parser.NextToken();
                    FglNameExpression nameExp;
                    if (FglNameExpression.TryParseNode(parser, out nameExp))
                    {
                        defNode.SchemaName = nameExp;
                        defNode.EndIndex   = parser.Token.Span.End;
                        defNode.IsComplete = true;
                    }
                    else
                    {
                        StringExpressionNode strExp;
                        if (StringExpressionNode.TryGetExpressionNode(parser, out strExp))
                        {
                            defNode.SchemaName = nameExp;
                            defNode.EndIndex   = parser.Token.Span.End;
                            defNode.IsComplete = true;
                        }
                        else
                        {
                            parser.ReportSyntaxError(defNode.StartIndex, parser.Token.Span.End, "Invalid token type found.");
                        }
                    }
                }
                else if (defNode != null)
                {
                    parser.ReportSyntaxError(defNode.StartIndex, parser.Token.Span.End, "Legacy schema specification is incomplete.");
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static bool TryParseNode(IParser parser, out ScreenNode node)
        {
            bool result = false;

            node = null;

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

                if (parser.PeekToken(TokenKind.SizeKeyword))
                {
                    parser.NextToken();
                    var linesVal = parser.NextToken().Value.ToString();
                    int tempLines;
                    if (int.TryParse(linesVal, out tempLines))
                    {
                        node.Lines = tempLines;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid value found for screen height.");
                    }

                    if (parser.PeekToken(TokenKind.ByKeyword))
                    {
                        parser.NextToken();
                        var charsVal = parser.NextToken().Value.ToString();
                        if (int.TryParse(linesVal, out tempLines))
                        {
                            node.Chars = tempLines;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid value found for screen width.");
                        }
                    }
                }

                if (parser.PeekToken(TokenKind.TitleKeyword))
                {
                    parser.NextToken();
                    StringExpressionNode strExpr;
                    if (StringExpressionNode.TryGetExpressionNode(parser, out strExpr))
                    {
                        node.Title = strExpr.LiteralValue;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid screen title found.");
                    }
                }

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

                    while (!parser.PeekToken(TokenKind.RightBrace))
                    {
                        parser.NextToken();
                    }

                    if (parser.PeekToken(TokenKind.RightBrace))
                    {
                        parser.ReportSyntaxError("Expected right-brace.");
                    }

                    if (parser.PeekToken(TokenKind.EndKeyword))
                    {
                        parser.NextToken();
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected left-brace.");
                }

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

            return(result);
        }
Ejemplo n.º 5
0
        public static bool TryParseAttribute(IParser parser, out LayoutAttribute attrib)
        {
            attrib = new LayoutAttribute();
            bool result = true;

            int?intVal = null;
            StringExpressionNode stringNode = null;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.ImageKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.Image;

                if (StringExpressionNode.TryGetExpressionNode(parser, out stringNode))
                {
                    attrib.Image = stringNode;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid token found in Image attribute, expected string literal.");
                }

                break;

            case TokenKind.MinHeightKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.MinHeight;

                intVal = GetIntegerValue(parser);
                if (intVal.HasValue)
                {
                    attrib.MinHeight = intVal.Value;
                }
                break;

            case TokenKind.MinWidthKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.MinWidth;

                intVal = GetIntegerValue(parser);
                if (intVal.HasValue)
                {
                    attrib.MinWidth = intVal.Value;
                }

                break;

            case TokenKind.SpacingKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.Spacing;

                if (parser.PeekToken(TokenKind.NormalKeyword))
                {
                    parser.NextToken();
                    attrib.Spacing = LayoutSpacing.Normal;
                }
                else if (parser.PeekToken(TokenKind.CompactKeyword))
                {
                    parser.NextToken();
                    attrib.Spacing = LayoutSpacing.Compact;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid token found in Spacing attribute, expected \"NORMAL\" or \"COMPACT\".");
                }

                break;

            case TokenKind.StyleKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.Style;

                if (StringExpressionNode.TryGetExpressionNode(parser, out stringNode))
                {
                    attrib.Style = stringNode;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid token found in Style attribute, expected string literal.");
                }

                break;

            case TokenKind.TextKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.Text;

                if (StringExpressionNode.TryGetExpressionNode(parser, out stringNode))
                {
                    attrib.Text = stringNode;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid token found in Text attribute, expected string literal.");
                }
                break;

            case TokenKind.TagKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.Tag;

                if (StringExpressionNode.TryGetExpressionNode(parser, out stringNode))
                {
                    attrib.Tag = stringNode;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid token found in Tag attribute, expected string literal.");
                }

                break;

            case TokenKind.VersionKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.Version;

                if (StringExpressionNode.TryGetExpressionNode(parser, out stringNode))
                {
                    attrib.Version = stringNode;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid token found in Version attribute, expected string literal.");
                }
                break;

            case TokenKind.WindowStyleKeyword:
                parser.NextToken();
                attrib.StartIndex = parser.Token.Span.Start;
                attrib.Type       = LayoutAttributes.WindowStyle;

                if (StringExpressionNode.TryGetExpressionNode(parser, out stringNode))
                {
                    attrib.WindowStyle = stringNode;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid token found in WindowStyle attribute, expected string literal.");
                }
                break;

            default:
                result = false;
                attrib = null;
                break;
            }

            if (attrib != null)
            {
                attrib.EndIndex = parser.Token.Span.End;
            }


            return(result);
        }