Exemplo n.º 1
0
        public override IEnumerable <Definition> GetChildDefinitions(string name)
        {
            var col = _table.GetColumn(name);

            if (col != null)
            {
                yield return(col.Definition);
            }
        }
Exemplo n.º 2
0
        private void ParseCreateIndex()
        {
            var code = Code;

            DkDict.RelInd relind = null;
            DkDict.Table  table  = null;
            string        word;

            if (code.ReadExactWholeWord("primary"))
            {
                AddToken(new KeywordToken(Scope, code.Span, "primary"));
            }
            if (code.ReadExactWholeWord("nopick"))
            {
                AddToken(new KeywordToken(Scope, code.Span, "nopick"));
            }
            if (code.ReadExactWholeWord("NOPICK"))
            {
                AddToken(new KeywordToken(Scope, code.Span, "NOPICK"));
            }

            if (!string.IsNullOrEmpty(word = code.PeekWordR()))
            {
                if ((relind = DkDict.Dict.GetRelInd(word)) != null)
                {
                    AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, relind.Definition));
                }
                else
                {
                    var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens);
                    if (exp != null)
                    {
                        AddToken(exp);
                    }
                }
            }
            else
            {
                var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens);
                if (exp != null)
                {
                    AddToken(exp);
                }
            }

            if (code.ReadExactWholeWord("on"))
            {
                AddToken(new KeywordToken(Scope, code.Span, "on"));

                if (!string.IsNullOrEmpty(word = code.PeekWordR()) &&
                    (table = DkDict.Dict.GetTable(word)) != null)
                {
                    AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition));
                }
                else
                {
                    var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens);
                    if (exp != null)
                    {
                        AddToken(exp);
                    }
                }
            }

            while (!code.EndOfFile)
            {
                if (code.PeekExact('(') || code.PeekExact('{'))
                {
                    break;
                }

                if (!string.IsNullOrEmpty(word = code.PeekWordR()))
                {
                    if (word == "description")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "description"));
                        var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens);
                        if (exp != null)
                        {
                            AddToken(exp);
                        }
                    }
                    else if (word == "tag")
                    {
                        ParseTag(Scope, this, new KeywordToken(Scope, code.MovePeekedSpan(), "tag"), _createIndexEndTokens);
                    }
                    else
                    {
                        var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens);
                        if (exp != null)
                        {
                            AddToken(exp);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens);
                    if (exp != null)
                    {
                        AddToken(exp);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (code.ReadExact('(') || code.ReadExact('{'))
            {
                var brackets = new BracketsToken(Scope);
                brackets.AddOpen(code.Span);
                AddToken(brackets);

                DkDict.Column field = null;

                while (!code.EndOfFile)
                {
                    if (code.ReadExact(')') || code.ReadExact('}'))
                    {
                        brackets.AddClose(code.Span);
                        break;
                    }

                    if (code.ReadExact(','))
                    {
                        brackets.AddToken(new DelimiterToken(Scope, code.Span));
                    }

                    if (table != null &&
                        !string.IsNullOrEmpty(word = code.PeekWordR()) &&
                        (field = table.GetColumn(word)) != null)
                    {
                        brackets.AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, field.Definition));
                    }
                    else
                    {
                        var exp = ExpressionToken.TryParse(Scope, _createIndexColumnEndTokens);
                        if (exp != null)
                        {
                            brackets.AddToken(exp);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ParseAlterTable()
        {
            var code = Code;

            DkDict.Table    table = null;
            ExpressionToken exp;

            var word = code.PeekWordR();

            if (!string.IsNullOrEmpty(word) && (table = DkDict.Dict.GetTable(word)) != null)
            {
                AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition));
            }
            else
            {
                if ((exp = ExpressionToken.TryParse(Scope, _alterTableEndTokens)) != null)
                {
                    AddToken(exp);
                }
            }

            ParseTableAttributes(_alterTableEndTokens);

            if (code.ReadExact(';'))
            {
                AddToken(new StatementEndToken(Scope, code.Span));
                return;
            }

            if (code.ReadExactWholeWord("before") ||
                code.ReadExactWholeWord("after"))
            {
                AddToken(new KeywordToken(Scope, code.Span, code.Text));
            }

            if (code.ReadExactWholeWord("column"))
            {
                AddToken(new KeywordToken(Scope, code.Span, code.Text));
            }

            if (table != null)
            {
                var field = table.GetColumn(code.PeekWordR());
                if (field != null)
                {
                    AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), code.Text, field.Definition));
                }
                else
                {
                    if ((exp = ExpressionToken.TryParse(Scope, _alterTableEndTokens)) != null)
                    {
                        AddToken(exp);
                    }
                }
            }

            if (code.ReadExactWholeWord("add") ||
                code.ReadExactWholeWord("alter") ||
                code.ReadExactWholeWord("drop") ||
                code.ReadExactWholeWord("move"))
            {
                AddToken(new KeywordToken(Scope, code.Span, code.Text));
            }

            if (code.ReadExactWholeWord("column"))
            {
                AddToken(new KeywordToken(Scope, code.Span, code.Text));
            }

            if (code.ReadExactWholeWord("sametype"))
            {
                AddToken(new KeywordToken(Scope, code.Span, code.Text));
            }
            else
            {
                var dataType = DataType.TryParse(new DataType.ParseArgs
                {
                    Code  = code,
                    Scope = Scope,
                    TokenCreateCallback = token =>
                    {
                        AddToken(token);
                    },
                    VisibleModel = true,
                    AllowTags    = true
                });
            }

            TryParseColumnDefinition(Scope, this, table != null ? table.Definition : null, false);

            if (code.ReadExact(';'))
            {
                AddToken(new StatementEndToken(Scope, code.Span));
            }
        }
Exemplo n.º 4
0
        private void ParseCreateRelationship(KeywordToken relationshipToken)
        {
            AddToken(relationshipToken);

            var code   = Code;
            var word   = code.PeekWordR();
            var relind = DkDict.Dict.GetRelInd(word);

            if (relind != null)
            {
                AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, relind.Definition));

                if (code.ReadNumber())
                {
                    AddToken(new NumberToken(Scope, code.Span, code.Text));
                }
            }
            else
            {
                var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                if (exp != null)
                {
                    AddToken(exp);
                }
            }

            DkDict.Table table = null;

            var done = false;

            while (!code.EndOfFile && !done)
            {
                if (!string.IsNullOrEmpty(word = code.PeekWordR()))
                {
                    if (word == "updates")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word));
                    }
                    else if (word == "prompt" || word == "comment" || word == "image" || word == "description")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word));
                        var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                        if (exp != null)
                        {
                            AddToken(exp);
                        }
                    }
                    else if (word == "one" || word == "many")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word));
                        word = code.PeekWordR();
                        if (!string.IsNullOrEmpty(word))
                        {
                            table = DkDict.Dict.GetTable(word);
                            if (table != null)
                            {
                                AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition));
                            }
                            else
                            {
                                var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                                if (exp != null)
                                {
                                    AddToken(exp);
                                }
                            }
                        }
                        else
                        {
                            var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                            if (exp != null)
                            {
                                AddToken(exp);
                            }
                        }
                    }
                    else if (word == "to")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "to"));
                        if (code.ReadExactWholeWord("one") || code.ReadExactWholeWord("many"))
                        {
                            AddToken(new KeywordToken(Scope, code.Span, code.Text));

                            word = code.PeekWordR();
                            if (!string.IsNullOrEmpty(word))
                            {
                                table = DkDict.Dict.GetTable(word);
                                if (table != null)
                                {
                                    AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition));
                                }
                                else
                                {
                                    var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                                    if (exp != null)
                                    {
                                        AddToken(exp);
                                    }
                                }
                            }
                            else
                            {
                                var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                                if (exp != null)
                                {
                                    AddToken(exp);
                                }
                            }
                        }
                    }
                    else if (word == "order")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "order"));

                        if (code.ReadExactWholeWord("by"))
                        {
                            AddToken(new KeywordToken(Scope, code.Span, "by"));

                            if (code.ReadExactWholeWord("unique"))
                            {
                                AddToken(new KeywordToken(Scope, code.Span, "unique"));
                            }

                            while (!code.EndOfFile)
                            {
                                if (code.PeekExact('(') || code.PeekExact('{'))
                                {
                                    break;
                                }

                                if (table != null && !string.IsNullOrEmpty(word = code.PeekWordR()))
                                {
                                    var field = table.GetColumn(word);
                                    if (field != null)
                                    {
                                        AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, field.Definition));
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else if (word == "tag")
                    {
                        ParseTag(Scope, this, new KeywordToken(Scope, code.MovePeekedSpan(), "tag"), _createRelationshipEndTokens);
                    }
                    else
                    {
                        var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                        if (exp != null)
                        {
                            AddToken(exp);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else if (code.ReadExact('(') || code.ReadExact('{'))
                {
                    var brackets = new BracketsToken(Scope);
                    brackets.AddOpen(code.Span);
                    AddToken(brackets);

                    while (!code.EndOfFile)
                    {
                        if (code.ReadExact(')') || code.ReadExact('}'))
                        {
                            brackets.AddClose(code.Span);
                            done = true;
                            break;
                        }

                        if (!TryParseColumnDefinition(Scope, brackets, relind != null ? relind.Definition : null, true))
                        {
                            var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                            if (exp != null)
                            {
                                AddToken(exp);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens);
                    if (exp != null)
                    {
                        AddToken(exp);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void ParseCreateTimeRelationship()
        {
            var code   = Code;
            var word   = code.PeekWordR();
            var relind = DkDict.Dict.GetRelInd(word);

            if (relind != null)
            {
                AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, relind.Definition));
            }
            else
            {
                return;
            }

            if (code.ReadNumber())
            {
                AddToken(new NumberToken(Scope, code.Span, code.Text));
            }
            else
            {
                return;
            }

            DkDict.Table table = null;

            while (!code.EndOfFile)
            {
                if (code.PeekExact('(') || code.PeekExact('{'))
                {
                    break;
                }

                if (!string.IsNullOrEmpty(word = code.PeekWordR()))
                {
                    if (word == "prompt" || word == "comment" || word == "description")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word));
                        var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens);
                        if (exp != null)
                        {
                            AddToken(exp);
                        }
                    }
                    else if (word == "tag")
                    {
                        ParseTag(Scope, this, new KeywordToken(Scope, code.MovePeekedSpan(), word), _createTimeRelationshipEndTokens);
                    }
                    else if (word == "order")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "order"));
                        if (code.ReadExactWholeWord("by"))
                        {
                            AddToken(new KeywordToken(Scope, code.Span, "by"));

                            while (!code.EndOfFile)
                            {
                                if (code.PeekExact('(') || code.PeekExact('{'))
                                {
                                    break;
                                }

                                if (!string.IsNullOrEmpty(word = code.PeekWordR()))
                                {
                                    var field = table != null?table.GetColumn(word) : null;

                                    if (field != null)
                                    {
                                        AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, field.Definition));
                                    }
                                    else
                                    {
                                        var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens);
                                        if (exp != null)
                                        {
                                            AddToken(exp);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (word == "to")
                    {
                        AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "to"));

                        if ((table = DkDict.Dict.GetTable(word)) != null)
                        {
                            AddToken(new IdentifierToken(Scope, code.Span, word, table.Definition));
                        }
                        else
                        {
                            var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens);
                            if (exp != null)
                            {
                                AddToken(exp);
                            }
                        }
                    }
                    else if ((table = DkDict.Dict.GetTable(word)) != null)
                    {
                        AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition));

                        if (code.ReadExactWholeWord("to"))
                        {
                            AddToken(new KeywordToken(Scope, code.Span, "to"));

                            if ((table = DkDict.Dict.GetTable(word)) != null)
                            {
                                AddToken(new IdentifierToken(Scope, code.Span, word, table.Definition));
                            }
                            else
                            {
                                var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens);
                                if (exp != null)
                                {
                                    AddToken(exp);
                                }
                            }
                        }
                    }
                    else
                    {
                        var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens);
                        if (exp != null)
                        {
                            AddToken(exp);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens);
                    if (exp != null)
                    {
                        AddToken(exp);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (code.PeekExact('('))
            {
                AddToken(BracketsToken.Parse(Scope, expectedDataType: null));
            }
        }