Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace DefaultGSNamesCrawler
- {
- static class Util
- {
- public static void ForEach(this MatchCollection matches, Action<Match> action)
- {
- for (int i = 0; i < matches.Count; i++) {
- action(matches[i]);
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var path = args[0];
- var files = Directory.GetFiles(path, "*.gs");
- var classes = new HashSet<string>();
- var methods = new HashSet<string>();
- var constants = new HashSet<string>();
- var classRegexp = new Regex(@"^\s*(\w+\s+)*class\s+(\w+)\b",
- RegexOptions.Multiline | RegexOptions.Compiled);
- var methodRegexp = new Regex(@"^\s*((?:\w+\s+)*)(\w+)\s+(\w+)\s*\(",
- RegexOptions.Multiline | RegexOptions.Compiled);
- var constantRegexp = new Regex(@"^\s*((?:\w+\s+)*define\s+(?:\w+\s+)*)(\w+)\s+(\w+)\s*=",
- RegexOptions.Multiline | RegexOptions.Compiled);
- foreach (var file in files) {
- var contents = File.ReadAllText(file);
- classRegexp.Matches(contents).ForEach(m => classes.Add(m.Groups[2].Value));
- methodRegexp.Matches(contents).ForEach(m => {
- if (m.Groups[1].Value.Contains("public"))
- methods.Add(m.Groups[3].Value);
- });
- constantRegexp.Matches(contents).ForEach(m => {
- if (m.Groups[1].Value.Contains("public"))
- constants.Add(m.Groups[3].Value);
- });
- }
- var output = new StringBuilder();
- output.AppendFormat(@"\b({0})\b", String.Join("|", classes.OrderBy(s => s).ToArray()));
- output.AppendLine();
- output.AppendFormat(@"\b({0})\b", String.Join("|", methods.OrderBy(s => s).ToArray()));
- output.AppendLine();
- output.AppendFormat(@"\b({0})\b", String.Join("|", constants.OrderBy(s => s).ToArray()));
- File.WriteAllText("output.txt", output.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement