Exemple #1
0
  private static Sexp parseCharacterClass(String pattern, Sexp sexp) {
    Matcher matcher = Pattern.compile("(.*)(.\\-.)(.*)").matcher(pattern);

    if (matcher.matches()) {
      String[] range = matcher.group(2).split("-");

      parseCharacterClass(matcher.group(1), sexp);
      sexp.add(new Sexp(RANGE).add(literal(range[0])).add(literal(range[1])));
      parseCharacterClass(matcher.group(3), sexp);

    } else if (!pattern.isEmpty()) {
      for (String token : pattern.split("")) {
        sexp.add(literal(token));
      }
    }

    return sexp;
  }
Exemple #2
0
 private static Sexp intersection(Sexp lhs, Sexp rhs) {
   Sexp intersectionSexp = new Sexp(INTERSECTION).add(lhs);
   if (rhs.first().equals(INTERSECTION)) {
     intersectionSexp.addAll(ArrayUtils.remove(rhs.getValues().toArray(), 0));
   } else {
     intersectionSexp.add(rhs);
   }
   return intersectionSexp;
 }
Exemple #3
0
  private static Sexp quantifyRhs(Sexp sexp, Quantifier quantifier) {
    Sexp quantifierSexp = null;
    if (sexp.first() != null && sexp.first().equals(UNION)) {
      quantifierSexp = sexp.add(quantify((Sexp) sexp.removeLast(), quantifier));
    } else {
      quantifierSexp = quantify(sexp, quantifier);
    }

    return quantifierSexp;
  }
Exemple #4
0
  private static Sexp union(Sexp lhs, Sexp... rhs) {
    if (lhs == null) {
      return union(rhs[0], (Sexp[]) ArrayUtils.remove(rhs, 0));
    } else if (ArrayUtils.isEmpty(rhs)) {
      return lhs;
    } else if (lhs.first() != null && lhs.first().equals(UNION)) {
      for (Sexp sexp : rhs) {
        lhs.add(sexp);
      }
      return lhs;
    }

    return new Sexp(UNION).add(lhs).addAll(rhs);
  }