~ubuntu-branches/ubuntu/jaunty/weka/jaunty

« back to all changes in this revision

Viewing changes to weka/core/parser/JFlex/LexParse.cup

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg, Torsten Werner, Soeren Sonnenburg
  • Date: 2008-10-30 06:42:46 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081030064246-648zj038l155host
Tags: 3.5.8+cup1-1
[ Torsten Werner ]
* Update Section field in doc-base file.
* Add Class-Path attribute to jar file.

[ Soeren Sonnenburg ]
* Update my email address to sonne@debian.org.
* Update copyright.
* Remove build, java cup and jflex from orig.tar.gz.
* Add cup and jflex as build dependency.
* Patch weka source to use cup from debian.
* Patch weka shell wrapper to use java-6-sun or openjdk.
* Obtain documentation from svn.
* Build depend on texlive-latex-extra (required to generate documentation).
* Add javadoc as build target.
* Use java-wrappers to start weka.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 
 * JFlex 1.4.1                                                             *
3
 
 * Copyright (C) 1998-2004  Gerwin Klein <lsf@jflex.de>                    *
4
 
 * All rights reserved.                                                    *
5
 
 *                                                                         *
6
 
 * This program is free software; you can redistribute it and/or modify    *
7
 
 * it under the terms of the GNU General Public License. See the file      *
8
 
 * COPYRIGHT for more information.                                         *
9
 
 *                                                                         *
10
 
 * This program is distributed in the hope that it will be useful,         *
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
13
 
 * GNU General Public License for more details.                            *
14
 
 *                                                                         *
15
 
 * You should have received a copy of the GNU General Public License along *
16
 
 * with this program; if not, write to the Free Software Foundation, Inc., *
17
 
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                 *
18
 
 *                                                                         *
19
 
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20
 
 
21
 
package JFlex;
22
 
 
23
 
import java.util.*;
24
 
 
25
 
/* customizing code */
26
 
 
27
 
action code {:
28
 
 
29
 
  LexScan     scanner;
30
 
  CharClasses charClasses = new CharClasses(127);
31
 
  RegExps     regExps     = new RegExps();
32
 
  Macros      macros      = new Macros();
33
 
  Integer     stateNumber;
34
 
  Timer       t           = new Timer();
35
 
  EOFActions  eofActions  = new EOFActions();
36
 
 
37
 
  void fatalError(ErrorMessages message, int line, int col) {
38
 
    syntaxError(message, line, col);
39
 
    throw new GeneratorException();
40
 
  }
41
 
 
42
 
  void fatalError(ErrorMessages message) {
43
 
    fatalError(message, scanner.currentLine(), -1);
44
 
    throw new GeneratorException();
45
 
  }
46
 
 
47
 
  void syntaxError(ErrorMessages message) {
48
 
    Out.error(scanner.file, message, scanner.currentLine(), -1);
49
 
  }
50
 
  
51
 
  void syntaxError(ErrorMessages message, int line) {
52
 
    Out.error(scanner.file, message, line, -1);
53
 
  }
54
 
 
55
 
  void syntaxError(ErrorMessages message, int line, int col) {
56
 
    Out.error(scanner.file, message, line, col);
57
 
  }
58
 
 
59
 
 
60
 
  private boolean check(int type, char c) {
61
 
    switch (type) {
62
 
      case sym.JLETTERCLASS:
63
 
        return Character.isJavaIdentifierStart(c);
64
 
        
65
 
      case sym.JLETTERDIGITCLASS:
66
 
        return Character.isJavaIdentifierPart(c);
67
 
        
68
 
      case sym.LETTERCLASS:
69
 
        return Character.isLetter(c);
70
 
        
71
 
      case sym.DIGITCLASS:
72
 
        return Character.isDigit(c);
73
 
        
74
 
      case sym.UPPERCLASS: 
75
 
        return Character.isUpperCase(c);
76
 
        
77
 
      case sym.LOWERCLASS: 
78
 
        return Character.isLowerCase(c);
79
 
        
80
 
      default: return false;
81
 
    }
82
 
  }
83
 
  
84
 
  private Vector makePreClass(int type) {
85
 
    
86
 
    Vector result = new Vector();
87
 
    
88
 
    char c = 0;
89
 
    char start = 0;
90
 
    char last = charClasses.getMaxCharCode();
91
 
    
92
 
    boolean prev, current;
93
 
    
94
 
    prev = check(type,'\u0000');
95
 
    
96
 
    for (c = 1; c < last; c++) {
97
 
      
98
 
      current = check(type,c);
99
 
      
100
 
      if (!prev && current) start = c;
101
 
      if (prev && !current) {
102
 
        result.addElement(new Interval(start, (char)(c-1)));
103
 
      }
104
 
      
105
 
      prev = current;
106
 
    }
107
 
    
108
 
    // the last iteration is moved out of the loop to
109
 
    // avoid an endless loop if last == maxCharCode and
110
 
    // last+1 == 0
111
 
    current = check(type,c);
112
 
    
113
 
    if (!prev && current) result.addElement(new Interval(c,c));
114
 
    if (prev && current)  result.addElement(new Interval(start, c));    
115
 
    if (prev && !current) result.addElement(new Interval(start, (char)(c-1)));
116
 
 
117
 
    return result;
118
 
  }
119
 
  
120
 
  private RegExp makeRepeat(RegExp r, int n1, int n2, int line, int col) {
121
 
 
122
 
    if (n1 <= 0 && n2 <= 0) {
123
 
      syntaxError(ErrorMessages.REPEAT_ZERO, line, col);
124
 
      return null;
125
 
    }
126
 
 
127
 
    if (n1 > n2) {
128
 
      syntaxError(ErrorMessages.REPEAT_GREATER, line, col);
129
 
      return null;
130
 
    }
131
 
    
132
 
    int i;
133
 
    RegExp result;    
134
 
 
135
 
    if (n1 > 0) {
136
 
      result = r;
137
 
      n1--; n2--; // we need one concatenation less than the number of expressions to match
138
 
    }
139
 
    else {
140
 
      result = new RegExp1(sym.QUESTION,r);
141
 
      n2--;
142
 
    }
143
 
 
144
 
    for (i = 0; i < n1; i++) 
145
 
      result = new RegExp2(sym.CONCAT, result, r);
146
 
      
147
 
    n2-= n1;  
148
 
    for (i = 0; i < n2; i++)
149
 
      result = new RegExp2(sym.CONCAT, result, new RegExp1(sym.QUESTION,r));
150
 
    
151
 
    return result;
152
 
  }
153
 
 
154
 
  private RegExp makeNL() {
155
 
    Vector list = new Vector();
156
 
    list.addElement(new Interval('\n','\r'));
157
 
    list.addElement(new Interval('\u0085','\u0085'));
158
 
    list.addElement(new Interval('\u2028','\u2029'));
159
 
 
160
 
        // assumption: line feeds are caseless
161
 
    charClasses.makeClass(list, false);
162
 
    charClasses.makeClass('\n', false);
163
 
    charClasses.makeClass('\r', false);
164
 
 
165
 
    RegExp1   c = new RegExp1(sym.CCLASS, list);
166
 
    Character n = new Character('\n');
167
 
    Character r = new Character('\r');
168
 
 
169
 
    return new RegExp2(sym.BAR, 
170
 
                       c, 
171
 
                       new RegExp2(sym.CONCAT, 
172
 
                                   new RegExp1(sym.CHAR, r), 
173
 
                                   new RegExp1(sym.CHAR, n)));
174
 
  }
175
 
  
176
 
:};
177
 
 
178
 
parser code {:
179
 
   public LexScan scanner;
180
 
 
181
 
   public LexParse(LexScan scanner) {
182
 
     super(scanner);
183
 
     this.scanner = scanner;
184
 
   }
185
 
   
186
 
   public CharClasses getCharClasses() {
187
 
     return action_obj.charClasses;
188
 
   }
189
 
 
190
 
   public EOFActions getEOFActions() {
191
 
     return action_obj.eofActions;
192
 
   }
193
 
       
194
 
   public void report_error(String message, Object info) {     
195
 
     if ( info instanceof java_cup.runtime.Symbol ) {
196
 
       java_cup.runtime.Symbol s = (java_cup.runtime.Symbol) info;
197
 
  
198
 
       if (s.sym == sym.EOF) 
199
 
         Out.error(ErrorMessages.UNEXPECTED_EOF);
200
 
       else
201
 
         Out.error(scanner.file, ErrorMessages.SYNTAX_ERROR, s.left, s.right);
202
 
     }
203
 
     else 
204
 
       Out.error(ErrorMessages.UNKNOWN_SYNTAX);
205
 
   }
206
 
   
207
 
   public void report_fatal_error(String message, Object info) {
208
 
     // report_error(message, info);
209
 
     throw new GeneratorException();
210
 
   }
211
 
 
212
 
:};
213
 
 
214
 
init with {:
215
 
  action_obj.scanner = this.scanner;
216
 
:};
217
 
 
218
 
/* token declarations */
219
 
 
220
 
terminal OPENBRACKET, CLOSEBRACKET, HAT, DOLLAR, OPENCLASS,
221
 
         CLOSECLASS, DASH, DELIMITER, EQUALS, COMMA, LESSTHAN,
222
 
         MORETHAN, LBRACE, RBRACE, FULL, UNICODE, REGEXPEND;
223
 
 
224
 
terminal JLETTERCLASS, JLETTERDIGITCLASS, LETTERCLASS, DIGITCLASS, 
225
 
         UPPERCLASS, LOWERCLASS, EOFRULE, NOACTION, LOOKAHEAD;
226
 
         
227
 
terminal Action ACTION;
228
 
terminal String IDENT, USERCODE;
229
 
terminal Integer REPEAT;
230
 
 
231
 
/* tokens used in RegExp parse tree */
232
 
terminal STAR, PLUS, BAR, QUESTION, POINT, BANG, TILDE;
233
 
 
234
 
terminal Character CHAR;
235
 
terminal String STRING, MACROUSE;
236
 
 
237
 
/* symbols *only* used in the parse tree (not in the grammar) */
238
 
terminal CCLASS, CCLASSNOT, CONCAT;
239
 
terminal STRING_I, CHAR_I;  /* case insensitive strings/chars */
240
 
 
241
 
 
242
 
non terminal           macros, macro;
243
 
non terminal Integer   rule;
244
 
non terminal NFA       specification;
245
 
non terminal RegExp    series, concs, nregexp, regexp, charclass, lookaheadOPT;
246
 
non terminal Interval classcontentelem;
247
 
non terminal Vector    states, statesOPT, classcontent, preclass, rules;
248
 
non terminal Boolean   hatOPT;
249
 
non terminal Action    actions;
250
 
 
251
 
 
252
 
/* grammar specification */
253
 
start with specification;
254
 
 
255
 
specification ::=  USERCODE
256
 
                   /* delimiter is checked in lexer */
257
 
                   macros
258
 
                   DELIMITER 
259
 
                   rules
260
 
                   {:
261
 
                     scanner.t.stop();
262
 
 
263
 
                     Out.checkErrors();
264
 
                     
265
 
                     Out.time(ErrorMessages.PARSING_TOOK, t);
266
 
                     
267
 
                     macros.expand();
268
 
                     Enumeration unused = macros.unused();                     
269
 
                     while ( unused.hasMoreElements() ) {
270
 
                       Out.warning("Macro \""+unused.nextElement()+"\" has been declared but never used.");
271
 
                     }
272
 
 
273
 
                     SemCheck.check(regExps, macros, charClasses.getMaxCharCode(), scanner.file);
274
 
  
275
 
                     regExps.checkActions();
276
 
 
277
 
                     if (Options.dump) charClasses.dump();
278
 
 
279
 
                     Out.print("Constructing NFA : ");
280
 
 
281
 
                     t.start();
282
 
                     int num = regExps.getNum();
283
 
                     
284
 
                     RESULT = new NFA(charClasses.getNumClasses(), 
285
 
                                      scanner, regExps, macros, charClasses);
286
 
                     
287
 
                     eofActions.setNumLexStates(scanner.states.number());
288
 
 
289
 
                     for (int i = 0; i < num; i++) {
290
 
                       if (regExps.isEOF(i))
291
 
                         eofActions.add( regExps.getStates(i), regExps.getAction(i) );
292
 
                       else
293
 
                         RESULT.addRegExp(i);
294
 
                     }
295
 
                     
296
 
                     if (scanner.standalone) RESULT.addStandaloneRule();
297
 
                     t.stop();
298
 
       
299
 
                     Out.time("");              
300
 
                         Out.time(ErrorMessages.NFA_TOOK, t);
301
 
                     
302
 
                   :}
303
 
                 | /* emtpy spec. error */
304
 
                   {: 
305
 
                     fatalError(ErrorMessages.NO_LEX_SPEC);
306
 
                   :}
307
 
                 ;  
308
 
 
309
 
macros        ::=  /* empty, most switches & state declarations are parsed in lexer */
310
 
                | macros macro
311
 
                | error;
312
 
 
313
 
macro         ::=  FULL
314
 
                   {: charClasses.setMaxCharCode(255); :}
315
 
                |  UNICODE
316
 
                   {: charClasses.setMaxCharCode(0xFFFF); :} 
317
 
                |  IDENT:name EQUALS series:definition REGEXPEND
318
 
                   {: macros.insert(name, definition); :} 
319
 
                | IDENT EQUALS:e
320
 
                   {: syntaxError(ErrorMessages.REGEXP_EXPECTED, eleft, eright); :}
321
 
                ;
322
 
                
323
 
 
324
 
rules         ::=  rules:rlist rule:r
325
 
                   {: rlist.addElement(r); RESULT = rlist; :}
326
 
                |  rules:rlist1 LESSTHAN states:states MORETHAN LBRACE rules:rlist2 RBRACE
327
 
                   {: 
328
 
                     Enumeration rs = rlist2.elements();
329
 
                     while ( rs.hasMoreElements() ) {
330
 
                       Integer elem = (Integer) rs.nextElement();
331
 
                       regExps.addStates( elem.intValue(), states );
332
 
                       rlist1.addElement( elem );
333
 
                     }                       
334
 
                     RESULT = rlist1;
335
 
                   :}
336
 
                |  LESSTHAN states:states MORETHAN LBRACE rules:rlist RBRACE
337
 
                   {: 
338
 
                     Enumeration rs = rlist.elements();
339
 
                     while ( rs.hasMoreElements() ) {
340
 
                       Integer elem = (Integer) rs.nextElement();
341
 
                       regExps.addStates( elem.intValue(), states );
342
 
                     }                       
343
 
                     RESULT = rlist;
344
 
                   :}
345
 
                |  rule:r
346
 
                   {: RESULT = new Vector(); RESULT.addElement(r); :}
347
 
                ;  
348
 
 
349
 
rule          ::=  statesOPT:s hatOPT:bol series:r lookaheadOPT:l actions:a
350
 
                   {: RESULT = new Integer(regExps.insert(rleft, s, r, a, bol, l)); :}
351
 
                |  statesOPT:s EOFRULE ACTION:a
352
 
                   {: RESULT = new Integer(regExps.insert(s, a)); :}
353
 
                |  error
354
 
                ;
355
 
 
356
 
lookaheadOPT  ::=  DOLLAR
357
 
                   {: RESULT = makeNL(); :}
358
 
                |  LOOKAHEAD series:r
359
 
                   {: RESULT = r; :}
360
 
                |  /* empty */
361
 
                   {: RESULT = null; :}
362
 
                |  LOOKAHEAD series:s DOLLAR
363
 
                   {: RESULT = new RegExp2(sym.CONCAT, s, makeNL()); :}
364
 
                ;
365
 
 
366
 
actions       ::=  REGEXPEND ACTION:a
367
 
                   {: RESULT = a; :}
368
 
                |  NOACTION
369
 
                   {: RESULT = null; :}
370
 
                ;
371
 
 
372
 
                
373
 
statesOPT     ::=  LESSTHAN states:list MORETHAN          
374
 
                   {: RESULT = list; :}
375
 
                |  /* empty */
376
 
                   {: RESULT = new Vector(); :}                   
377
 
                ;
378
 
                
379
 
states        ::=  IDENT:id COMMA states:list
380
 
                   {:
381
 
                     stateNumber = scanner.states.getNumber( id );
382
 
                     if ( stateNumber != null )
383
 
                       list.addElement( stateNumber ); 
384
 
                     else {
385
 
                       throw new ScannerException(scanner.file, ErrorMessages.LEXSTATE_UNDECL, 
386
 
                                                  idleft, idright);
387
 
                     }
388
 
                     RESULT = list;
389
 
                   :}                
390
 
                |  IDENT:id
391
 
                   {:
392
 
                     Vector list = new Vector();
393
 
                     stateNumber = scanner.states.getNumber( id );
394
 
                     if ( stateNumber != null )
395
 
                       list.addElement( stateNumber ); 
396
 
                     else {
397
 
                       throw new ScannerException(scanner.file, ErrorMessages.LEXSTATE_UNDECL, 
398
 
                                                  idleft, idright);
399
 
                     }
400
 
                     RESULT = list;
401
 
                   :}
402
 
                 | IDENT COMMA:c
403
 
                   {: syntaxError(ErrorMessages.REGEXP_EXPECTED, cleft, cright+1); :}
404
 
                ;
405
 
                
406
 
hatOPT        ::=  HAT 
407
 
                   {: // assumption: there is no upper case for \n
408
 
                      charClasses.makeClass('\n', false); 
409
 
                      RESULT = new Boolean(true); :}
410
 
                |  /* empty */ 
411
 
                   {: RESULT = new Boolean(false); :}
412
 
                ;
413
 
                
414
 
series        ::= series:r1 BAR concs:r2
415
 
                  {: RESULT = new RegExp2(sym.BAR, r1, r2); :}                 
416
 
                | concs:r
417
 
                  {: RESULT = r; :} 
418
 
                | BAR:b
419
 
                  {: syntaxError(ErrorMessages.REGEXP_EXPECTED, bleft, bright); :}
420
 
                ;
421
 
               
422
 
concs         ::= concs:r1 nregexp:r2
423
 
                  {: RESULT = new RegExp2(sym.CONCAT, r1, r2); :} 
424
 
                | nregexp:r
425
 
                  {: RESULT = r; :}
426
 
                ;
427
 
 
428
 
nregexp       ::= regexp:r
429
 
                  {: RESULT = r; :}
430
 
                | BANG nregexp:r
431
 
                  {: RESULT = new RegExp1(sym.BANG, r); :}
432
 
                | TILDE nregexp:r
433
 
                  {: RESULT = new RegExp1(sym.TILDE, r); :}
434
 
                ;
435
 
 
436
 
regexp        ::=  regexp:r STAR
437
 
                   {: RESULT = new RegExp1(sym.STAR, r); :}
438
 
                |  regexp:r PLUS
439
 
                   {: RESULT = new RegExp1(sym.PLUS, r); :}
440
 
                |  regexp:r QUESTION
441
 
                   {: RESULT = new RegExp1(sym.QUESTION, r); :}
442
 
                |  regexp:r REPEAT:n RBRACE:b
443
 
                   {: RESULT = makeRepeat(r, n.intValue(), n.intValue(), bleft, bright); :}
444
 
                |  regexp:r REPEAT:n1 REPEAT:n2 RBRACE
445
 
                   {: RESULT = makeRepeat(r, n1.intValue(), n2.intValue(), n1left, n2right); :}
446
 
                |  OPENBRACKET series:r CLOSEBRACKET
447
 
                   {: RESULT = r; :}
448
 
                |  MACROUSE:ident
449
 
                   {: 
450
 
                      if ( !scanner.macroDefinition ) {
451
 
                        if ( ! macros.markUsed(ident) ) 
452
 
                          throw new ScannerException(scanner.file, ErrorMessages.MACRO_UNDECL, 
453
 
                                                     identleft, identright);
454
 
                      }
455
 
                      RESULT = new RegExp1(sym.MACROUSE, ident); 
456
 
                   :}
457
 
                |  charclass:c
458
 
                   {: RESULT = c; :}
459
 
                |  preclass:list
460
 
                   {:
461
 
                     try {
462
 
                       // assumption [correct?]: preclasses are already closed under case
463
 
                       charClasses.makeClass(list, false);
464
 
                     }
465
 
                     catch (CharClassException e) {
466
 
                       syntaxError(ErrorMessages.CHARSET_2_SMALL, listleft);
467
 
                     }
468
 
                     RESULT = new RegExp1(sym.CCLASS, list);
469
 
                   :}
470
 
                |  STRING:str
471
 
                   {: 
472
 
                     try {
473
 
                       if ( scanner.caseless ) {
474
 
                         charClasses.makeClass(str, true);
475
 
                         RESULT = new RegExp1(sym.STRING_I, str);
476
 
                       }
477
 
                       else {
478
 
                         charClasses.makeClass(str, false);
479
 
                         RESULT = new RegExp1(sym.STRING, str); 
480
 
                       }
481
 
                     }
482
 
                     catch (CharClassException e) {
483
 
                       syntaxError(ErrorMessages.CS2SMALL_STRING, strleft, strright);
484
 
                     }
485
 
 
486
 
                   :}
487
 
                |  POINT
488
 
                   {: 
489
 
                      Vector any = new Vector();
490
 
                      any.addElement(new Interval('\n','\n'));
491
 
                      // assumption: there is no upper case for \n
492
 
                      charClasses.makeClass('\n', false);
493
 
                      RESULT = new RegExp1(sym.CCLASSNOT, any); 
494
 
                   :}
495
 
                |  CHAR:c
496
 
                   {: 
497
 
                     try {
498
 
                       if ( scanner.caseless ) {
499
 
                         charClasses.makeClass(c.charValue(), true);
500
 
                         RESULT = new RegExp1(sym.CHAR_I, c);
501
 
                       }
502
 
                       else {
503
 
                         charClasses.makeClass(c.charValue(), false);
504
 
                         RESULT = new RegExp1(sym.CHAR, c); 
505
 
                       }
506
 
                     }
507
 
                     catch (CharClassException e) {
508
 
                       syntaxError(ErrorMessages.CS2SMALL_CHAR, cleft, cright);
509
 
                     }
510
 
                   :}
511
 
                ;
512
 
 
513
 
charclass     ::=  OPENCLASS CLOSECLASS
514
 
                   {: 
515
 
                     RESULT = new RegExp1(sym.CCLASS,null);
516
 
                   :}
517
 
                |  OPENCLASS classcontent:list CLOSECLASS:close
518
 
                   {: 
519
 
                     try {
520
 
                       charClasses.makeClass(list, Options.jlex && scanner.caseless);
521
 
                     }
522
 
                     catch (CharClassException e) {
523
 
                       syntaxError(ErrorMessages.CHARSET_2_SMALL, closeleft, closeright);
524
 
                     }
525
 
                     RESULT = new RegExp1(sym.CCLASS,list);
526
 
                   :}
527
 
                |  OPENCLASS HAT CLOSECLASS:close
528
 
                   {: 
529
 
                     Vector list = new Vector();
530
 
                     list.addElement(new Interval((char)0,CharClasses.maxChar));
531
 
                     try {
532
 
                       charClasses.makeClass(list, false);
533
 
                     }
534
 
                     catch (CharClassException e) {
535
 
                       syntaxError(ErrorMessages.CHARSET_2_SMALL, closeleft, closeright);
536
 
                     }
537
 
                     RESULT = new RegExp1(sym.CCLASS,list);
538
 
                   :}
539
 
                |  OPENCLASS HAT classcontent:list CLOSECLASS:close
540
 
                   {: 
541
 
                     try {
542
 
                       charClasses.makeClassNot(list, Options.jlex && scanner.caseless);
543
 
                     }
544
 
                     catch (CharClassException e) {
545
 
                       syntaxError(ErrorMessages.CHARSET_2_SMALL, closeleft, closeright);
546
 
                     }
547
 
                     RESULT = new RegExp1(sym.CCLASSNOT,list);
548
 
                   :}
549
 
                | OPENCLASS DASH classcontent:list CLOSECLASS:close
550
 
                   {: 
551
 
                     try {
552
 
                       list.addElement(new Interval('-','-'));
553
 
                       charClasses.makeClass(list, Options.jlex && scanner.caseless);
554
 
                     }
555
 
                     catch (CharClassException e) {
556
 
                       syntaxError(ErrorMessages.CHARSET_2_SMALL, closeleft, closeright);
557
 
                     }
558
 
                     RESULT = new RegExp1(sym.CCLASS,list);
559
 
                   :}
560
 
                |  OPENCLASS HAT DASH classcontent:list CLOSECLASS:close
561
 
                   {: 
562
 
                     try {
563
 
                       list.addElement(new Interval('-','-'));
564
 
                       charClasses.makeClassNot(list, Options.jlex && scanner.caseless);
565
 
                     }
566
 
                     catch (CharClassException e) {
567
 
                       syntaxError(ErrorMessages.CHARSET_2_SMALL, closeleft, closeright);
568
 
                     }
569
 
                     RESULT = new RegExp1(sym.CCLASSNOT,list);
570
 
                   :}
571
 
                ;
572
 
 
573
 
classcontent  ::=  classcontent:list classcontentelem:elem
574
 
                   {:
575
 
                     list.addElement(elem);
576
 
                     RESULT = list;
577
 
                   :}
578
 
                |  classcontentelem:elem
579
 
                   {:
580
 
                     Vector list = new Vector();
581
 
                     list.addElement(elem);
582
 
                     RESULT = list;
583
 
                   :}
584
 
                |  classcontent:list preclass:plist
585
 
                   {:
586
 
                     for (Enumeration e = plist.elements(); e.hasMoreElements();)
587
 
                       list.addElement(e.nextElement());
588
 
                     RESULT = list;
589
 
                   :}
590
 
                |  preclass:list 
591
 
                   {: RESULT = list; :}
592
 
                |  classcontent:list STRING:s
593
 
                   {: 
594
 
                      for (int i = 0; i < s.length(); i++)
595
 
                        list.addElement(new Interval(s.charAt(i),s.charAt(i)));
596
 
                      RESULT = list;
597
 
                   :}
598
 
                |  STRING:s
599
 
                   {: 
600
 
                      RESULT = new Vector();
601
 
                      for (int i = 0; i < s.length(); i++)
602
 
                        RESULT.addElement(new Interval(s.charAt(i),s.charAt(i)));
603
 
                   :}
604
 
                |  classcontent:list MACROUSE:ident
605
 
                   {: 
606
 
                     syntaxError(ErrorMessages.CHARCLASS_MACRO, identleft, identright);
607
 
                   :}
608
 
                |  MACROUSE:ident
609
 
                   {: 
610
 
                     syntaxError(ErrorMessages.CHARCLASS_MACRO, identleft, identright);
611
 
                   :}
612
 
                ;
613
 
 
614
 
classcontentelem ::= CHAR:c1 DASH CHAR:c2
615
 
                     {: RESULT = new Interval(c1.charValue(), c2.charValue()); :}
616
 
                   | CHAR:c
617
 
                     {: RESULT = new Interval(c.charValue(), c.charValue()); :}
618
 
                   ;
619
 
                   
620
 
preclass ::= JLETTERCLASS
621
 
             {: RESULT = makePreClass(sym.JLETTERCLASS); :}
622
 
           | JLETTERDIGITCLASS 
623
 
             {: RESULT = makePreClass(sym.JLETTERDIGITCLASS); :}
624
 
           | LETTERCLASS
625
 
             {: RESULT = makePreClass(sym.LETTERCLASS); :}
626
 
           | DIGITCLASS
627
 
             {: RESULT = makePreClass(sym.DIGITCLASS); :}
628
 
           | UPPERCLASS
629
 
             {: RESULT = makePreClass(sym.UPPERCLASS); :}
630
 
           | LOWERCLASS
631
 
             {: RESULT = makePreClass(sym.LOWERCLASS); :}
632
 
           ;