code: public TregexPattern compile(String tregex) {
      for (Pair<String, String> macro : macros) {
        tregex = tregex.replaceAll(macro.first(), macro.second());
      }
      TregexPattern pattern;
      try {
        TregexParser parser = new TregexParser(new StringReader(tregex + '\n'),
                                               basicCatFunction, headFinder);
        pattern = parser.Root();
      } catch (TokenMgrError tme) {
        throw new TregexParseException("Could not parse " + tregex, tme);
      } catch (ParseException e) {
        throw new TregexParseException("Could not parse " + tregex, e);
      }
      pattern.setPatternString(tregex);
      return pattern;
    }
docs: Create a TregexPattern from this tregex string using the headFinder and
  basicCat function this TregexPatternCompiler was created with.
  
  <i>Implementation note:</i> If there is an invalid token in the Tregex
  parser, JavaCC will throw a TokenMgrError.  This is a class
  that extends Error, not Exception (OMG! - bad!), and so rather than
  requiring clients to catch it, we wrap it in a ParseException.
  (The original Error's are thrown in TregexParserTokenManager.)
  
  @param tregex The pattern to parse
  @return A new TregexPattern object based on this string
  @throws TregexParseException If the expression is syntactically invalid