public static CondensedSourcepawnDefinition Condense(string[] Paths) { SourcepawnDefinitionCondeser csd = new SourcepawnDefinitionCondeser(); StringBuilder wholeSource = new StringBuilder(); for (int j = 0; j < Paths.Length; ++j) { if (Directory.Exists(Paths[j])) { string[] files = Directory.GetFiles(Paths[j], "*.inc", SearchOption.AllDirectories); for (int i = 0; i < files.Length; ++i) { wholeSource.AppendLine(File.ReadAllText(files[i])); } } } string source = wholeSource.ToString().Trim(); if (source.Length > 5) //lol.. { FunctionsCondenser.Condense(source, ref csd); Regex removeMultilineComments = new Regex(@"/\*.*?\*/", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline); source = removeMultilineComments.Replace(source, string.Empty); EnumCondenser.Condense(source, ref csd); ConstantsCondenser.Condense(source, ref csd); } return(csd.FinalCondense()); }
public static void Condense(string source, ref SourcepawnDefinitionCondeser sdc) { //defines Regex regex = new Regex(@"^[ \f\t\v]*\#define\s+(?<name>[a-zA-Z_][a-zA-Z1-9_]+)" , RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Multiline); MatchCollection mc = regex.Matches(source, 0); for (int i = 0; i < mc.Count; ++i) { sdc._Constants.Add(mc[i].Groups["name"].Value); } //constants and dynamic variables regex = new Regex(@"\b(public|const)(\s+)(([a-zA-Z]+\s+)|([a-zA-Z]+:))?(?<name>[a-zA-Z_][a-zA-Z1-9_]+)(\[[a-zA-Z0-9_]+\])?;" //(\s*=\s*[a-zA-Z0-9_()<>\s]+)? , RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase); mc = regex.Matches(source, 0); for (int i = 0; i < mc.Count; ++i) { sdc._Constants.Add(mc[i].Groups["name"].Value); } }
public static void Condense(string source, ref SourcepawnDefinitionCondeser sdc) { int length = source.Length; Regex regex = new Regex(@"\benum(\s+(?<name>[a-zA-Z_][a-zA-Z_1-9]+\:?))?(\s*//.+)?\s*\{" , RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Multiline); //^[ \f\t\v]*(?<name>[a-zA-Z_][a-zA-Z1-9_]+)(\s*=\s*[a-zA-Z0-9-\+\s\"]+)?, Regex inEnumRegex = new Regex(@"^[ \f\t\v]*(?<name>[a-zA-Z_][a-zA-Z1-9_]+)" , RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Multiline); MatchCollection mc = regex.Matches(source, 0); for (int i = 0; i < mc.Count; ++i) { string matchedName = mc[i].Groups["name"].Value; if (!string.IsNullOrWhiteSpace(matchedName)) { sdc._Types.Add(matchedName); } bool canCountDown = false; int scopeLevel = 0; int startIndex = (mc[i].Index + mc[i].Length) - 1; for (int j = startIndex; j < length; ++j) { if (source[j] == '{') { canCountDown = true; scopeLevel++; } else if (canCountDown) { if (source[j] == '}') { scopeLevel--; if (scopeLevel == 0) { string inEnumString = source.Substring(startIndex, (j - startIndex) + 1); MatchCollection inEnumMC = inEnumRegex.Matches(inEnumString); for (int k = 0; k < inEnumMC.Count; ++k) { /*if (inEnumMC[k].Groups["name"].Value == "enum") * { * int nul = 0; * }*/ sdc._Constants.Add(inEnumMC[k].Groups["name"].Value); } break; } } } } } regex = new Regex(@"\bstruct\s+(?<name>[a-zA-Z_][a-zA-Z_1-9]+)" , RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase); mc = regex.Matches(source, 0); for (int i = 0; i < mc.Count; ++i) { sdc._Types.Add(mc[i].Groups["name"].Value); } regex = new Regex(@"\bproperty(\s+[a-zA-Z_][a-zA-Z_1-9]+)?(\s+(?<name>[a-zA-Z_][a-zA-Z_1-9]+))\s*\{" , RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Multiline); mc = regex.Matches(source, 0); for (int i = 0; i < mc.Count; ++i) { sdc._Properties.Add(mc[i].Groups["name"].Value); } regex = new Regex(@"\b(functag|funcenum|typeset|typedef)(\s+(?<name>[a-zA-Z_][a-zA-Z_1-9]+))" , RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase); mc = regex.Matches(source, 0); for (int i = 0; i < mc.Count; ++i) { sdc._Types.Add(mc[i].Groups["name"].Value); } }
public static void Condense(string source, ref SourcepawnDefinitionCondeser sdc) { int length = source.Length; Regex regex = new Regex(@"\bmethodmap\s+(([a-zA-z_][a-zA-z1-9_]+\s+[a-zA-z_][a-zA-z1-9_]+)|([a-zA-z_][a-zA-z1-9_]+\s*\<\s*[a-zA-z_][a-zA-z1-9_]+))" , RegexOptions.Compiled | RegexOptions.ExplicitCapture); MatchCollection mc = regex.Matches(source, 0); List <TextMarker> methodmapBlocks = new List <TextMarker>(); for (int i = 0; i < mc.Count; ++i) { bool canCountDown = false; int scopeLevel = 0; int startIndex = (mc[i].Index + mc[i].Length) - 1; for (int j = startIndex; j < length; ++j) { if (source[j] == '{') { canCountDown = true; scopeLevel++; } else if (canCountDown) { if (source[j] == '}') { scopeLevel--; if (scopeLevel == 0) { methodmapBlocks.Add(new TextMarker() { Position = startIndex, EndPosition = j, Value = source.Substring(startIndex, j - startIndex + 1) }); break; } } } } } regex = new Regex(@"/\*.*?\*/", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline); mc = regex.Matches(source, 0); List <TextMarker> commentBlocks = new List <TextMarker>(); for (int i = 0; i < mc.Count; ++i) { commentBlocks.Add(new TextMarker() { Position = mc[i].Index, EndPosition = mc[i].Index + mc[i].Length, Value = mc[i].Value }); } regex = new Regex(@"(?<fullname>\b(public|stock|native|forward|normal)\s+((public|stock|native|static|forward|normal)\s+){0,2}((([a-zA-z]+\:)|([a-zA-z]+\s+)))?(?<name>[a-zA-Z][a-zA-Z1-9_]+)(\(.*?\))(\s*\=.+?)?(?=(\s*(\;|\{))))" , RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.ExplicitCapture); mc = regex.Matches(source, 0); for (int i = 0; i < mc.Count; ++i) { int foundIndex = mc[i].Index; bool isMethod = false; for (int j = 0; j < methodmapBlocks.Count; ++j) { if (foundIndex >= methodmapBlocks[j].Position) { if (foundIndex <= methodmapBlocks[j].EndPosition) { isMethod = true; break; } } } if (isMethod) { sdc._MethodNames.Add(mc[i].Groups["name"].Value); } else { string commentString = string.Empty; int possibleCommentIndex = Math.Max(foundIndex - 3, 0); for (int j = 0; j < commentBlocks.Count; ++j) { int testPosition = commentBlocks[j].EndPosition; if ((possibleCommentIndex <= testPosition) && (foundIndex >= testPosition)) { commentString = PreParseCommentString(commentBlocks[j].Value); break; } } string FuncName = mc[i].Groups["name"].Value; sdc._FunctionNames.Add(FuncName); sdc._Functions.Add(new SPFunction() { Name = FuncName, FullName = PreParseFullFunctionName(mc[i].Groups["fullname"].Value), Comment = commentString }); } } }