Exemplo n.º 1
0
        public static bool TryParseNode(IParser parser, out NeedStatement node)
        {
            node = null;
            bool result = false;

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

                ExpressionNode numLines;
                if (FglExpressionNode.TryGetExpressionNode(parser, out numLines))
                {
                    node.NumLines = numLines;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid expression found in need statement.");
                }

                if (parser.PeekToken(TokenKind.LineKeyword) || parser.PeekToken(TokenKind.LinesKeyword))
                {
                    parser.NextToken();
                }

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

            return(result);
        }
Exemplo n.º 2
0
        public static bool TryParseNode(Genero4glParser parser, out SleepStatement node)
        {
            node = null;
            bool result = false;

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

                ExpressionNode expr;
                if (!FglExpressionNode.TryGetExpressionNode(parser, out expr, Genero4glAst.ValidStatementKeywords.ToList()))
                {
                    parser.ReportSyntaxError("Invalid expression found in sleep statement.");
                }
                else
                {
                    node.SleepSeconds = expr;
                }

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

            return(result);
        }
Exemplo n.º 3
0
        public static bool TryParseNode(Genero4glParser parser, out LocateStatement defNode)
        {
            defNode = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.LocateKeyword))
            {
                result  = true;
                defNode = new LocateStatement();
                parser.NextToken();
                defNode.StartIndex      = parser.Token.Span.Start;
                defNode.TargetVariables = new List <FglNameExpression>();

                FglNameExpression name;
                while (FglNameExpression.TryParseNode(parser, out name))
                {
                    defNode.TargetVariables.Add(name);
                    if (!parser.PeekToken(TokenKind.Comma))
                    {
                        break;
                    }
                    parser.NextToken();
                }

                if (parser.PeekToken(TokenKind.InKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.MemoryKeyword))
                    {
                        parser.NextToken();
                        defNode.Location = LocateLocation.Memory;
                    }
                    else if (parser.PeekToken(TokenKind.FileKeyword))
                    {
                        parser.NextToken();
                        defNode.Location = LocateLocation.File;

                        ExpressionNode filename;
                        if (FglExpressionNode.TryGetExpressionNode(parser, out filename, Genero4glAst.ValidStatementKeywords.ToList()))
                        {
                            defNode.Filename = filename;
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Locate statement can only specify memory or a file.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Locate statement missing \"in\" keyword.");
                }

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

            return(result);
        }
Exemplo n.º 4
0
        public static bool TryParseNode(Genero4glParser parser, out DialogAttribute node)
        {
            node            = new DialogAttribute();
            node.StartIndex = parser.Token.Span.Start;
            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.FieldKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.OrderKeyword))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"order\" keyword in dialog attribute.");
                }
                if (parser.PeekToken(TokenKind.FormKeyword))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"form\" keyword in dialog attribute.");
                }
                break;
            }

            case TokenKind.UnbufferedKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    ExpressionNode boolExpr;
                    if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                            TokenKind.Comma, TokenKind.RightParenthesis
                        }))
                    {
                        parser.ReportSyntaxError("Invalid boolean expression found in dialog attribute.");
                    }
                }
                break;
            }

            default:
                result = false;
                break;
            }

            return(result);
        }
Exemplo n.º 5
0
        public static bool TryParseNode(IParser parser, out PrintxStatement node)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.PrintxKeyword))
            {
                result = true;
                node   = new PrintxStatement();
                parser.NextToken();
                node.StartIndex  = parser.Token.Span.Start;
                node.Expressions = new List <ExpressionNode>();

                if (parser.PeekToken(TokenKind.NameKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        parser.NextToken();
                        FglNameExpression name;
                        if (FglNameExpression.TryParseNode(parser, out name))
                        {
                            node.Name = name;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid name expression found in printx statement.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected '=' in printx statement.");
                    }
                }

                ExpressionNode expr;
                while (FglExpressionNode.TryGetExpressionNode(parser, out expr))
                {
                    node.Expressions.Add(expr);
                    if (parser.PeekToken(TokenKind.Comma))
                    {
                        parser.NextToken();
                    }
                    else
                    {
                        break;
                    }
                }

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

            return(result);
        }
Exemplo n.º 6
0
        public static bool TryParseNode(Genero4glParser parser, out MessageAttribute node)
        {
            node            = new MessageAttribute();
            node.StartIndex = parser.Token.Span.Start;
            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.BlackKeyword:
            case TokenKind.BlueKeyword:
            case TokenKind.CyanKeyword:
            case TokenKind.GreenKeyword:
            case TokenKind.MagentaKeyword:
            case TokenKind.RedKeyword:
            case TokenKind.WhiteKeyword:
            case TokenKind.YellowKeyword:
            case TokenKind.BoldKeyword:
            case TokenKind.DimKeyword:
            case TokenKind.InvisibleKeyword:
            case TokenKind.NormalKeyword:
            case TokenKind.ReverseKeyword:
            case TokenKind.BlinkKeyword:
            case TokenKind.UnderlineKeyword:
                parser.NextToken();
                break;

            case TokenKind.StyleKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in message attribute.");
                }

                // get the style name
                ExpressionNode styleName;
                if (!FglExpressionNode.TryGetExpressionNode(parser, out styleName))
                {
                    parser.ReportSyntaxError("Invalid style name found in message attribute.");
                }
                break;
            }

            default:
                result = false;
                break;
            }

            return(result);
        }
Exemplo n.º 7
0
        public static bool TryParseNode(IParser parser, out SkipStatement node)
        {
            node = null;
            bool result = false;

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

                if (parser.PeekToken(TokenKind.ToKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.TopKeyword) &&
                        parser.PeekToken(TokenKind.OfKeyword, 2) &&
                        parser.PeekToken(TokenKind.PageKeyword, 3))
                    {
                        parser.NextToken();
                        parser.NextToken();
                        parser.NextToken();
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"top of page\" in skip statement.");
                    }
                }
                else
                {
                    ExpressionNode numLines;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out numLines))
                    {
                        node.NumLines = numLines;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid expression found in skip statement.");
                    }

                    if (parser.PeekToken(TokenKind.LineKeyword) || parser.PeekToken(TokenKind.LinesKeyword))
                    {
                        parser.NextToken();
                    }
                }

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

            return(result);
        }
Exemplo n.º 8
0
        public static bool TryParseNode(Genero4glParser parser, out PrepareStatement defNode, IModuleResult containingModule)
        {
            defNode = null;
            bool result = false;

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

                if (parser.PeekToken(TokenCategory.Identifier) || parser.PeekToken(TokenCategory.Keyword))
                {
                    parser.NextToken();
                    defNode.Identifier = parser.Token.Token.Value.ToString();

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

                        ExpressionNode exprNode;
                        if (FglExpressionNode.TryGetExpressionNode(parser, out exprNode) && exprNode != null)
                        {
                            defNode.Children.Add(exprNode.StartIndex, exprNode);
                            defNode.EndIndex   = exprNode.EndIndex;
                            defNode.IsComplete = true;

                            containingModule.BindCursorResult(defNode, parser);
                        }
                        else
                        {
                            parser.ReportSyntaxError("SQL prepare statement must specify an expression to prepare.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("SQL prepare statement is missing keyword \"from\".");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("SQL prepare statement must specify an identifier to prepare.");
                }
            }

            return(result);
        }
Exemplo n.º 9
0
        public static bool TryParseNode(Genero4glParser parser, out ReturnStatement node)
        {
            node = null;
            bool result = false;

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

                while (true)
                {
                    // TODO: not sure about this....it was in here for a reason, right?
                    var tok = parser.PeekToken();
                    if (Genero4glAst.ValidStatementKeywords.Contains(tok.Kind) &&
                        !Genero4glAst.Acceptable_ReturnVariableName_StatementKeywords.Contains(tok.Kind))
                    {
                        // TODO: need to check and see if there are any variables defined with the same name as the statement keyword?
                        break;
                    }

                    ExpressionNode expr;
                    if (!FglExpressionNode.TryGetExpressionNode(parser, out expr))
                    {
                        break;
                    }
                    node.Returns.Add(expr);

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

            return(result);
        }
Exemplo n.º 10
0
        public static bool TryParseNode(IParser parser, out BracketWrappedExpressionNode node)
        {
            node = null;
            bool result = false;

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

                ExpressionNode expr;
                while (FglExpressionNode.TryGetExpressionNode(parser, out expr, new List <TokenKind> {
                    TokenKind.Comma, TokenKind.LeftBracket
                }))
                {
                    node.Parameters.Add(expr);
                    if (!parser.PeekToken(TokenKind.Comma))
                    {
                        break;
                    }
                    parser.NextToken();
                }

                // get the right paren
                if (parser.PeekToken(TokenKind.RightBracket))
                {
                    parser.NextToken(); // TODO: not sure if this is needed
                }
                else
                {
                    parser.ReportSyntaxError("Call statement missing right bracket.");
                }
                node.EndIndex = parser.Token.Span.End;
            }
            return(result);
        }
Exemplo n.º 11
0
        public static bool TryParseNode(Genero4glParser parser, out ConstructBlock node,
                                        IModuleResult containingModule,
                                        List <Func <PrepareStatement, bool> > prepStatementBinders,
                                        Func <ReturnStatement, ParserResult> returnStatementBinder   = null,
                                        Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null,
                                        List <TokenKind> validExitKeywords = null,
                                        IEnumerable <ContextStatementFactory> contextStatementFactories = null,
                                        HashSet <TokenKind> endKeywords = null)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.ConstructKeyword))
            {
                result = true;
                node   = new ConstructBlock();
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                node.ColumnList = new List <FglNameExpression>();
                node.FieldList  = new List <FglNameExpression>();
                node.Attributes = new List <ConstructAttribute>();

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

                        // Implicit field mapping
                        node.IsImplicitMapping = true;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"name\" token in construct statement.");
                    }
                }

                FglNameExpression varName;
                if (FglNameExpression.TryParseNode(parser, out varName))
                {
                    node.Variable = varName;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid variable name found in construct statement.");
                }

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

                if (parser.PeekToken(TokenKind.OnKeyword))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expecting \"on\" keyword in construct statement.");
                }

                FglNameExpression colName;
                while (FglNameExpression.TryParseNode(parser, out colName))
                {
                    node.ColumnList.Add(colName);
                    if (!parser.PeekToken(TokenKind.Comma))
                    {
                        break;
                    }
                    parser.NextToken();
                }

                if (!node.IsImplicitMapping)
                {
                    if (parser.PeekToken(TokenKind.FromKeyword))
                    {
                        parser.NextToken();

                        // read the field list
                        FglNameExpression nameExpr;
                        while (FglNameExpression.TryParseNode(parser, out nameExpr))
                        {
                            node.FieldList.Add(nameExpr);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"from\" token in construct statement.");
                    }
                }

                if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();

                        // get the list of display or control attributes
                        ConstructAttribute attrib;
                        while (ConstructAttribute.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 construct attributes section.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting left-paren in construct attributes section.");
                    }
                }

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

                    // get the help number
                    ExpressionNode optionNumber;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                    {
                        node.HelpNumber = optionNumber;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid help-number found in construct statement.");
                    }
                }

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

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

                bool hasControlBlocks = false;
                ConstructControlBlock icb;
                prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                while (ConstructControlBlock.TryParseNode(parser, out icb, containingModule, prepStatementBinders, returnStatementBinder,
                                                          limitedScopeVariableAdder, validExits, contextStatementFactories, newEndKeywords) && icb != null)
                {
                    if (icb.StartIndex < 0)
                    {
                        continue;
                    }

                    node.Children.Add(icb.StartIndex, icb);
                    hasControlBlocks = true;
                    if (parser.PeekToken(TokenKind.EndOfFile) ||
                        (parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.ConstructKeyword, 2)))
                    {
                        break;
                    }
                }
                prepStatementBinders.RemoveAt(0);

                if (hasControlBlocks ||
                    (parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.ConstructKeyword, 2)))
                {
                    if (!(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.ConstructKeyword, 2)))
                    {
                        parser.ReportSyntaxError("A construct block must be terminated with \"end construct\".");
                    }
                    else
                    {
                        parser.NextToken(); // advance to the 'end' token
                        parser.NextToken(); // advance to the 'construct' token
                        node.EndIndex = parser.Token.Span.End;
                    }
                }
            }

            return(result);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public static bool TryParseNode(Genero4glParser parser, out IfStatement 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,
                                        ExpressionParsingOptions expressionOptions = null,
                                        HashSet <TokenKind> endKeywords            = null)
        {
            node = null;
            bool result = false;

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

                ExpressionNode conditionExpr;
                if (!FglExpressionNode.TryGetExpressionNode(parser, out conditionExpr, new List <TokenKind> {
                    TokenKind.ThenKeyword
                }, expressionOptions))
                {
                    parser.ReportSyntaxError("An if statement must have a condition expression.");
                }
                else
                {
                    node.ConditionExpression = conditionExpr;
                }

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

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

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

                    IfBlockContentsNode ifBlock;
                    prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                    if (IfBlockContentsNode.TryParseNode(parser, out ifBlock, containingModule, prepStatementBinders, returnStatementBinder,
                                                         limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, expressionOptions, newEndKeywords))
                    {
                        if (ifBlock != null)
                        {
                            node.Children.Add(ifBlock.StartIndex, ifBlock);
                        }
                    }

                    if (parser.PeekToken(TokenKind.ElseKeyword))
                    {
                        parser.NextToken();
                        ElseBlockContentsNode elseBlock;
                        if (ElseBlockContentsNode.TryParseNode(parser, out elseBlock, containingModule, prepStatementBinders, returnStatementBinder,
                                                               limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, expressionOptions, newEndKeywords))
                        {
                            if (elseBlock != null)
                            {
                                node.Children.Add(elseBlock.StartIndex, elseBlock);

                                // Add the span of "else" to the additional decorators
                                node.AdditionalDecoratorRanges.Add(elseBlock.StartIndex, elseBlock.StartIndex + 4);
                            }
                        }
                    }
                    prepStatementBinders.RemoveAt(0);

                    if (!(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.IfKeyword, 2)))
                    {
                        parser.ReportSyntaxError("An if statement must be terminated with \"end if\".");
                    }
                    else
                    {
                        parser.NextToken(); // advance to the 'end' token
                        parser.NextToken(); // advance to the 'if' token
                        node.EndIndex = parser.Token.Span.End;
                    }
                }
                else
                {
                    parser.ReportSyntaxError("An if statement must have a \"then\" keyword prior to containing code.");
                }
            }

            return(result);
        }
Exemplo n.º 15
0
        public static bool TryParseNode(Genero4glParser parser, out MenuBlock node,
                                        IModuleResult containingModule,
                                        List <Func <PrepareStatement, bool> > prepStatementBinders,
                                        Func <ReturnStatement, ParserResult> returnStatementBinder   = null,
                                        Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null,
                                        List <TokenKind> validExitKeywords = null,
                                        IEnumerable <ContextStatementFactory> contextStatementFactories = null,
                                        HashSet <TokenKind> endKeywords = null)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.MenuKeyword))
            {
                result = true;
                node   = new MenuBlock();
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                node.Attributes = new List <ExpressionNode>();

                if (parser.PeekToken(TokenCategory.StringLiteral))
                {
                    parser.NextToken();
                    node.MenuTitle = parser.Token.Token.Value.ToString();
                }

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

                if (parser.PeekToken(TokenKind.AttributesKeyword) ||
                    parser.PeekToken(TokenKind.AttributeKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        ExpressionNode expr;
                        while (FglExpressionNode.TryGetExpressionNode(parser, out expr, new List <TokenKind> {
                            TokenKind.Comma, TokenKind.RightParenthesis
                        }))
                        {
                            node.Attributes.Add(expr);
                            if (!parser.PeekToken(TokenKind.Comma))
                            {
                                break;
                            }
                            parser.NextToken();
                        }

                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expecting right-paren for menu attributes.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting left-paren for menu attributes.");
                    }
                }

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

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

                int beforeStart = -1, beforeDecEnd = -1, beforeEnd = -1;
                if (parser.PeekToken(TokenKind.BeforeKeyword))
                {
                    parser.NextToken();
                    beforeStart = parser.Token.Span.Start;
                    if (parser.PeekToken(TokenKind.MenuKeyword))
                    {
                        parser.NextToken();
                        beforeDecEnd = parser.Token.Span.End;
                        FglStatement        menuStmt;
                        List <FglStatement> stmts = new List <FglStatement>();
                        prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                        while (MenuStatementFactory.TryGetStatement(parser, out menuStmt, containingModule, prepStatementBinders, returnStatementBinder,
                                                                    limitedScopeVariableAdder, validExits, contextStatementFactories, newEndKeywords))
                        {
                            stmts.Add(menuStmt);
                            beforeEnd = menuStmt.EndIndex;
                        }
                        prepStatementBinders.RemoveAt(0);

                        if (beforeEnd < 0)
                        {
                            beforeEnd = beforeDecEnd;
                        }
                        MenuOption beforeMenu = new MenuOption(beforeStart, beforeDecEnd, beforeEnd, stmts);
                        if (beforeMenu != null)
                        {
                            node.Children.Add(beforeMenu.StartIndex, beforeMenu);
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting \"before\" keyword for menu block.");
                    }
                }

                prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                while (!parser.PeekToken(TokenKind.EndOfFile) &&
                       !(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.MenuKeyword, 2)))
                {
                    MenuOption menuOpt;
                    if (MenuOption.TryParseNode(parser, out menuOpt, containingModule, prepStatementBinders, returnStatementBinder,
                                                limitedScopeVariableAdder, validExits, contextStatementFactories, newEndKeywords) && menuOpt != null)
                    {
                        if (menuOpt.StartIndex < 0)
                        {
                            continue;
                        }
                        node.Children.Add(menuOpt.StartIndex, menuOpt);
                    }
                    else if (parser.PeekToken(TokenKind.EndKeyword) && endKeywords != null && endKeywords.Contains(parser.PeekToken(2).Kind))
                    {
                        break;
                    }
                    else
                    {
                        parser.NextToken();
                    }
                }
                prepStatementBinders.RemoveAt(0);

                if (!(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.MenuKeyword, 2)))
                {
                    parser.ReportSyntaxError("A menu block must be terminated with \"end menu\".");
                }
                else
                {
                    parser.NextToken(); // advance to the 'end' token
                    parser.NextToken(); // advance to the 'menu' token
                    node.EndIndex = parser.Token.Span.End;
                }
            }

            return(result);
        }
Exemplo n.º 16
0
        public static bool TryParseNode(IParser parser, out ArrayTypeReference defNode)
        {
            defNode = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.DynamicKeyword))
            {
                result            = true;
                defNode           = new ArrayTypeReference();
                defNode.ArrayType = ArrayType.Dynamic;
                parser.NextToken();
                defNode.StartIndex = parser.Token.Span.Start;
                defNode._location  = parser.TokenLocation;

                if (!parser.PeekToken(TokenKind.ArrayKeyword))
                {
                    parser.ReportSyntaxError("Missing \"array\" keyword after \"dynamic\" array keyword.");
                }
                else
                {
                    parser.NextToken();
                }

                AttributeSpecifier attribSpec;
                if (AttributeSpecifier.TryParseNode(parser, out attribSpec))
                {
                    defNode.Attribute = attribSpec;
                }

                // [WITH DIMENSION rank] is optional
                if (parser.PeekToken(TokenKind.WithKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.DimensionKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenCategory.NumericLiteral))
                        {
                            var tok = parser.NextToken() as ConstantValueToken;
                            if (tok != null)
                            {
                                uint   intVal;
                                string val = tok.Value.ToString();
                                if (uint.TryParse(val, out intVal))
                                {
                                    if (intVal >= 1 && intVal <= 3)
                                    {
                                        defNode.DynamicArrayDimension = intVal;
                                    }
                                    else
                                    {
                                        parser.ReportSyntaxError("A dynamic array's dimension can be 1, 2, or 3.");
                                    }
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Invalid array dimension found.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid token found.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid dimension specifier for dynamic array.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("\"dimension\" keyword not specified for dynamic array");
                    }
                }

                if (!parser.PeekToken(TokenKind.OfKeyword))
                {
                    parser.ReportSyntaxError("Missing \"of\" keyword in array definition.");
                }
                else
                {
                    parser.NextToken();
                }

                // now try to get the datatype
                TypeReference typeRef;
                if ((TypeReference.TryParseNode(parser, out typeRef) && typeRef != null))
                {
                    defNode.Children.Add(typeRef.StartIndex, typeRef);
                    defNode.EndIndex = typeRef.EndIndex;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid type specified for dynamic array definition");
                }
            }
            else if (parser.PeekToken(TokenKind.ArrayKeyword))
            {
                result  = true;
                defNode = new ArrayTypeReference();
                parser.NextToken();
                defNode.StartIndex = parser.Token.Span.Start;
                defNode._location  = parser.TokenLocation;

                if (!parser.PeekToken(TokenKind.LeftBracket))
                {
                    parser.ReportSyntaxError("A non-dynamic array definition must have brackets.");
                }
                else
                {
                    parser.NextToken();
                }

                if (parser.PeekToken(TokenKind.RightBracket))
                {
                    // we should have a java array
                    defNode.ArrayType = ArrayType.Java;
                    parser.NextToken();

                    AttributeSpecifier attribSpec;
                    if (AttributeSpecifier.TryParseNode(parser, out attribSpec))
                    {
                        defNode.Attribute = attribSpec;
                    }

                    if (!parser.PeekToken(TokenKind.OfKeyword))
                    {
                        parser.ReportSyntaxError("Missing \"of\" keyword in array definition.");
                    }
                    else
                    {
                        parser.NextToken();
                    }

                    // now try to get the datatype
                    TypeReference typeRef;
                    if ((TypeReference.TryParseNode(parser, out typeRef) && typeRef != null))
                    {
                        defNode.Children.Add(typeRef.StartIndex, typeRef);
                        defNode.EndIndex = typeRef.EndIndex;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid type specified for java array definition");
                    }
                }
                else
                {
                    defNode.ArrayType = ArrayType.Static;
                    List <TokenKind> breakToks = new List <TokenKind> {
                        TokenKind.Comma, TokenKind.RightBracket
                    };
                    // get the first-dimension size
                    ExpressionNode dimensionExpr;
                    if (!FglExpressionNode.TryGetExpressionNode(parser, out dimensionExpr, breakToks))
                    {
                        parser.ReportSyntaxError("Array's first dimension size is invalid");
                    }
                    else
                    {
                        defNode.StaticDimOneSize = dimensionExpr;
                    }

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

                        if (!FglExpressionNode.TryGetExpressionNode(parser, out dimensionExpr, breakToks))
                        {
                            parser.ReportSyntaxError("Array's second dimension size is invalid");
                        }
                        else
                        {
                            defNode.StaticDimTwoSize = dimensionExpr;
                        }

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

                            if (!FglExpressionNode.TryGetExpressionNode(parser, out dimensionExpr, breakToks))
                            {
                                parser.ReportSyntaxError("Array's third dimension size is invalid");
                            }
                            else
                            {
                                defNode.StaticDimThreeSize = dimensionExpr;
                            }
                        }
                    }

                    if (!parser.PeekToken(TokenKind.RightBracket))
                    {
                        parser.ReportSyntaxError("Invalid end of static array dimension specifier.");
                    }
                    else
                    {
                        parser.NextToken();
                    }

                    AttributeSpecifier attribSpec;
                    if (AttributeSpecifier.TryParseNode(parser, out attribSpec))
                    {
                        defNode.Attribute = attribSpec;
                    }

                    if (!parser.PeekToken(TokenKind.OfKeyword))
                    {
                        parser.ReportSyntaxError("Missing \"of\" keyword in array definition.");
                    }
                    else
                    {
                        parser.NextToken();
                    }

                    // now try to get the datatype
                    TypeReference typeRef;
                    if ((TypeReference.TryParseNode(parser, out typeRef) && typeRef != null))
                    {
                        defNode.Children.Add(typeRef.StartIndex, typeRef);
                        defNode.EndIndex   = typeRef.EndIndex;
                        defNode.IsComplete = true;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid type specified for static array definition");
                    }
                }
            }
            return(result);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        public static bool TryParseNode(Genero4glParser parser, out DeclareStatement defNode, IModuleResult containingModule)
        {
            defNode = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.DeclareKeyword))
            {
                result  = true;
                defNode = new DeclareStatement();
                parser.NextToken();
                defNode.StartIndex             = parser.Token.Span.Start;
                defNode._prepStatementResolver = containingModule.PreparedCursorResolver;

                if (parser.PeekToken(TokenCategory.Identifier) || parser.PeekToken(TokenCategory.Keyword))
                {
                    parser.NextToken();
                    defNode.Identifier = parser.Token.Token.Value.ToString();

                    if (parser.PeekToken(TokenKind.ScrollKeyword))
                    {
                        parser.NextToken();
                        defNode.Scroll = true;
                    }

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

                        if (parser.PeekToken(TokenKind.WithKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.HoldKeyword))
                            {
                                parser.NextToken();
                                defNode.WithHold = true;
                            }
                            else
                            {
                                parser.ReportSyntaxError("SQL declare statement missing \"hold\" keyword.");
                            }
                        }

                        if (parser.PeekToken(TokenKind.FromKeyword))
                        {
                            parser.NextToken();
                            // We have a string expression declare
                            ExpressionNode exprNode;
                            if (FglExpressionNode.TryGetExpressionNode(parser, out exprNode) /* && exprNode is StringExpressionNode*/ && exprNode != null)
                            {
                                defNode.Children.Add(exprNode.StartIndex, exprNode);
                                defNode.EndIndex = exprNode.EndIndex;

                                containingModule.BindCursorResult(defNode, parser);
                            }
                            else
                            {
                                parser.ReportSyntaxError("String expression not found for SQl declare statement");
                            }
                        }
                        else if (parser.PeekToken(TokenKind.ForKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.SqlKeyword))
                            {
                                // we have a sql block declare
                                SqlBlockNode sqlBlock;
                                if (SqlBlockNode.TryParseSqlNode(parser, out sqlBlock) && sqlBlock != null)
                                {
                                    defNode.Children.Add(sqlBlock.StartIndex, sqlBlock);
                                    defNode.EndIndex   = sqlBlock.EndIndex;
                                    defNode.IsComplete = true;
                                    containingModule.BindCursorResult(defNode, parser);
                                }
                            }
                            else if (parser.PeekToken(TokenKind.SelectKeyword))
                            {
                                // we have a static sql select statement
                                FglStatement sqlStmt;
                                bool         dummy;
                                if (SqlStatementFactory.TryParseSqlStatement(parser, out sqlStmt, out dummy, TokenKind.SelectKeyword) && sqlStmt != null)
                                {
                                    defNode.Children.Add(sqlStmt.StartIndex, sqlStmt);
                                    defNode.EndIndex   = sqlStmt.EndIndex;
                                    defNode.IsComplete = true;
                                    containingModule.BindCursorResult(defNode, parser);
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Static SQL declare statement must specify a SELECT statement.");
                                }
                            }
                            else if (parser.PeekToken(TokenCategory.Identifier) || parser.PeekToken(TokenCategory.Keyword))
                            {
                                // we have a prepared statment
                                parser.NextToken();
                                defNode.PreparedStatementId = parser.Token.Token.Value.ToString();
                                defNode.EndIndex            = parser.Token.Span.End;
                                defNode.IsComplete          = true;
                                containingModule.BindCursorResult(defNode, parser);
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid token found in SQL declare statment.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("SQL declare statement must have either \"for\" or \"from\" keyword.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("SQL declare statement missing \"cursor\" keyword.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("SQL declare statement must specify an identifier to declare.");
                }
            }

            return(result);
        }
Exemplo n.º 19
0
        public static bool TryParseNode(IParser parser, out PrintStatement node, ReportBlockNode reportNode)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.PrintKeyword))
            {
                result = true;
                node   = new PrintStatement();
                parser.NextToken();
                node.StartIndex        = parser.Token.Span.Start;
                node.WhereExpressions  = new List <ExpressionNode>();
                node.ColumnExpressions = new List <ExpressionNode>();
                node.VariableNames     = new List <ExpressionNode>();
                node.Filenames         = new List <ExpressionNode>();
                node.OtherExpressions  = new List <ExpressionNode>();

                TokenKind nextTokKind = parser.PeekToken().Kind;

                if (ReportStatementFactory.StatementStartKeywords.Contains(nextTokKind) ||
                    Genero4glAst.ValidStatementKeywords.Contains(nextTokKind) ||
                    parser.PeekToken(TokenKind.OnKeyword) ||
                    parser.PeekToken(TokenKind.EveryKeyword) ||
                    (parser.PeekToken(TokenKind.FirstKeyword) && parser.PeekToken(TokenKind.PageKeyword, 2)) ||
                    parser.PeekToken(TokenKind.PageKeyword) ||
                    parser.PeekToken(TokenKind.BeforeKeyword) ||
                    parser.PeekToken(TokenKind.AfterKeyword))
                {
                    node.EndIndex = parser.Token.Span.End;
                    return(true);
                }


                List <TokenKind> breaks = new List <TokenKind> {
                    TokenKind.Comma
                };
                while (true)
                {
                    if (parser.PeekToken(TokenKind.GroupKeyword))
                    {
                        parser.NextToken();
                    }

                    switch (parser.PeekToken().Kind)
                    {
                    case TokenKind.PagenoKeyword:
                    case TokenKind.LinenoKeyword:
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.UsingKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenCategory.StringLiteral))
                            {
                                parser.NextToken();
                            }
                            if (parser.PeekToken(TokenKind.ClippedKeyword))
                            {
                                parser.NextToken();
                            }
                        }
                        break;

                    case TokenKind.ColumnKeyword:
                    {
                        parser.NextToken();
                        ExpressionNode colExpr;
                        if (FglExpressionNode.TryGetExpressionNode(parser, out colExpr, breaks))
                        {
                            node.ColumnExpressions.Add(colExpr);
                        }
                        break;
                    }

                    case TokenKind.CountKeyword:
                    case TokenKind.PercentKeyword:
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.LeftParenthesis))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.Multiply))
                            {
                                parser.NextToken();
                                if (parser.PeekToken(TokenKind.RightParenthesis))
                                {
                                    parser.NextToken();
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Expected right-paren in print statement.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expected '*' in print statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected left-paren in print statement.");
                        }

                        if (parser.PeekToken(TokenKind.WhereKeyword))
                        {
                            parser.NextToken();
                            ExpressionNode whereClause;
                            if (FglExpressionNode.TryGetExpressionNode(parser, out whereClause, breaks))
                            {
                                node.WhereExpressions.Add(whereClause);
                            }
                        }

                        if (parser.PeekToken(TokenKind.UsingKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenCategory.StringLiteral))
                            {
                                parser.NextToken();
                            }
                            if (parser.PeekToken(TokenKind.ClippedKeyword))
                            {
                                parser.NextToken();
                            }
                        }
                        break;
                    }

                    case TokenKind.SumKeyword:
                    case TokenKind.MinKeyword:
                    case TokenKind.MaxKeyword:
                    case TokenKind.AvgKeyword:
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.LeftParenthesis))
                        {
                            parser.NextToken();
                            ExpressionNode varName;
                            if (FglExpressionNode.TryGetExpressionNode(parser, out varName))
                            {
                                node.VariableNames.Add(varName);
                                if (parser.PeekToken(TokenKind.RightParenthesis))
                                {
                                    parser.NextToken();
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Expected right-paren in print statement.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid variable name found in print statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expected left-paren in print statement.");
                        }

                        if (parser.PeekToken(TokenKind.WhereKeyword))
                        {
                            parser.NextToken();
                            ExpressionNode whereClause;
                            if (FglExpressionNode.TryGetExpressionNode(parser, out whereClause, breaks))
                            {
                                node.WhereExpressions.Add(whereClause);
                            }
                        }

                        if (parser.PeekToken(TokenKind.UsingKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenCategory.StringLiteral))
                            {
                                parser.NextToken();
                            }
                            if (parser.PeekToken(TokenKind.ClippedKeyword))
                            {
                                parser.NextToken();
                            }
                        }
                        break;
                    }

                    case TokenKind.FileKeyword:
                    {
                        parser.NextToken();
                        ExpressionNode filename;
                        if (FglExpressionNode.TryGetExpressionNode(parser, out filename, breaks))
                        {
                            node.Filenames.Add(filename);
                        }
                        break;
                    }

                    default:
                    {
                        ExpressionNode expr;
                        if (FglExpressionNode.TryGetExpressionNode(parser, out expr, breaks, new ExpressionParsingOptions
                            {
                                AllowStarParam = true,
                                AdditionalExpressionParsers = new ExpressionParser[] { (x) => ReportStatementFactory.ParseAggregateReportFunction(x, reportNode) }
                            }))
                        {
                            node.OtherExpressions.Add(expr);
                            if (parser.PeekToken(TokenKind.SpacesKeyword))
                            {
                                parser.NextToken();
                            }
                            else if (parser.PeekToken(TokenKind.WordwrapKeyword))
                            {
                                parser.NextToken();
                                if (parser.PeekToken(TokenKind.RightKeyword) && parser.PeekToken(TokenKind.MarginKeyword, 2))
                                {
                                    parser.NextToken();
                                    parser.NextToken();
                                    if (FglExpressionNode.TryGetExpressionNode(parser, out expr, breaks))
                                    {
                                        node.OtherExpressions.Add(expr);
                                    }
                                    else
                                    {
                                        parser.ReportSyntaxError("Invalid expression found in print statement.");
                                    }
                                }
                            }
                        }
                        break;
                    }
                    }

                    var tokKind = parser.PeekToken().Kind;
                    if (tokKind == TokenKind.Comma)
                    {
                        parser.NextToken();
                    }
                    else if (tokKind == TokenKind.Semicolon)
                    {
                        parser.NextToken();
                        break;
                    }
                    else if (tokKind >= TokenKind.FirstOperator &&
                             tokKind <= TokenKind.LastOperator)
                    {
                        parser.NextToken();
                    }
                    else
                    {
                        break;
                    }
                }

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

            return(result);
        }
Exemplo n.º 20
0
        public static bool VerifyValidConstraint(IParser parser, out string typeConstraintString, TokenKind specifiedToken = TokenKind.EndOfFile, bool suppressErrors = false, TokenKind alreadyEatenToken = TokenKind.EndOfFile)
        {
            typeConstraintString = null;
            StringBuilder sb           = new StringBuilder();
            TokenKind     tokenToCheck = specifiedToken;

            if (tokenToCheck == TokenKind.EndOfFile)
            {
                if (ConstrainedTypes.Contains(parser.Token.Token.Kind))
                {
                    sb.Append(Tokens.TokenKinds[parser.Token.Token.Kind]);
                    tokenToCheck = parser.Token.Token.Kind;
                }
                else
                {
                    return(false);
                }
            }

            switch (tokenToCheck)
            {
            case TokenKind.CharKeyword:
            case TokenKind.CharacterKeyword:
            case TokenKind.VarcharKeyword:
            {
                if (parser.PeekToken(TokenKind.LeftParenthesis))
                {
                    parser.NextToken();
                    sb.Append("(");
                    ExpressionNode expr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out expr))
                    {
                        sb.Append(expr.ToString());
                        if (tokenToCheck == TokenKind.VarcharKeyword &&
                            parser.PeekToken(TokenKind.Comma))
                        {
                            parser.NextToken();
                            sb.Append(", ");
                            if (FglExpressionNode.TryGetExpressionNode(parser, out expr))
                            {
                                sb.Append(expr.ToString());
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid expression found in varchar definition.");
                            }
                        }
                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                            sb.Append(")");
                            typeConstraintString = sb.ToString();
                            return(true);
                        }
                    }
                    parser.ReportSyntaxError("Incomplete character-type size specification found.");
                    return(false);
                }
                break;
            }

            case TokenKind.DecKeyword:
            case TokenKind.DecimalKeyword:
            case TokenKind.MoneyKeyword:
            case TokenKind.NumericKeyword:
            {
                if (parser.PeekToken(TokenKind.LeftParenthesis))
                {
                    parser.NextToken();
                    sb.Append("(");
                    if (parser.PeekToken(TokenCategory.NumericLiteral))
                    {
                        parser.NextToken();
                        sb.Append(parser.Token.Token.Value.ToString());

                        if (parser.PeekToken(TokenKind.Comma))
                        {
                            parser.NextToken();
                            sb.Append(", ");
                            if (parser.PeekToken(TokenCategory.NumericLiteral))
                            {
                                parser.NextToken();
                                sb.Append(parser.Token.Token.Value.ToString());
                            }
                            else
                            {
                                parser.ReportSyntaxError("Incomplete decimal/money-type scale specification found.");
                                return(false);
                            }
                        }

                        if (parser.PeekToken(TokenKind.RightParenthesis))
                        {
                            parser.NextToken();
                            sb.Append(")");
                            typeConstraintString = sb.ToString();
                            return(true);
                        }
                    }
                    parser.ReportSyntaxError("Incomplete decimal/money-type precision specification found.");
                    return(false);
                }
                break;
            }

            case TokenKind.CurrentKeyword:
            case TokenKind.DatetimeKeyword:
            {
                TokenKind tokenToLookAt = alreadyEatenToken;
                if (tokenToLookAt == TokenKind.EndOfFile)
                {
                    tokenToLookAt = parser.PeekToken().Kind;
                }
                if (_dtQuals.Contains(tokenToLookAt))
                {
                    if (alreadyEatenToken == TokenKind.EndOfFile)
                    {
                        parser.NextToken();
                    }
                    sb.AppendFormat(" {0}", parser.Token.Token.Value.ToString());

                    if (parser.PeekToken(TokenKind.ToKeyword))
                    {
                        parser.NextToken();
                        sb.AppendFormat(" {0}", parser.Token.Token.Value.ToString());

                        if (_dtQuals.Contains(parser.PeekToken().Kind))
                        {
                            parser.NextToken();
                            sb.AppendFormat(" {0}", parser.Token.Token.Value.ToString());

                            if (parser.Token.Token.Kind == TokenKind.FractionKeyword && parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                sb.Append("(");

                                if (parser.PeekToken(TokenCategory.NumericLiteral))
                                {
                                    parser.NextToken();
                                    sb.Append(parser.Token.Token.Value.ToString());

                                    if (parser.PeekToken(TokenKind.RightParenthesis))
                                    {
                                        parser.NextToken();
                                        sb.Append(")");
                                        typeConstraintString = sb.ToString();
                                        return(true);
                                    }
                                }
                                if (!suppressErrors)
                                {
                                    parser.ReportSyntaxError("Invalid datetime fraction specification found.");
                                }
                                return(false);
                            }

                            typeConstraintString = sb.ToString();
                            return(true);
                        }
                    }
                }
                if (!suppressErrors)
                {
                    parser.ReportSyntaxError("Invalid datetime specification found.");
                }
                return(false);
            }

            case TokenKind.IntervalKeyword:
            {
                if (_dtQuals.Contains(parser.PeekToken().Kind))
                {
                    parser.NextToken();
                    sb.AppendFormat(" {0}", parser.Token.Token.Value.ToString());

                    if (parser.Token.Token.Kind == TokenKind.FractionKeyword && parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.ReportSyntaxError("A scale cannot be defined on the first span of the interval.");
                        return(false);
                    }

                    if (parser.PeekToken(TokenKind.LeftParenthesis))
                    {
                        parser.NextToken();
                        sb.Append("(");
                        if (parser.PeekToken(TokenCategory.NumericLiteral))
                        {
                            parser.NextToken();
                            sb.Append(parser.Token.Token.Value.ToString());
                            if (parser.PeekToken(TokenKind.RightParenthesis))
                            {
                                parser.NextToken();
                                sb.Append(")");
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid interval specification found.");
                                return(false);
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid interval specification found.");
                            return(false);
                        }
                    }

                    if (parser.PeekToken(TokenKind.ToKeyword))
                    {
                        parser.NextToken();
                        sb.Append(" to");

                        if (_dtQuals.Contains(parser.PeekToken().Kind))
                        {
                            parser.NextToken();
                            sb.AppendFormat(" {0}", parser.Token.Token.Value.ToString());

                            if (parser.Token.Token.Kind == TokenKind.FractionKeyword && parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                sb.Append("(");
                                if (parser.PeekToken(TokenCategory.NumericLiteral))
                                {
                                    parser.NextToken();
                                    sb.Append(parser.Token.Token.Value.ToString());
                                    if (parser.PeekToken(TokenKind.RightParenthesis))
                                    {
                                        parser.NextToken();
                                        sb.Append(")");
                                        typeConstraintString = sb.ToString();
                                        return(true);
                                    }
                                }
                                parser.ReportSyntaxError("Invalid fraction scale specification found.");
                                return(false);
                            }

                            typeConstraintString = sb.ToString();
                            return(true);
                        }
                    }
                }
                parser.ReportSyntaxError("Invalid interval specification found.");
                return(false);
            }
            }

            return(false);
        }
Exemplo n.º 21
0
        public static bool TryParseNode(Genero4glParser parser, out ExecuteStatement node)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.ExecuteKeyword))
            {
                result = true;
                node   = new ExecuteStatement();
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;
                node.InputVars  = new List <ExpressionNode>();
                node.OutputVars = new List <FglNameExpression>();

                if (parser.PeekToken(TokenKind.ImmediateKeyword))
                {
                    parser.NextToken();
                    ExpressionNode immExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out immExpr, Genero4glAst.ValidStatementKeywords.ToList()))
                    {
                        node.ImmediateExpression = immExpr;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid expression found in execute immediate statement.");
                    }
                }
                else
                {
                    FglNameExpression cid;
                    if (FglNameExpression.TryParseNode(parser, out cid))
                    {
                        node.PreparedStatementId = cid;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid prepared statement id found in execute statement.");
                    }

                    HashSet <TokenKind> inVarMods = new HashSet <TokenKind> {
                        TokenKind.InKeyword, TokenKind.OutKeyword, TokenKind.InOutKeyword
                    };
                    bool hitUsing = false;
                    if (parser.PeekToken(TokenKind.UsingKeyword))
                    {
                        hitUsing = true;
                        parser.NextToken();
                        ExpressionNode inVar;
                        while (FglExpressionNode.TryGetExpressionNode(parser, out inVar))
                        {
                            node.InputVars.Add(inVar);
                            if (inVarMods.Contains(parser.PeekToken().Kind))
                            {
                                parser.NextToken();
                            }
                            if (parser.PeekToken(TokenKind.Comma))
                            {
                                parser.NextToken();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (parser.PeekToken(TokenKind.IntoKeyword))
                    {
                        parser.NextToken();
                        FglNameExpression outVar;
                        while (FglNameExpression.TryParseNode(parser, out outVar, TokenKind.Comma))
                        {
                            node.InputVars.Add(outVar);
                            if (parser.PeekToken(TokenKind.Comma))
                            {
                                parser.NextToken();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (!hitUsing && parser.PeekToken(TokenKind.UsingKeyword))
                    {
                        parser.NextToken();
                        ExpressionNode inVar;
                        while (FglExpressionNode.TryGetExpressionNode(parser, out inVar))
                        {
                            node.InputVars.Add(inVar);
                            if (inVarMods.Contains(parser.PeekToken().Kind))
                            {
                                parser.NextToken();
                            }
                            if (parser.PeekToken(TokenKind.Comma))
                            {
                                parser.NextToken();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                node.EndIndex = parser.Token.Span.End;
            }

            return(result);
        }
Exemplo n.º 22
0
        public static bool TryParseNode(Genero4glParser parser, out DisplayBlock node,
                                        IModuleResult containingModule,
                                        List <Func <PrepareStatement, bool> > prepStatementBinders,
                                        Func <ReturnStatement, ParserResult> returnStatementBinder   = null,
                                        Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null,
                                        List <TokenKind> validExitKeywords = null,
                                        IEnumerable <ContextStatementFactory> contextStatementFactories = null,
                                        HashSet <TokenKind> endKeywords = null)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.DisplayKeyword))
            {
                result = true;
                node   = new DisplayBlock();
                parser.NextToken();
                node.StartIndex   = parser.Token.Span.Start;
                node.Attributes   = new List <DisplayAttribute>();
                node.ByNameFields = new List <FglNameExpression>();
                node.FieldSpecs   = new List <FglNameExpression>();
                node.DecoratorEnd = parser.Token.Span.End;

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

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

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

                        // get the optional attributes
                        if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                DisplayAttribute attrib;
                                while (DisplayAttribute.TryParseNode(parser, out attrib, node.IsArray))
                                {
                                    node.Attributes.Add(attrib);
                                    if (!parser.PeekToken(TokenKind.Comma))
                                    {
                                        break;
                                    }
                                    parser.NextToken();
                                }

                                if (parser.PeekToken(TokenKind.RightParenthesis))
                                {
                                    parser.NextToken();
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Expecting right-paren in display attributes section.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expecting left-paren in display attributes section.");
                            }
                        }
                        node.EndIndex = parser.Token.Span.End;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"name\" keyword in display statement.");
                    }
                }
                else if (parser.PeekToken(TokenKind.ArrayKeyword))
                {
                    parser.NextToken();
                    node.IsArray = true;

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

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

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

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

                            // get the help number
                            ExpressionNode optionNumber;
                            if (FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                            {
                                node.HelpNumber = optionNumber;
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid help-number found in input statement.");
                            }
                        }

                        // get the optional attributes
                        if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                DisplayAttribute attrib;
                                while (DisplayAttribute.TryParseNode(parser, out attrib, node.IsArray))
                                {
                                    node.Attributes.Add(attrib);
                                    if (!parser.PeekToken(TokenKind.Comma))
                                    {
                                        break;
                                    }
                                    parser.NextToken();
                                }

                                if (parser.PeekToken(TokenKind.RightParenthesis))
                                {
                                    parser.NextToken();
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Expecting right-paren in display attributes section.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expecting left-paren in display attributes section.");
                            }
                        }

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

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

                        bool hasControlBlocks = false;
                        DisplayControlBlock icb;
                        prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier);
                        while (DisplayControlBlock.TryParseNode(parser, out icb, containingModule, hasControlBlocks, node.IsArray, prepStatementBinders,
                                                                returnStatementBinder, limitedScopeVariableAdder, validExits, contextStatementFactories, newEndKeywords) && icb != null)
                        {
                            // check for include file sign
                            if (icb.StartIndex < 0)
                            {
                                continue;
                            }

                            node.Children.Add(icb.StartIndex, icb);
                            hasControlBlocks = true;
                            if (parser.PeekToken(TokenKind.EndOfFile) ||
                                (parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.DisplayKeyword, 2)))
                            {
                                break;
                            }
                        }
                        prepStatementBinders.RemoveAt(0);

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

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

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

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

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

                        // get the optional attributes
                        if (parser.PeekToken(TokenKind.AttributesKeyword) || parser.PeekToken(TokenKind.AttributeKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LeftParenthesis))
                            {
                                parser.NextToken();
                                DisplayAttribute attrib;
                                while (DisplayAttribute.TryParseNode(parser, out attrib, node.IsArray))
                                {
                                    node.Attributes.Add(attrib);
                                    if (!parser.PeekToken(TokenKind.Comma))
                                    {
                                        break;
                                    }
                                    parser.NextToken();
                                }

                                if (parser.PeekToken(TokenKind.RightParenthesis))
                                {
                                    parser.NextToken();
                                }
                                else
                                {
                                    parser.ReportSyntaxError("Expecting right-paren in input attributes section.");
                                }
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expecting left-paren in display attributes section.");
                            }
                        }
                    }

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

            return(result);
        }
Exemplo n.º 23
0
        public static bool TryParseNode(Genero4glParser parser, out ConstructAttribute node)
        {
            node            = new ConstructAttribute();
            node.StartIndex = parser.Token.Span.Start;
            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.BlackKeyword:
            case TokenKind.BlueKeyword:
            case TokenKind.CyanKeyword:
            case TokenKind.GreenKeyword:
            case TokenKind.MagentaKeyword:
            case TokenKind.RedKeyword:
            case TokenKind.WhiteKeyword:
            case TokenKind.YellowKeyword:
            case TokenKind.BoldKeyword:
            case TokenKind.DimKeyword:
            case TokenKind.InvisibleKeyword:
            case TokenKind.NormalKeyword:
            case TokenKind.ReverseKeyword:
            case TokenKind.BlinkKeyword:
            case TokenKind.UnderlineKeyword:
                parser.NextToken();
                break;

            case TokenKind.AcceptKeyword:
            case TokenKind.CancelKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    ExpressionNode boolExpr;
                    if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                            TokenKind.Comma, TokenKind.RightParenthesis
                        }))
                    {
                        parser.ReportSyntaxError("Invalid boolean expression found in construct attribute.");
                    }
                }
                break;
            }

            case TokenKind.HelpKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in construct attribute.");
                }

                // get the help number
                ExpressionNode optionNumber;
                if (!FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                {
                    parser.ReportSyntaxError("Invalid help-number found in construct attribute.");
                }
                break;
            }

            case TokenKind.NameKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in construct attribute.");
                }

                // get the help number
                ExpressionNode optionNumber;
                if (!FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                {
                    parser.ReportSyntaxError("Invalid dialog name found in construct attribute.");
                }
                break;
            }

            case TokenKind.FieldKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.OrderKeyword))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"order\" keyword in input attribute.");
                }
                if (parser.PeekToken(TokenKind.FormKeyword))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"form\" keyword in input attribute.");
                }
                break;
            }

            default:
                result = false;
                break;
            }

            return(result);
        }
Exemplo n.º 24
0
        public static bool TryParseNode(Genero4glParser parser, out MessageStatement node)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.MessageKeyword))
            {
                result          = true;
                node            = new MessageStatement();
                node.Messages   = new List <ExpressionNode>();
                node.Attributes = new List <MessageAttribute>();
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;

                while (true)
                {
                    ExpressionNode msgExpr;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out msgExpr))
                    {
                        node.Messages.Add(msgExpr);
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid message expression found.");
                    }

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

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

            return(result);
        }
Exemplo n.º 25
0
        public static bool TryParseNode(Genero4glParser parser, out CreatedTableColumn node)
        {
            node               = new CreatedTableColumn();
            node.StartIndex    = parser.Token.Span.Start;
            node.UniqueColumns = new List <FglNameExpression>();
            node.ReferencingTableColumnNames = new List <FglNameExpression>();

            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.UniqueKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.LeftParenthesis))
                {
                    parser.NextToken();
                    FglNameExpression nameExpr;
                    while (FglNameExpression.TryParseNode(parser, out nameExpr))
                    {
                        node.UniqueColumns.Add(nameExpr);
                        if (parser.PeekToken(TokenKind.Comma))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (parser.PeekToken(TokenKind.RightParenthesis))
                    {
                        parser.NextToken();
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected right-paren in create table statement.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected left-paren in create table statement.");
                }
                break;
            }

            case TokenKind.PrimaryKeyword:
            case TokenKind.CheckKeyword:
            case TokenKind.ForeignKeyword:
                result = false;
                parser.ReportSyntaxError("Token not supported at this time for create table statements.");
                break;

            default:
            {
                FglNameExpression colName;
                if (FglNameExpression.TryParseNode(parser, out colName))
                {
                    node.ColumnName = colName;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid name found for table column in create table statement.");
                }

                TypeReference dataType;
                if (TypeReference.TryParseNode(parser, out dataType))
                {
                    // TODO: should probably ensure that only SQL compatible types are used here...
                    node.DataType = dataType;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid data-type found for table column in create table statement.");
                }

                if (parser.PeekToken(TokenKind.DefaultKeyword))
                {
                    parser.NextToken();
                    ExpressionNode defVal;
                    if (FglExpressionNode.TryGetExpressionNode(parser, out defVal))
                    {
                        node.DefaultValue = defVal;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Invalid expression found for default value in create table statement.");
                    }
                }

                if (parser.PeekToken(TokenKind.NotKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.NullKeyword))
                    {
                        parser.NextToken();
                        node.NotNull = true;
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting \"null\" keyword in create table statement.");
                    }
                }

                // TODO: do the other modifiers (primary key, unique, check, references)
            }
            break;
            }

            return(result);
        }
Exemplo n.º 26
0
        internal static bool TryParseNode(Genero4glParser parser, out CreateTableStatement node, IModuleResult containingModule)
        {
            node = null;
            bool result = false;
            bool temp   = false;

            int tempIndex = -1;

            if (parser.PeekToken(TokenKind.TempKeyword))
            {
                tempIndex = parser.Token.Span.Start;
                temp      = true;
                parser.NextToken();
            }

            if (parser.PeekToken(TokenKind.TableKeyword))
            {
                result         = true;
                node           = new CreateTableStatement();
                node.TempTable = temp;
                if (tempIndex >= 0)
                {
                    node.StartIndex = tempIndex;
                }
                else
                {
                    node.StartIndex = parser.Token.Span.Start;
                }
                parser.NextToken();

                if (parser.PeekToken(TokenKind.IfKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.NotKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.ExistsKeyword))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expecting \"exists\" keyword in create table statement.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expecting \"not\" keyword in create table statement.");
                    }
                }

                FglNameExpression nameExpr;
                if (FglNameExpression.TryParseNode(parser, out nameExpr))
                {
                    node.TableName = nameExpr;
                }
                else
                {
                    parser.ReportSyntaxError("Invalid name found for create table statement.");
                }

                if (parser.PeekToken(TokenKind.LeftParenthesis))
                {
                    parser.NextToken();
                    CreatedTableColumn tableCol;
                    while (CreatedTableColumn.TryParseNode(parser, out tableCol) && tableCol != null)
                    {
                        node.Children.Add(tableCol.StartIndex, tableCol);
                        if (parser.PeekToken(TokenKind.Comma))
                        {
                            parser.NextToken();
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (parser.PeekToken(TokenKind.RightParenthesis))
                    {
                        parser.NextToken();
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected right-paren in create table statement.");
                    }

                    if (parser.PeekToken(TokenKind.WithKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.NoKeyword))
                        {
                            parser.NextToken();
                            if (parser.PeekToken(TokenKind.LogKeyword))
                            {
                                parser.NextToken();
                            }
                            else
                            {
                                parser.ReportSyntaxError("Expecting \"log\" keyword in create table statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expecting \"no\" keyword in create table statement.");
                        }
                    }

                    if (parser.PeekToken(TokenKind.InKeyword))
                    {
                        parser.NextToken();
                        if (FglNameExpression.TryParseNode(parser, out nameExpr))
                        {
                            node.TablespaceName = nameExpr;
                        }
                        else
                        {
                            parser.ReportSyntaxError("Invalid name found for create table statement.");
                        }
                    }

                    if (parser.PeekToken(TokenKind.ExtentKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.SizeKeyword))
                        {
                            parser.NextToken();
                            ExpressionNode extSize;
                            if (FglExpressionNode.TryGetExpressionNode(parser, out extSize))
                            {
                                node.ExtentSize = extSize;
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid expression found for extent size in create table statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expecting \"size\" keyword in create table statement.");
                        }
                    }

                    if (parser.PeekToken(TokenKind.NextKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.SizeKeyword))
                        {
                            parser.NextToken();
                            ExpressionNode extSize;
                            if (FglExpressionNode.TryGetExpressionNode(parser, out extSize))
                            {
                                node.NextSize = extSize;
                            }
                            else
                            {
                                parser.ReportSyntaxError("Invalid expression found for next size in create table statement.");
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expecting \"size\" keyword in create table statement.");
                        }
                    }

                    if (parser.PeekToken(TokenKind.LockKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.ModeKeyword))
                        {
                            parser.NextToken();
                            switch (parser.PeekToken().Kind)
                            {
                            case TokenKind.PageKeyword:
                                parser.NextToken();
                                break;

                            case TokenKind.RowKeyword:
                                parser.NextToken();
                                break;

                            default:
                                parser.ReportSyntaxError("Expecting \"page\" or \"row\" keyword in create table statement.");
                                break;
                            }
                        }
                        else
                        {
                            parser.ReportSyntaxError("Expecting \"mode\" keyword in create table statement.");
                        }
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected left-paren in create table statement.");
                }

                containingModule.BindTableResult(node, parser);
            }
            return(result);
        }
Exemplo n.º 27
0
        public static bool TryParseNode(Genero4glParser parser, out DisplayAttribute node, bool isArray)
        {
            node            = new DisplayAttribute();
            node.StartIndex = parser.Token.Span.Start;
            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.BlackKeyword:
            case TokenKind.BlueKeyword:
            case TokenKind.CyanKeyword:
            case TokenKind.GreenKeyword:
            case TokenKind.MagentaKeyword:
            case TokenKind.RedKeyword:
            case TokenKind.WhiteKeyword:
            case TokenKind.YellowKeyword:
            case TokenKind.BoldKeyword:
            case TokenKind.DimKeyword:
            case TokenKind.NormalKeyword:
            case TokenKind.ReverseKeyword:
            case TokenKind.BlinkKeyword:
            case TokenKind.UnderlineKeyword:
            case TokenKind.InvisibleKeyword:
                parser.NextToken();
                break;

            case TokenKind.AcceptKeyword:
            case TokenKind.CancelKeyword:
            case TokenKind.UnbufferedKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    ExpressionNode boolExpr;
                    if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                            TokenKind.Comma, TokenKind.RightParenthesis
                        }))
                    {
                        parser.ReportSyntaxError("Invalid boolean expression found in input attribute.");
                    }
                }
                break;
            }

            case TokenKind.HelpKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in display attribute.");
                }

                // get the help number
                ExpressionNode optionNumber;
                if (!FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                {
                    parser.ReportSyntaxError("Invalid help-number found in display attribute.");
                }
                break;
            }

            case TokenKind.CountKeyword:
            {
                if (isArray)
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        parser.NextToken();
                        ExpressionNode boolExpr;
                        if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                                TokenKind.Comma, TokenKind.RightParenthesis
                            }))
                        {
                            parser.ReportSyntaxError("Invalid expression found in display attribute.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected integer expression in display array attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Attribute can only be used for an display array statement.");
                }
                break;
            }

            case TokenKind.KeepKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.CurrentKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.RowKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.Equals))
                        {
                            parser.NextToken();
                            ExpressionNode boolExpr;
                            if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                                    TokenKind.Comma, TokenKind.RightParenthesis
                                }))
                            {
                                parser.ReportSyntaxError("Invalid boolean expression found in input array attribute.");
                            }
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"row\" keyword in input array attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"current\" keyword in input array attribute.");
                }
                break;
            }

            case TokenKind.DetailActionKeyword:
            case TokenKind.DoubleClickKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    FglNameExpression nameExpression;
                    if (!FglNameExpression.TryParseNode(parser, out nameExpression))
                    {
                        parser.ReportSyntaxError("Invalid action name found in input attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in display attribute.");
                }
                break;
            }

            case TokenKind.AccessoryTypeKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    var tokKind = parser.NextToken().Kind;
                    if (tokKind != TokenKind.DetailActionKeyword ||
                        tokKind != TokenKind.DisclosureIndicatorKeyword ||
                        tokKind != TokenKind.CheckmarkKeyword)
                    {
                        parser.ReportSyntaxError("Invalid token found in ACCESSORYTYPE display attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in display attribute.");
                }
                break;
            }

            default:
                result = false;
                break;
            }

            return(result);
        }
Exemplo n.º 28
0
        public static bool TryParseNode(Genero4glParser parser, out InputAttribute node, bool isArray)
        {
            node            = new InputAttribute();
            node.StartIndex = parser.Token.Span.Start;
            bool result = true;

            switch (parser.PeekToken().Kind)
            {
            case TokenKind.BlackKeyword:
            case TokenKind.BlueKeyword:
            case TokenKind.CyanKeyword:
            case TokenKind.GreenKeyword:
            case TokenKind.MagentaKeyword:
            case TokenKind.RedKeyword:
            case TokenKind.WhiteKeyword:
            case TokenKind.YellowKeyword:
            case TokenKind.BoldKeyword:
            case TokenKind.DimKeyword:
            case TokenKind.InvisibleKeyword:
            case TokenKind.NormalKeyword:
            case TokenKind.ReverseKeyword:
            case TokenKind.BlinkKeyword:
            case TokenKind.UnderlineKeyword:
                parser.NextToken();
                break;

            case TokenKind.AcceptKeyword:
            case TokenKind.CancelKeyword:
            case TokenKind.UnbufferedKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    ExpressionNode boolExpr;
                    if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                            TokenKind.Comma, TokenKind.RightParenthesis
                        }))
                    {
                        parser.ReportSyntaxError("Invalid boolean expression found in input attribute.");
                    }
                }
                break;
            }

            case TokenKind.CountKeyword:
            case TokenKind.MaxCountKeyword:
            {
                if (isArray)
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        parser.NextToken();
                        ExpressionNode boolExpr;
                        if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                                TokenKind.Comma, TokenKind.RightParenthesis
                            }))
                        {
                            parser.ReportSyntaxError("Invalid expression found in input attribute.");
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected integer expression in input array attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Attribute can only be used for an input array statement.");
                }
                break;
            }

            case TokenKind.WithoutKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.DefaultsKeyword))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"defaults\" keyword in input attribute.");
                }
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                    ExpressionNode boolExpr;
                    if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                            TokenKind.Comma, TokenKind.RightParenthesis
                        }))
                    {
                        parser.ReportSyntaxError("Invalid boolean expression found in input attribute.");
                    }
                }
                break;
            }

            case TokenKind.HelpKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.Equals))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected equals token in input attribute.");
                }

                // get the help number
                ExpressionNode optionNumber;
                if (!FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                {
                    parser.ReportSyntaxError("Invalid help-number found in input attribute.");
                }
                break;
            }

            case TokenKind.NameKeyword:
            {
                if (!isArray)
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        parser.NextToken();
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected equals token in input attribute.");
                    }

                    // get the help number
                    ExpressionNode optionNumber;
                    if (!FglExpressionNode.TryGetExpressionNode(parser, out optionNumber))
                    {
                        parser.ReportSyntaxError("Invalid dialog name found in input attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("The name attribute can only be used for an input statement (not an input array statement).");
                }
                break;
            }

            case TokenKind.FieldKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.OrderKeyword))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"order\" keyword in input attribute.");
                }
                if (parser.PeekToken(TokenKind.FormKeyword))
                {
                    parser.NextToken();
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"form\" keyword in input attribute.");
                }
                break;
            }

            case TokenKind.AppendKeyword:
            case TokenKind.DeleteKeyword:
            case TokenKind.InsertKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.RowKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        parser.NextToken();
                        ExpressionNode boolExpr;
                        if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                                TokenKind.Comma, TokenKind.RightParenthesis
                            }))
                        {
                            parser.ReportSyntaxError("Invalid boolean expression found in input array attribute.");
                        }
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"row\" keyword in input array attribute.");
                }
                break;
            }

            case TokenKind.KeepKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.CurrentKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.RowKeyword))
                    {
                        parser.NextToken();
                        if (parser.PeekToken(TokenKind.Equals))
                        {
                            parser.NextToken();
                            ExpressionNode boolExpr;
                            if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                                    TokenKind.Comma, TokenKind.RightParenthesis
                                }))
                            {
                                parser.ReportSyntaxError("Invalid boolean expression found in input array attribute.");
                            }
                        }
                    }
                    else
                    {
                        parser.ReportSyntaxError("Expected \"row\" keyword in input array attribute.");
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"current\" keyword in input array attribute.");
                }
                break;
            }

            case TokenKind.AutoKeyword:
            {
                parser.NextToken();
                if (parser.PeekToken(TokenKind.AppendKeyword))
                {
                    parser.NextToken();
                    if (parser.PeekToken(TokenKind.Equals))
                    {
                        parser.NextToken();
                        ExpressionNode boolExpr;
                        if (!FglExpressionNode.TryGetExpressionNode(parser, out boolExpr, new List <TokenKind> {
                                TokenKind.Comma, TokenKind.RightParenthesis
                            }))
                        {
                            parser.ReportSyntaxError("Invalid boolean expression found in input array attribute.");
                        }
                    }
                }
                else
                {
                    parser.ReportSyntaxError("Expected \"append\" keyword in input array attribute.");
                }
                break;
            }

            default:
                result = false;
                break;
            }

            if (result && node != null)
            {
                node.EndIndex = parser.Token.Span.End;
            }

            return(result);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        public static bool TryParse(IParser parser, out ArrayIndexFglNameExpressionPiece node, TokenKind breakToken = TokenKind.EndOfFile)
        {
            node = null;
            bool result = false;

            if (parser.PeekToken(TokenKind.LeftBracket))
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("[");
                result = true;
                node   = new ArrayIndexFglNameExpressionPiece();
                parser.NextToken();
                node.StartIndex = parser.Token.Span.Start;

                // TODO: need to get an integer expression
                // for right now, we'll just check for a constant or a ident/keyword
                ExpressionNode indexExpr;
                while (FglExpressionNode.TryGetExpressionNode(parser, out indexExpr, new List <TokenKind> {
                    TokenKind.RightBracket, TokenKind.Comma
                }))
                {
                    if (node._expression == null)
                    {
                        node._expression = indexExpr;
                    }
                    else
                    {
                        node._expression.AppendExpression(indexExpr);
                    }

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

                //if(parser.PeekToken(TokenCategory.NumericLiteral) ||
                //   parser.PeekToken(TokenCategory.Keyword) ||
                //   parser.PeekToken(TokenCategory.Identifier))
                //{
                //    parser.NextToken();
                //    sb.Append(parser.Token.Token.Value.ToString());
                //}
                //else
                //{
                //    parser.ReportSyntaxError("The parser is unable to parse a complex expression as an array index. This may not be a syntax error.");
                //}

                //// TODO: check for a nested array index access
                //ArrayIndexFglNameExpressionPiece arrayIndex;
                //if (ArrayIndexFglNameExpressionPiece.TryParse(parser, out arrayIndex, breakToken))
                //{
                //    sb.Append(arrayIndex._expression);
                //}

                //while(!parser.PeekToken(TokenKind.RightBracket))
                //{
                //    if(parser.PeekToken().Kind == breakToken)
                //    {
                //        parser.ReportSyntaxError("Unexpected end of array index expression.");
                //        break;
                //    }
                //    parser.NextToken();
                //    sb.Append(parser.Token.Token.Value.ToString());
                //}

                if (parser.PeekToken(TokenKind.RightBracket))
                {
                    parser.NextToken();
                    node.EndIndex   = parser.Token.Span.End;
                    node.IsComplete = true;
                }
                else
                {
                    parser.ReportSyntaxError("Expected right-bracket in array index.");
                }
            }

            return(result);
        }