Ejemplo n.º 1
0
        public static CastStatement Parse(Scope scope, BracketsToken castToken, IEnumerable <string> endTokens)
        {
            var ret = new CastStatement(scope);

            ret.AddToken(castToken);
            ret._castDataType = castToken.CastDataType;

            var exp = ExpressionToken.TryParse(scope, endTokens, expectedDataType: ret._castDataType);

            if (exp != null)
            {
                ret.AddToken(exp);
            }

            return(ret);
        }
Ejemplo n.º 2
0
        public static ForStatement Parse(Scope scope, KeywordToken forToken)
        {
            var ret = new ForStatement(scope);

            var code = scope.Code;

            ret.AddToken(forToken);
            if (!code.ReadExact('('))
            {
                return(ret);
            }

            var brackets = new BracketsToken(scope);

            brackets.AddOpen(code.Span);
            ret.AddToken(brackets);

            // Initializer
            var exp = ExpressionToken.TryParse(scope, _conditionEndTokens);

            if (exp != null)
            {
                brackets.AddToken(exp);
            }
            if (!code.ReadExact(';'))
            {
                return(ret);
            }

            // Condition
            exp = ExpressionToken.TryParse(scope, _conditionEndTokens);
            if (exp != null)
            {
                brackets.AddToken(exp);
            }
            if (!code.ReadExact(';'))
            {
                return(ret);
            }

            // Increment
            exp = ExpressionToken.TryParse(scope, _conditionEndTokens);
            if (exp != null)
            {
                brackets.AddToken(exp);
            }
            if (!code.ReadExact(')'))
            {
                return(ret);
            }
            brackets.AddClose(code.Span);

            // Body
            var bodyScope = scope.Clone();

            bodyScope.BreakOwner    = ret;
            bodyScope.ContinueOwner = ret;

            if (!code.PeekExact('{'))
            {
                return(ret);
            }
            var body = BracesToken.Parse(bodyScope, null);

            ret.AddToken(body);

            return(ret);
        }
Ejemplo n.º 3
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;
                        }
                    }
                }
            }
        }
Ejemplo 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;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void ParseCreateTable(KeywordToken tableToken)
        {
            AddToken(tableToken);

            var code = Code;

            // Table name
            if (!code.ReadWord())
            {
                return;
            }
            var table = DkDict.Dict.GetTable(code.Text);

            if (table != null)
            {
                AddToken(new IdentifierToken(Scope, code.Span, code.Text, table.Definition));
            }
            else
            {
                AddToken(new UnknownToken(Scope, code.Span, code.Text));
            }

            // Table number
            if (!code.ReadNumber())
            {
                return;
            }
            AddToken(new NumberToken(Scope, code.Span, code.Text));

            // Table number+1
            if (Code.ReadNumber())
            {
                AddToken(new NumberToken(Scope, code.Span, code.Text));
            }

            ExpressionToken exp;

            // Attributes
            ParseTableAttributes(_createTableEndTokens);

            BracketsToken brackets = null;
            BracesToken   braces   = null;
            GroupToken    parent   = null;

            if (code.ReadExact('('))
            {
                brackets = new BracketsToken(Scope);
                brackets.AddOpen(code.Span);
                AddToken(brackets);
                parent = brackets;
            }
            else if (code.ReadExact('{'))
            {
                braces = new BracesToken(Scope);
                braces.AddOpen(code.Span);
                AddToken(braces);
                parent = braces;
            }
            else
            {
                return;
            }

            // Columns
            while (!code.EndOfFile)
            {
                if (code.ReadExact(')') || code.ReadExact('}'))
                {
                    if (brackets != null)
                    {
                        brackets.AddClose(code.Span);
                    }
                    else if (braces != null)
                    {
                        braces.AddClose(code.Span);
                    }
                    return;
                }

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

                if (!TryParseColumnDefinition(Scope, parent, table != null ? table.Definition : null, true))
                {
                    if ((exp = ExpressionToken.TryParse(Scope, _columnEndTokens)) != null)
                    {
                        parent.AddToken(exp);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void ParseCreateWorkspace()
        {
            var code = Code;
            var word = code.PeekWordR();

            if (!string.IsNullOrEmpty(word))
            {
                AddToken(new UnknownToken(Scope, code.MovePeekedSpan(), word));
            }
            else
            {
                return;
            }

            while (true)
            {
                if (code.PeekExact('('))
                {
                    break;
                }

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

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

                while (true)
                {
                    if (code.ReadExact(')'))
                    {
                        brackets.AddClose(code.Span);
                        break;
                    }

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

                    if (code.ReadWord())
                    {
                        brackets.AddToken(new UnknownToken(Scope, code.Span, code.Text));

                        DkDict.Table table = null;
                        do
                        {
                            table = DkDict.Dict.GetTable(code.PeekWordR());
                            if (table != null)
                            {
                                brackets.AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), code.Text, table.Definition));
                                if (code.ReadExact('\\'))
                                {
                                    brackets.AddToken(new OperatorToken(Scope, code.Span, code.Text));
                                }
                            }
                        }while (table != null);

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

                            if (!string.IsNullOrEmpty(word = code.PeekWordR()))
                            {
                                if (word == "prompt" || word == "comment")
                                {
                                    brackets.AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word));
                                    var exp = ExpressionToken.TryParse(Scope, _createWorkspaceColumnEndTokens);
                                    if (exp != null)
                                    {
                                        brackets.AddToken(exp);
                                    }
                                }
                                else if (word == "preload")
                                {
                                    brackets.AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word));
                                }
                                else if (word == "tag")
                                {
                                    ParseTag(Scope, brackets, new KeywordToken(Scope, code.MovePeekedSpan(), "tag"), _createWorkspaceColumnEndTokens);
                                }
                                else
                                {
                                    var exp = ExpressionToken.TryParse(Scope, _createWorkspaceColumnEndTokens);
                                    if (exp != null)
                                    {
                                        brackets.AddToken(exp);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                var exp = ExpressionToken.TryParse(Scope, _createWorkspaceColumnEndTokens);
                                if (exp != null)
                                {
                                    brackets.AddToken(exp);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
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));
            }
        }