示例#1
0
        public ProtoSpecColumn Colon()
        {
            ProtoSpecColumn result = new ProtoSpecColumn(Name, this.ColumnType);

            result.Format       = this.Format;
            result.Values       = this.Values;
            result.ClassModule  = this.ClassModule;
            result.ClassName    = this.ClassName;
            result.ParentAction = this.ParentAction;

            return(result);
        }
示例#2
0
        public ProtoSpecColumn Colon(ProtoSpecAction parentAction)
        {
            ProtoSpecColumn result = new ProtoSpecColumn(Name, this.ColumnType);

            result.Values       = this.Values;
            result.ClassModule  = this.ClassModule;
            result.ClassName    = this.ClassName;
            result.ParentAction = parentAction;

            ProtoSpecSubset format = null;

            if (ClassName != null)
            {
                ProtoSpecClassDef classDef = GetClassDef(parentAction, ClassModule, ClassName);

                format = classDef.GetFullSpec(parentAction);
            }
            else
            {
                format = this.Format;
            }

            if (format != null)
            {
                ProtoSpecSubset newformat = new ProtoSpecSubset(parentAction);

                foreach (ProtoSpecColumn column in format.Columns)
                {
                    newformat.Columns.Add(column.Colon(parentAction));
                }

                result.Format = newformat;
            }

            return(result);
        }
示例#3
0
        private ProtoSpecSubset ParseSpecSubset(ProtoSpecAction action)
        {
            if (CurrentToken.Type != ProtoSpecTokenType.LeftBrace)
            {
                Error("规格定义起始位置,缺少'{'");
            }

            ProtoSpecSubset subset = new ProtoSpecSubset(action);

            while (true)
            {
                NextToken();

                if (CurrentToken.Type != ProtoSpecTokenType.Identifier)
                {
                    if (CurrentToken.Type != ProtoSpecTokenType.EndOfFile && CurrentToken.Type != ProtoSpecTokenType.RightBrace)
                    {
                        Error("缺少列名");
                    }

                    break;
                }

                string name = CurrentToken.Text;

                NextToken();

                if (CurrentToken.Type != ProtoSpecTokenType.Colon)
                {
                    Error("列名之后缺少':'");
                    break;
                }

                NextToken();

                if (IsColumnType(CurrentToken.Type) == false)
                {
                    Error("缺少类型定义");
                    break;
                }

                ProtoSpecColumnType type = (ProtoSpecColumnType)CurrentToken.Type;

                ProtoSpecColumn column = null;

                if (CurrentToken.Type == ProtoSpecTokenType.List)
                {
                    NextToken();

                    if (CurrentToken.Type == ProtoSpecTokenType.LeftAngular)
                    {
                        NextToken();

                        if (CurrentToken.Type != ProtoSpecTokenType.Identifier)
                        {
                            Error("列表类型缺少类型名");
                            break;
                        }

                        string part1 = CurrentToken.Text;

                        string part2 = null;

                        NextToken();

                        if (CurrentToken.Type == ProtoSpecTokenType.Dot)
                        {
                            NextToken();

                            if (CurrentToken.Type != ProtoSpecTokenType.Identifier)
                            {
                                Error("列表类型的模块名后缺少类型名");
                                break;
                            }

                            part2 = CurrentToken.Text;

                            NextToken();
                        }

                        if (CurrentToken.Type != ProtoSpecTokenType.RightAngular)
                        {
                            Error("列表类型后缺少闭合符号'>'");
                            break;
                        }

                        if (part2 == null)
                        {
                            column = new ProtoSpecColumn(name, type, part1);
                        }
                        else
                        {
                            column = new ProtoSpecColumn(name, type, part1, part2);
                        }
                    }
                    else
                    {
                        ProtoSpecSubset format = ParseSpecSubset(action);

                        column = new ProtoSpecColumn(name, type, format);
                    }
                }
                else if (CurrentToken.Type == ProtoSpecTokenType.TypeOf)
                {
                    NextToken();

                    if (CurrentToken.Type != ProtoSpecTokenType.LeftAngular)
                    {
                        Error("自定义类型前缺少起始符号'<'");
                        break;
                    }

                    NextToken();

                    if (CurrentToken.Type != ProtoSpecTokenType.Identifier)
                    {
                        Error("自定义类型的模块名后缺少类型名");
                        break;
                    }

                    string part1 = CurrentToken.Text;

                    string part2 = null;

                    NextToken();

                    if (CurrentToken.Type == ProtoSpecTokenType.Dot)
                    {
                        NextToken();

                        if (CurrentToken.Type != ProtoSpecTokenType.Identifier)
                        {
                            Error("自定义类型的模块名后缺少类型名");
                            break;
                        }

                        part2 = CurrentToken.Text;

                        NextToken();
                    }

                    if (CurrentToken.Type != ProtoSpecTokenType.RightAngular)
                    {
                        Error("自定义类型后缺少闭合符号'>'");
                        break;
                    }

                    if (part2 == null)
                    {
                        column = new ProtoSpecColumn(name, type, part1);
                    }
                    else
                    {
                        column = new ProtoSpecColumn(name, type, part1, part2);
                    }
                }
                else if (CurrentToken.Type == ProtoSpecTokenType.Enum)
                {
                    ProtoSpecEnumValueList values = ParseEnum();

                    column = new ProtoSpecColumn(name, type, values);
                }
                else
                {
                    column = new ProtoSpecColumn(name, type);
                }

                subset.Columns.Add(column);
            }

            if (CurrentToken.Type != ProtoSpecTokenType.RightBrace)
            {
                Error("规格定义结束位置,缺少'}'");
            }

            return(subset);
        }