public static Token HaveName(this FileEntity entity, string nameSpace, string name) { foreach (var ns in entity.NameSpaces) { if (ns.Name.Value == nameSpace) { foreach (var st in ns.Structs) { if (st.Name.Value == name) { return(st.Name); } } foreach (var st in ns.Enums) { if (st.Name.Value == name) { return(st.Name); } } } } return(null); }
/* * 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); }