Esempio n. 1
0
        public static bool TryParseNode(Genero4glParser parser, out CreateStatement node, IModuleResult containingModule)
        {
            node = null;
            bool result = true;

            if (parser.PeekToken(TokenKind.CreateKeyword))
            {
                parser.NextToken();
                switch (parser.PeekToken().Kind)
                {
                case TokenKind.SequenceKeyword:
                    CreateSequenceStatement sequenceNode;
                    result = CreateSequenceStatement.TryParseNode(parser, out sequenceNode);
                    node   = sequenceNode;
                    break;

                case TokenKind.TableKeyword:
                case TokenKind.TempKeyword:
                    CreateTableStatement tableNode;
                    result = CreateTableStatement.TryParseNode(parser, out tableNode, containingModule);
                    node   = tableNode;
                    break;

                default:
                    result = false;
                    break;
                }
            }

            return(result);
        }
Esempio n. 2
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);
        }