Пример #1
0
        public static AlterColumnInfo ReadColumnInfo(LexemCollection collection)
        {
            var             lex = collection.CurrentLexem();
            var             col = CommonParserFunc.ReadColumnNameOnly(collection);
            AlterColumnInfo cd  = new AlterColumnInfo();

            cd.Name = col;
            lex     = collection.GotoNextMust();
            if (lex.LexemType != LexType.Command)
            {
                collection.ErrorUnexpected(collection.CurrentLexem());
            }
            ExactType?tp = ExactType.Parse(collection);

            if (tp == null)
            {
                collection.Error("Unknow data type", collection.CurrentOrLast());
            }
            cd.Type = tp.Value;
            lex     = collection.GotoNext();
            while (lex != null && lex.LexemType != LexType.Zpt && !lex.IsSkobraClose())
            {
                string s1 = lex.LexemText.ToLower();
                if (ParserUtils.ParseCommandPhrase(collection, "not null"))
                {
                    cd.Nullable = false;
                }
                else if (ParserUtils.ParseCommandPhrase(collection, "null"))
                {
                    cd.Nullable = true;
                }
                else if (ParserUtils.ParseCommandPhrase(collection, "primary key"))
                {
                    cd.PrimaryKey = true;
                }
                else if (lex.LexemType == LexType.Command && (s1 == "auto_increment"))
                {
                    cd.AutoIncrement = true;
                }
                else
                {
                    collection.ErrorUnexpected(collection.CurrentOrLast());
                }
                lex = collection.GotoNext();
            }
            return(cd);
        }
Пример #2
0
        public static void DoParseInside(Expression exp, LexemCollection collection)
        {
            var idx = collection.IndexLexem;
            var le  = collection.GotoNext();

            if (le == null)
            {
                collection.Error("неожиданный конец", collection.GetPrev());
            }
            if (!le.IsSkobraOpen())
            {
                collection.Error("Ожидалась открывающая скобка", collection.GetPrev());
            }
            le = collection.GotoNext();
            while (true)
            {
                if (le.IsSkobraClose())
                {
                    return;
                }
                ExpressionParser tonode = new ExpressionParser(collection);
                tonode.Parse();
                if (collection.CurrentLexem() == null)
                {
                    collection.Error("нет закрывающейся скобки", collection.GetLast());
                }
                if (tonode.Results.Count == 0)
                {
                    collection.Error("нет значений", collection.Get(idx));
                }
                if (tonode.Results.Count > 1)
                {
                    collection.Error("несколько значений", collection.Get(idx));
                }
                exp.AddChild(tonode.Results[0]);
                if (collection.CurrentLexem().LexemType == LexType.Zpt)
                {
                    collection.GotoNext();
                    continue;
                }
                if (collection.CurrentLexem().IsSkobraClose())
                {
                    return;
                }
                collection.Error("Unknow value", collection.CurrentLexem());
            }
        }