@Override
  public int compare(SyntaxNode left, SyntaxNode right) {
    Integer leftMark = left.getStart();
    Integer rightMark = right.getStart();

    if (reverse) {
      return rightMark.compareTo(leftMark);
    }
    return leftMark.compareTo(rightMark);
  }
 @Override
 public String getAbstractSyntax(ChoiceContext context) {
   context.push(arguments);
   String res = ref.getAbstractSyntax(context);
   context.pop();
   return res;
 }
Exemple #3
0
  void _followPosition(BitSet[] follow, SyntaxNode[] nodes) {
    BitSet last, first;
    int size;

    _left._followPosition(follow, nodes);

    last = _lastPosition();
    first = _firstPosition();
    size = last.size();

    while (0 < size--) if (last.get(size)) follow[size].or(first);
  }
Exemple #4
0
 SyntaxNode _clone(int pos[]) {
   return new StarNode(_left._clone(pos));
 }
Exemple #5
0
 BitSet _lastPosition() {
   return _left._lastPosition();
 }
Exemple #6
0
 BitSet _firstPosition() {
   return _left._firstPosition();
 }
Exemple #7
0
  private SyntaxNode __repetition(SyntaxNode atom) throws MalformedPatternException {
    int min, max, startPosition[];
    SyntaxNode root = null;
    CatNode catNode;

    __match('{');

    min = __parseUnsignedInteger(10, 1, Integer.MAX_VALUE);
    startPosition = new int[1];
    startPosition[0] = __position;

    if (__lookahead == '}') {
      // Match exactly min times.  Concatenate the atom min times.
      __match('}');

      if (min == 0)
        throw new MalformedPatternException(
            "Parse error: Superfluous interval specified at position "
                + __bytesRead
                + ".  Number of occurences was set to zero.");

      if (min == 1) return atom;

      root = catNode = new CatNode();
      catNode._left = atom;

      while (--min > 1) {
        atom = atom._clone(startPosition);

        catNode._right = new CatNode();
        catNode = (CatNode) catNode._right;
        catNode._left = atom;
      }

      catNode._right = atom._clone(startPosition);
    } else if (__lookahead == ',') {
      __match(',');

      if (__lookahead == '}') {
        // match at least min times
        __match('}');

        if (min == 0) return new StarNode(atom);

        if (min == 1) return new PlusNode(atom);

        root = catNode = new CatNode();
        catNode._left = atom;

        while (--min > 0) {
          atom = atom._clone(startPosition);

          catNode._right = new CatNode();
          catNode = (CatNode) catNode._right;
          catNode._left = atom;
        }

        catNode._right = new StarNode(atom._clone(startPosition));
      } else {
        // match at least min times and at most max times
        max = __parseUnsignedInteger(10, 1, Integer.MAX_VALUE);
        __match('}');

        if (max < min)
          throw new MalformedPatternException(
              "Parse error: invalid interval; "
                  + max
                  + " is less than "
                  + min
                  + " at position "
                  + __bytesRead);
        if (max == 0)
          throw new MalformedPatternException(
              "Parse error: Superfluous interval specified at position "
                  + __bytesRead
                  + ".  Number of occurences was set to zero.");

        if (min == 0) {
          if (max == 1) return new QuestionNode(atom);

          root = catNode = new CatNode();
          atom = new QuestionNode(atom);
          catNode._left = atom;

          while (--max > 1) {
            atom = atom._clone(startPosition);

            catNode._right = new CatNode();
            catNode = (CatNode) catNode._right;
            catNode._left = atom;
          }

          catNode._right = atom._clone(startPosition);
        } else if (min == max) {
          if (min == 1) return atom;

          root = catNode = new CatNode();
          catNode._left = atom;

          while (--min > 1) {
            atom = atom._clone(startPosition);

            catNode._right = new CatNode();
            catNode = (CatNode) catNode._right;
            catNode._left = atom;
          }

          catNode._right = atom._clone(startPosition);
        } else {
          int count;

          root = catNode = new CatNode();
          catNode._left = atom;

          for (count = 1; count < min; count++) {
            atom = atom._clone(startPosition);

            catNode._right = new CatNode();
            catNode = (CatNode) catNode._right;
            catNode._left = atom;
          }

          atom = new QuestionNode(atom._clone(startPosition));

          count = max - min;

          if (count == 1) catNode._right = atom;
          else {
            catNode._right = new CatNode();
            catNode = (CatNode) catNode._right;
            catNode._left = atom;

            while (--count > 1) {
              atom = atom._clone(startPosition);

              catNode._right = new CatNode();
              catNode = (CatNode) catNode._right;
              catNode._left = atom;
            }

            catNode._right = atom._clone(startPosition);
          }
        }
      }
    } else
      throw new MalformedPatternException(
          "Parse error: unexpected character "
              + __lookahead
              + " in interval at position "
              + __bytesRead);
    __position = startPosition[0];
    return root;
  }
 @Override
 public SyntaxNode unlink() {
   return ref.unlink();
 }
 public String getDesc() {
   String desc = super.getDesc();
   if (desc == null || desc.isEmpty()) return ref.getDesc();
   return desc;
 }