3254 */
3255 private Node closure(Node prev) {
3256 Node atom;
3257 int ch = peek();
3258 switch (ch) {
3259 case '?':
3260 ch = next();
3261 if (ch == '?') {
3262 next();
3263 return new Ques(prev, Qtype.LAZY);
3264 } else if (ch == '+') {
3265 next();
3266 return new Ques(prev, Qtype.POSSESSIVE);
3267 }
3268 return new Ques(prev, Qtype.GREEDY);
3269 case '*':
3270 return curly(prev, 0);
3271 case '+':
3272 return curly(prev, 1);
3273 case '{':
3274 ch = temp[cursor+1];
3275 if (ASCII.isDigit(ch)) {
3276 skip();
3277 int cmin = 0;
3278 do {
3279 cmin = cmin * 10 + (ch - '0');
3280 } while (ASCII.isDigit(ch = read()));
3281 int cmax = cmin;
3282 if (ch == ',') {
3283 ch = read();
3284 cmax = MAX_REPS;
3285 if (ch != '}') {
3286 cmax = 0;
3287 while (ASCII.isDigit(ch)) {
3288 cmax = cmax * 10 + (ch - '0');
3289 ch = read();
3290 }
3291 }
3292 }
3293 if (ch != '}')
3294 throw error("Unclosed counted closure");
3295 if (((cmin) | (cmax) | (cmax - cmin)) < 0)
3296 throw error("Illegal repetition range");
3297 Curly curly;
3298 ch = peek();
3299 if (ch == '?') {
3300 next();
3301 curly = new Curly(prev, cmin, cmax, Qtype.LAZY);
3302 } else if (ch == '+') {
3303 next();
3304 curly = new Curly(prev, cmin, cmax, Qtype.POSSESSIVE);
3305 } else {
3306 curly = new Curly(prev, cmin, cmax, Qtype.GREEDY);
3307 }
3308 return curly;
3309 } else {
3310 throw error("Illegal repetition");
3311 }
3312 default:
3313 return prev;
3314 }
3315 }
|
3254 */
3255 private Node closure(Node prev) {
3256 Node atom;
3257 int ch = peek();
3258 switch (ch) {
3259 case '?':
3260 ch = next();
3261 if (ch == '?') {
3262 next();
3263 return new Ques(prev, Qtype.LAZY);
3264 } else if (ch == '+') {
3265 next();
3266 return new Ques(prev, Qtype.POSSESSIVE);
3267 }
3268 return new Ques(prev, Qtype.GREEDY);
3269 case '*':
3270 return curly(prev, 0);
3271 case '+':
3272 return curly(prev, 1);
3273 case '{':
3274 ch = skip();
3275 if (ASCII.isDigit(ch)) {
3276 int cmin = 0, cmax;
3277 try {
3278 do {
3279 cmin = Math.addExact(Math.multiplyExact(cmin, 10),
3280 ch - '0');
3281 } while (ASCII.isDigit(ch = read()));
3282 cmax = cmin;
3283 if (ch == ',') {
3284 ch = read();
3285 cmax = MAX_REPS;
3286 if (ch != '}') {
3287 cmax = 0;
3288 while (ASCII.isDigit(ch)) {
3289 cmax = Math.addExact(Math.multiplyExact(cmax, 10),
3290 ch - '0');
3291 ch = read();
3292 }
3293 }
3294 }
3295 } catch (ArithmeticException ae) {
3296 throw error("Illegal repetition range");
3297 }
3298 if (ch != '}')
3299 throw error("Unclosed counted closure");
3300 if (cmax < cmin)
3301 throw error("Illegal repetition range");
3302 Curly curly;
3303 ch = peek();
3304 if (ch == '?') {
3305 next();
3306 curly = new Curly(prev, cmin, cmax, Qtype.LAZY);
3307 } else if (ch == '+') {
3308 next();
3309 curly = new Curly(prev, cmin, cmax, Qtype.POSSESSIVE);
3310 } else {
3311 curly = new Curly(prev, cmin, cmax, Qtype.GREEDY);
3312 }
3313 return curly;
3314 } else {
3315 throw error("Illegal repetition");
3316 }
3317 default:
3318 return prev;
3319 }
3320 }
|