Exemple #1
0
  public List<Rule> findAllRules() {
    IntegerElement x, y;
    ArrayList<Rule> rules = new ArrayList<Rule>();

    for (x = (IntegerElement) getMinX(); x.compareTo(getMaxX()) <= 0; x = x.succ()) {
      for (y = (IntegerElement) getMinY(); y.compareTo(getMaxY()) <= 0; y = y.succ()) {
        boolean escaped = (!y.isZero() && get(x, y.pred()).getChar() != ' ');
        if (escaped) continue;
        if (get(x, y).getChar() == '(') {
          // System.out.println("Found a rule start at " + x + ", " + y);
          IntegerElement x2 = x;
          CharacterElement g = get(x2, y);
          while (g.getChar() != ')' && x2.compareTo(getMaxX()) <= 0) {
            x2 = x2.succ();
            g = get(x2, y);
          }
          if (g.getChar() != ')') continue;
          // System.out.println("Found a rule from " + x + "," + y + " to " + x2);
          CharacterElement w = get(x2.pred(), y);
          if (w.getChar() == ' ') w = null;
          Rule r = new Rule(this, x.succ(), y.succ(), (x2.subtract(x)).pred(), w);
          rules.add(r);
        }
      }
    }

    return rules;
  }