예제 #1
0
        public ProtoSpecClassDef GetClassDef(string classModule, string className, bool ignoreCase)
        {
            ProtoSpecModule module = Modules.GetByName(classModule, ignoreCase);

            if (module == null)
            {
                return(null);
            }

            ProtoSpecClassDef classDef = module.Classes.GetByName(className, ignoreCase);

            return(classDef);
        }
예제 #2
0
        public ProtoSpecSubset GetFullSpec(ProtoSpecAction action)
        {
            ProtoSpecSubset resultSpec = new ProtoSpecSubset(action);

            if (ClassBaseName != null)
            {
                ProtoSpecClassDef classBaseDef = null;

                if (ClassBaseModule != null)
                {
                    classBaseDef = ParentModule.ParentDocument.GetClassDef(ClassBaseModule, ClassBaseName, true);
                }
                else
                {
                    classBaseDef = ParentModule.ParentDocument.GetClassDef(ParentModule.Name, ClassBaseName, true);
                }

                if (classBaseDef == null)
                {
                    if (ClassBaseModule != null)
                    {
                        throw new Exception("无法找到类型'" + ParentModule.Name + "." + ClassName + "'的基类'" + ClassBaseModule + "." + ClassBaseName + "'");
                    }
                    else
                    {
                        throw new Exception("无法找到类型'" + ParentModule.Name + "." + ClassName + "'的基类'" + ClassBaseName + "'");
                    }
                }

                ProtoSpecSubset classBaseSpec = classBaseDef.GetFullSpec(action);


                foreach (ProtoSpecColumn column in classBaseSpec.Columns)
                {
                    resultSpec.Columns.Add(column.Colon(action));
                }
            }

            foreach (ProtoSpecColumn column in ClassBody.Columns)
            {
                resultSpec.Columns.Add(column.Colon(action));
            }

            return(resultSpec);
        }
예제 #3
0
        private void ParseModuleBody(ProtoSpecModule module)
        {
            while (true)
            {
                NextToken();

                if (CurrentToken.Type == ProtoSpecTokenType.Class)
                {
                    ProtoSpecClassDef classDef = ParseClass(module);

                    if (classDef == null)
                    {
                        break;
                    }

                    module.Classes.Add(classDef);
                }
                else if (CurrentToken.Type == ProtoSpecTokenType.Identifier)
                {
                    ProtoSpecAction action = ParseAction(module);

                    if (action == null)
                    {
                        break;
                    }

                    module.Actions.Add(action);
                }
                else if (CurrentToken.Type == ProtoSpecTokenType.EndOfFile ||
                         CurrentToken.Type == ProtoSpecTokenType.RightBrace)
                {
                    break;
                }
                else
                {
                    Error("未知的标识符");
                    break;
                }
            }
        }
예제 #4
0
        private static ProtoSpecClassDef GetClassDef(ProtoSpecAction parentAction, string classModule, string className)
        {
            ProtoSpecModule module = parentAction.ParentModule;

            if (classModule != null)
            {
                module = parentAction.ParentModule.ParentDocument.Modules.GetByName(classModule, true);

                if (module == null)
                {
                    throw new Exception("模块'" + parentAction.ParentModule.Name + "'的操作'" + parentAction.Name + "'中引用了不存在的模块'" + classModule + "'");
                }
            }

            ProtoSpecClassDef classDef = null;

            if (classModule == null)
            {
                classDef = parentAction.ParentModule.ParentDocument.GetClassDef(parentAction.ParentModule.Name, className, true);
            }
            else
            {
                classDef = parentAction.ParentModule.ParentDocument.GetClassDef(classModule, className, true);
            }

            if (classDef == null)
            {
                if (classModule != null)
                {
                    throw new Exception("模块'" + parentAction.ParentModule.Name + "'的操作'" + parentAction.Name + "'中引用了不存在的类'" + classModule + "." + className + "'");
                }
                else
                {
                    throw new Exception("模块'" + parentAction.ParentModule.Name + "'的操作'" + parentAction.Name + "'中引用了不存在的类'" + className + "'");
                }
            }

            return(classDef);
        }
예제 #5
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);
        }