示例#1
0
        public static void ParseFile(string strFileName, ProtoResult result)
        {
            Tokenizer tokenizer = new Tokenizer();

            if (tokenizer.Load(strFileName))
            {
                TokenIterator it = tokenizer.Iterator();
                while (true)
                {
                    var enumEntity = ParseEnumEntity(it);
                    if (enumEntity != null)
                    {
                        result.Enums.Add(enumEntity);
                        continue;
                    }

                    var stEntity = ParseStructEntity(it);
                    if (stEntity != null)
                    {
                        result.Structs.Add(stEntity);
                        continue;
                    }
                    break;
                }
            }
        }
示例#2
0
        /*
         * public static List<Token> ParseImport(TokenIterator it)
         * {
         *  List<Token> list = new List<Token>();
         *  while (true)
         *  {
         *      if (!ImportMatch.Match(it))
         *          break;
         *      Token token = null;
         *      if (NormalStringMatch.Match(it, ref token) && SemicolonMatch.Match(it))
         *      {
         *          list.Add(token);
         *          continue;
         *      }
         *      ThrowError(it);
         *  }
         *  return list;
         * }
         */
        public static FileEntity ParseFile(string strFileName)
        {
            Tokenizer tokenizer = new Tokenizer();

            if (tokenizer.Load(strFileName))
            {
                TokenIterator it        = tokenizer.Iterator();
                FileEntity    fileEnity = new FileEntity();
                fileEnity.FileName = strFileName;
                //fileEnity.Imports = ParseImport(it);
                NameSpaceEntity globalNS = new NameSpaceEntity()
                {
                    Name = new Token()
                };
                while (true)
                {
                    var entity = ParseNameSpace(it);
                    if (entity != null)
                    {
                        fileEnity.NameSpaces.Add(entity);
                        continue;
                    }

                    var enumEntity = ParseEnumEntity(it);
                    if (enumEntity != null)
                    {
                        globalNS.Enums.Add(enumEntity);
                        continue;
                    }

                    var stEntity = ParseStructEntity(it);
                    if (stEntity != null)
                    {
                        globalNS.Structs.Add(stEntity);
                        continue;
                    }

                    var messageEntity = ParseMessageEntity(it);
                    if (messageEntity != null)
                    {
                        globalNS.Structs.Add(messageEntity);
                        continue;
                    }

                    var serviceEntity = ParseServiceEntity(it);
                    if (serviceEntity != null)
                    {
                        globalNS.Services.Add(serviceEntity);
                        continue;
                    }

                    break;
                }
                if (globalNS.Enums.Count > 0 || globalNS.Structs.Count > 0)
                {
                    fileEnity.NameSpaces.Add(globalNS);
                }

                return(fileEnity);
            }
            return(null);
        }