wrap_keyword_regexp.js 716 B

123456789101112131415161718192021
  1. // a little script to turn giant keyword regexps into
  2. // something that ace can use; for example:
  3. //
  4. // \b(NS(Rect(ToCGRect|FromCGRect)|MakeCollectable|S(tringFromProtocol))\b
  5. //
  6. // into
  7. //
  8. // (?:\\b)(NS(?:Rect(?:ToCGRect|FromCGRect)|MakeCollectable|S(?:tringFromProtocol))(?:\b)
  9. var inputString = process.argv.splice(2)[0];
  10. // solve word boundaries
  11. var outputString = inputString.replace(/\\b/g, "(?:\\\\b)");
  12. // I apparently need to do this, instead of something clever, because the regexp
  13. // lastIndex is screwing up my positional
  14. outputString = outputString.split("b)(");
  15. outputString = outputString[0] + "b)(" + outputString[1].replace(/\(([^\?])/g, "(?:$1");
  16. console.log("\n\n" + outputString + "\n\n");