szabivan

Question node

Feb 12th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.31 KB | None | 0 0
  1. static final class Ques extends Node {
  2.         Node atom;
  3.         int type;
  4.         Ques(Node node, int type) {
  5.             this.atom = node;
  6.             this.type = type;
  7.         }
  8.         boolean match(Matcher matcher, int i, CharSequence seq) {
  9.             switch (type) {
  10.             case GREEDY:
  11.                 return (atom.match(matcher, i, seq) && next.match(matcher, matcher.last, seq))
  12.                     || next.match(matcher, i, seq);
  13.             case LAZY:
  14.                 return next.match(matcher, i, seq)
  15.                     || (atom.match(matcher, i, seq) && next.match(matcher, matcher.last, seq));
  16.             case POSSESSIVE:
  17.                 if (atom.match(matcher, i, seq)) i = matcher.last;
  18.                 return next.match(matcher, i, seq);
  19.             default:
  20.                 return atom.match(matcher, i, seq) && next.match(matcher, matcher.last, seq);
  21.             }
  22.         }
  23.         boolean study(TreeInfo info) {
  24.             if (type != INDEPENDENT) {
  25.                 int minL = info.minLength;
  26.                 atom.study(info);
  27.                 info.minLength = minL;
  28.                 info.deterministic = false;
  29.                 return next.study(info);
  30.             } else {
  31.                 atom.study(info);
  32.                 return next.study(info);
  33.             }
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment