public static List<CClass> CreateClassesFromFile(this LanguageDefinition inLanguage, string inFileContent) { var tmpClassList = new List<CClass>(); var tmpLines = new LineHelper(inFileContent); var tmpClass = new CClass(); CFunction tmpFunction = null; var tmpState = ClassState.None; Match tmpMatch; while (tmpLines.MoveNext()) { string tmpLine = tmpLines.Current.ToString(); //Usings ausfiltern if (tmpLine.StartsWith("using") && !tmpLine.Contains("(")) { continue; } if (tmpLine == "}") { tmpClassList.Add(tmpClass); tmpClass = new CClass(); tmpState = ClassState.None; } //Class definition laden if ((tmpMatch = inLanguage.Class.Definition.Match(tmpLine)).Success) { tmpClass.Name = tmpMatch.Groups[inLanguage.Class.NameGroup].Value; tmpClass.Modifier = tmpMatch.Groups[inLanguage.Class.ModifierGroup].Value.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries).ToList(); tmpClass.Parents = tmpMatch.Groups[inLanguage.Class.ParameterGroup].Value.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries).ToList(); tmpState = ClassState.Class; continue; } if (tmpState == ClassState.Class) { if ((tmpMatch = inLanguage.Function.Definition.Match(tmpLine)).Success) { tmpFunction = new CFunction { Name = tmpMatch.Groups[inLanguage.Class.NameGroup].Value, }; tmpFunction.Modifier = tmpMatch.Groups[inLanguage.Function.ModifierGroup].Value.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries).ToList(); ; tmpFunction.Parameter = tmpMatch.Groups[inLanguage.Function.ParameterGroup].Value; tmpClass.Functions.Add(tmpFunction); inLanguage.FillFunction(tmpFunction,tmpLines); continue; } } } if (!tmpClassList.Contains(tmpClass)) { tmpClassList.Add(tmpClass); } return tmpClassList; }
public static void FillFunction(this LanguageDefinition inLanguage, CFunction inFunction, LineHelper inLines) { var tmpDeep = 1; while (inLines.MoveNext()) { string tmpLine = inLines.Current.ToString(); if (tmpLine == "}") { tmpDeep--; } if (tmpLine.EndsWith("{")) { tmpDeep++; } inFunction.LinesofCode.Add(tmpLine); if (tmpDeep == 0) { return; } } }