void ParseLexSection(LexSection section, ProtectLevel protectionLevel) { section.source = source; string skipSymbols = " \r\n\t"; int dataLen = section.data.Length; int caret = 0; for (caret = 0; caret < dataLen; caret++) { if (skipSymbols.Contains(section.data[caret])) { continue; } Dictionary <string, ParserFunc> keyParsers = globalKeyParsers; if (section.GetType() == typeof(LexClass)) { keyParsers = classBodyKeyParsers; } bool passedKeyWord = false; foreach (var keyWordParser in keyParsers) { string sub = section.data.Substring(caret, Math.Min(keyWordParser.Key.Length, dataLen - caret)); if (sub == keyWordParser.Key) { keyWordParser.Value(section, ref caret, ref protectionLevel); passedKeyWord = true; break; } } if (passedKeyWord) { continue; } int blockbegin = caret; string block = ReadBlock(section.data, ref caret); block = block.Trim(' ', '\r', '\t', '\n'); if (block.Length > 0) { TryParseBlock(section, block, blockbegin, ref caret, ref protectionLevel); } } section.functions.ForEach(x => x.comment = section.FindComment(x.begin, x.end)); section.variables.ForEach(x => x.comment = section.FindComment(x.begin, x.end)); section.unknownBlocks.ForEach(x => x.comment = section.FindComment(x.begin, x.end)); }
void ParseLexSection(LexSection section, ProtectLevel protectionLevel) { section.source = source; string skipSymbols = " \r\n\t"; int dataLen = section.data.Length; int caret = 0; for (caret = 0; caret < dataLen; caret++) { if (skipSymbols.Contains(section.data[caret])) continue; Dictionary<string, ParserFunc> keyParsers = globalKeyParsers; if (section.GetType() == typeof(LexClass)) keyParsers = classBodyKeyParsers; bool passedKeyWord = false; foreach (var keyWordParser in keyParsers) { string sub = section.data.Substring(caret, Math.Min(keyWordParser.Key.Length, dataLen - caret)); if (sub == keyWordParser.Key) { keyWordParser.Value(section, ref caret, ref protectionLevel); passedKeyWord = true; break; } } if (passedKeyWord) continue; int blockbegin = caret; string block = ReadBlock(section.data, ref caret); block = block.Trim(' ', '\r', '\t', '\n'); if (block.Length > 0) TryParseBlock(section, block, blockbegin, ref caret, ref protectionLevel); } section.functions.ForEach(x => x.comment = section.FindComment(x.begin, x.end)); section.variables.ForEach(x => x.comment = section.FindComment(x.begin, x.end)); section.unknownBlocks.ForEach(x => x.comment = section.FindComment(x.begin, x.end)); }
void ParseClassOrStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel, bool isstruct) { int begin = caret; if (isstruct) caret += "struct".Length; else caret += "class".Length; string className = ReadWord(section.data, ref caret, " \n\t\r:;/"); string afterName = ReadWord(section.data, ref caret, ";{/").Trim(' ', ':', '\r', '\n', '\t'); string shortClassName = className; if (section.GetType() == typeof(LexClass)) className = (section as LexClass).name + "::" + className; else className = (section as LexNamespace).name + "::" + className; LexClass newClass = new LexClass() { begin = begin, end = caret, data = section.data.Substring(begin, caret - begin), name = className, shortName = shortClassName, source = source, parentLexSection = section, protectLevel = protectionLevel, haveBody = false, isTemplate = isNextLexTemplate }; if (isNextLexTemplate) newClass.templates = templatesBuffer; isNextLexTemplate = false; if (afterName.Length > 0) { var baseClasses = Split(afterName, ','); foreach (var baseClass in baseClasses) { string trimmedBaseClass = baseClass.Trim(); int spacePos = trimmedBaseClass.IndexOf(' '); if (spacePos < 0) { newClass.baseClasses.Add(new LexClass.BaseClassDef() { type = ProtectLevel.Private, className = trimmedBaseClass }); } else { string sectionTypeName = trimmedBaseClass.Substring(0, spacePos); string baseClassName = trimmedBaseClass.Substring(spacePos + 1); if (baseClassName.StartsWith("virtual")) baseClassName = baseClassName.Substring("virtual".Length + 1); ProtectLevel sectionType = ProtectLevel.Private; if (sectionTypeName == "public") sectionType = ProtectLevel.Public; else if (sectionTypeName == "protected") sectionType = ProtectLevel.Protected; newClass.baseClasses.Add(new LexClass.BaseClassDef() { type = sectionType, className = baseClassName }); } } } if (caret < section.data.Length && section.data[caret] == '/') { string comment = ReadWord(section.data, ref caret, "\n"); ReadWord(section.data, ref caret, ";{/"); newClass.comment = new LexComment() { comment = comment }; } if (caret < section.data.Length && section.data[caret] == '{') { int sectionBegin = caret; newClass.data = ReadBlock(section.data, ref caret).Trim('{', '}', ' ', '\n', '\r', '\t'); newClass.haveBody = true; section.classes.Add(newClass); section.childSections.Add(newClass); ParseLexSection(newClass, isstruct ? ProtectLevel.Public : ProtectLevel.Private); } }
void ParseClassOrStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel, bool isstruct) { int begin = caret; if (isstruct) { caret += "struct".Length; } else { caret += "class".Length; } string className = ReadWord(section.data, ref caret, " \n\t\r:;/"); string afterName = ReadWord(section.data, ref caret, ";{/").Trim(' ', ':', '\r', '\n', '\t'); string shortClassName = className; if (section.GetType() == typeof(LexClass)) { className = (section as LexClass).name + "::" + className; } else { className = (section as LexNamespace).name + "::" + className; } LexClass newClass = new LexClass() { begin = begin, end = caret, data = section.data.Substring(begin, caret - begin), name = className, shortName = shortClassName, source = source, parentLexSection = section, protectLevel = protectionLevel, haveBody = false, isTemplate = isNextLexTemplate }; if (isNextLexTemplate) { newClass.templates = templatesBuffer; } isNextLexTemplate = false; if (afterName.Length > 0) { var baseClasses = Split(afterName, ','); foreach (var baseClass in baseClasses) { string trimmedBaseClass = baseClass.Trim(); int spacePos = trimmedBaseClass.IndexOf(' '); if (spacePos < 0) { newClass.baseClasses.Add(new LexClass.BaseClassDef() { type = ProtectLevel.Private, className = trimmedBaseClass }); } else { string sectionTypeName = trimmedBaseClass.Substring(0, spacePos); string baseClassName = trimmedBaseClass.Substring(spacePos + 1); if (baseClassName.StartsWith("virtual")) { baseClassName = baseClassName.Substring("virtual".Length + 1); } ProtectLevel sectionType = ProtectLevel.Private; if (sectionTypeName == "public") { sectionType = ProtectLevel.Public; } else if (sectionTypeName == "protected") { sectionType = ProtectLevel.Protected; } newClass.baseClasses.Add(new LexClass.BaseClassDef() { type = sectionType, className = baseClassName }); } } } if (caret < section.data.Length && section.data[caret] == '/') { string comment = ReadWord(section.data, ref caret, "\n"); ReadWord(section.data, ref caret, ";{/"); newClass.comment = new LexComment() { comment = comment }; } if (caret < section.data.Length && section.data[caret] == '{') { int sectionBegin = caret; newClass.data = ReadBlock(section.data, ref caret).Trim('{', '}', ' ', '\n', '\r', '\t'); newClass.haveBody = true; section.classes.Add(newClass); section.childSections.Add(newClass); ParseLexSection(newClass, isstruct ? ProtectLevel.Public : ProtectLevel.Private); } }