示例#1
0
 public static StructEntity ParseStructEntity(TokenIterator it)
 {
     if (StructMatch.Match(it))
     {
         StructEntity entity = new StructEntity();
         if (VarNameMatch.Match(it, ref entity.Name))
         {
             if (OpeningbraceMatch.Match(it))
             {
                 while (true)
                 {
                     if (CloseingbraceMatch.Match(it))
                     {
                         break;
                     }
                     var filed = ParseStructField(it);
                     if (filed == null)
                     {
                         ThrowError(it);
                     }
                     entity.Fields.Add(filed);
                 }
                 return(entity);
             }
             ThrowError(it);
         }
     }
     return(null);
 }
示例#2
0
        public static bool Check(this StructEntity entity, string nameSpace)
        {
            if (entity.Name == null)
            {
                return(false);
            }
            var token = FindName(nameSpace, entity.Name);

            if (token != null)
            {
                Console.WriteLine(string.Format("{0} => Struct name has exist in {1}", entity.Name, token));
                return(false);
            }
            HashSet <int> vIndex = new HashSet <int>();

            for (int i = 0; i < entity.Fields.Count; ++i)
            {
                var field = entity.Fields[i];
                if (!field.Check(nameSpace))
                {
                    return(false);
                }
                if (vIndex.Contains(field.Index.IntValue))
                {
                    Console.WriteLine(string.Format("{0} => Struct index repeated", field.Index));
                    return(false);
                }
                vIndex.Add(field.Index.IntValue);
                for (int j = i + 1; j < entity.Fields.Count; ++j)
                {
                    if (field.Name.Value == entity.Fields[j].Name.Value)
                    {
                        Console.WriteLine(string.Format("{0} => Struct field name repeated", field.Name));
                        return(false);
                    }
                }
            }
            if (entity.IsMessage)
            {
                string idName   = string.Format("MSG_ID_{0}", entity.Name.Value);
                var    idEntity = FindMsgIdEntity(nameSpace, idName);
                if (idEntity == null)
                {
                    Console.WriteLine(string.Format("{0} => message need a ID enum in same namespace, like : MSG_ID_messageName", entity.Name));
                    return(false);
                }
                var msgEntity = (MessageEnity)entity;
                msgEntity.ID = idEntity;
            }
            return(true);
        }