public final RegExp normaliseMacros()

in jflex/src/main/java/jflex/core/RegExp.java [292:349]


  public final RegExp normaliseMacros(Macros m) {
    RegExp1 unary;
    RegExp2 binary;
    RegExp content;

    switch (type) {
      case sym.BAR:
      case sym.CONCAT:
        binary = (RegExp2) this;
        return new RegExp2(type, binary.r1.normaliseMacros(m), binary.r2.normaliseMacros(m));

      case sym.STAR:
      case sym.PLUS:
      case sym.QUESTION:
      case sym.BANG:
      case sym.TILDE:
        unary = (RegExp1) this;
        content = (RegExp) unary.content;
        return new RegExp1(type, content.normaliseMacros(m));

      case sym.CCLASS:
      case sym.CCLASSNOT:
        {
          unary = (RegExp1) this;
          List<RegExp> contents = (List<RegExp>) unary.content;
          List<RegExp> newContents = new ArrayList<RegExp>(contents.size());
          for (RegExp r : contents) {
            RegExp n = r.normaliseMacros(m);
            newContents.add(n);
          }
          return new RegExp1(type, newContents);
        }

      case sym.CCLASSOP:
        unary = (RegExp1) this;
        binary = (RegExp2) unary.content;
        RegExp l = binary.r1.normaliseMacros(m);
        RegExp r = binary.r2.normaliseMacros(m);
        return new RegExp1(type, new RegExp2(binary.type, l, r));

      case sym.STRING:
      case sym.STRING_I:
      case sym.CHAR:
      case sym.CHAR_I:
      case sym.PRIMCLASS:
      case sym.PRECLASS:
      case sym.UNIPROPCCLASS:
        unary = (RegExp1) this;
        return new RegExp1(type, unary.content);

      case sym.MACROUSE:
        unary = (RegExp1) this;
        return m.getDefinition((String) unary.content).normaliseMacros(m);

      default:
        throw new RegExpException(this);
    }
  }