KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > java > parser > UnicodeEscapes


1 /* The following code was generated by JFlex 1.3.5 on 8/30/02 3:00 PM */
2
3 /*
4  * The contents of this file are subject to the terms of the Common Development
5  * and Distribution License (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
9  * or http://www.netbeans.org/cddl.txt.
10  *
11  * When distributing Covered Code, include this CDDL Header Notice in each file
12  * and include the License file at http://www.netbeans.org/cddl.txt.
13  * If applicable, add the following below the CDDL Header, with the fields
14  * enclosed by brackets [] replaced by your own identifying information:
15  * "Portions Copyrighted [year] [name of copyright owner]"
16  *
17  * The Original Software is NetBeans. The Initial Developer of the Original
18  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
19  * Microsystems, Inc. All Rights Reserved.
20  */

21
22 package org.netbeans.lib.java.parser;
23
24 import java.io.*;
25 import java.util.ArrayList JavaDoc;
26
27
28 /**
29  * This class is a scanner generated by
30  * <a HREF="http://www.jflex.de/">JFlex</a> 1.3.5
31  * on 8/30/02 3:00 PM from the specification file
32  * <tt>file:/home/th125165/Projects/Source/netbeans-cvs/nb_all/java_meta_2/libsrc/org/netbeans/lib/java/parser/unicode.l</tt>
33  */

34 final class UnicodeEscapes extends FilterReader {
35
36   /** This character denotes the end of file */
37   final public static int YYEOF = -1;
38
39   /** initial size of the lookahead buffer */
40   final private static int YY_BUFFERSIZE = 16384;
41
42   /** lexical states */
43   final public static int DIGITS = 1;
44   final public static int YYINITIAL = 0;
45
46   /**
47    * Translates characters to character classes
48    */

49   final private static String JavaDoc yycmap_packed =
50     "\12\0\1\0\45\0\12\1\7\0\6\1\25\0\1\2\4\0\6\1"+
51     "\16\0\1\3\uff8a\0";
52
53   /**
54    * Translates characters to character classes
55    */

56   final private static char [] yycmap = yy_unpack_cmap(yycmap_packed);
57
58
59   /* error codes */
60   final private static int YY_UNKNOWN_ERROR = 0;
61   final private static int YY_ILLEGAL_STATE = 1;
62   final private static int YY_NO_MATCH = 2;
63   final private static int YY_PUSHBACK_2BIG = 3;
64
65   /* error messages for the codes above */
66   final private static String JavaDoc YY_ERROR_MSG[] = {
67     "Unkown internal scanner error",
68     "Internal error: unknown state",
69     "Error: could not match input",
70     "Error: pushback value was too large"
71   };
72
73   /** the input device */
74   private java.io.Reader JavaDoc yy_reader;
75
76   /** the current state of the DFA */
77   private int yy_state;
78
79   /** the current lexical state */
80   private int yy_lexical_state = YYINITIAL;
81
82   /** this buffer contains the current text to be matched and is
83       the source of the yytext() string */

84   private char yy_buffer[] = new char[YY_BUFFERSIZE];
85
86   /** the textposition at the last accepting state */
87   private int yy_markedPos;
88
89   /** the textposition at the last state to be included in yytext */
90   private int yy_pushbackPos;
91
92   /** the current text position in the buffer */
93   private int yy_currentPos;
94
95   /** startRead marks the beginning of the yytext() string in the buffer */
96   private int yy_startRead;
97
98   /** endRead marks the last character in the buffer, that has been read
99       from input */

100   private int yy_endRead;
101
102   /** number of newlines encountered up to the start of the matched text */
103   private int yyline;
104
105   /** the number of characters up to the start of the matched text */
106   private int yychar;
107
108   /**
109    * the number of characters from the last newline up to the start of the
110    * matched text
111    */

112   private int yycolumn;
113
114   /**
115    * yy_atBOL == true <=> the scanner is currently at the beginning of a line
116    */

117   private boolean yy_atBOL = true;
118
119   /** yy_atEOF == true <=> the scanner is at the EOF */
120   private boolean yy_atEOF;
121
122   /* user code: */
123     private char lastToken[]=null;
124
125     private int escapeOffset = 0;
126     private ArrayList JavaDoc escapes = new ArrayList JavaDoc();
127     private int escapesIndex = -1;
128     private int nextEscapePosition = -1;
129     private int currentEscapeDispl = 0;
130
131     private char value() {
132         char r=0;
133         String JavaDoc token = yytext();
134
135         for (int k = token.length()-4; k < token.length(); k++) {
136             int c = token.charAt(k);
137             if (c >= 'a')
138                 c-= 'a'-10;
139             else if (c >= 'A')
140                 c-= 'A'-10;
141             else
142                 c-= '0';
143             r <<= 4;
144             r += c;
145         }
146         return r;
147     }
148
149     int convertPosition(int position) {
150         if (escapes.isEmpty())
151             return position;
152         for (;;) {
153             if (position <= nextEscapePosition)
154                 return position+currentEscapeDispl;
155             if (nextEscapePosition != -1)
156                 currentEscapeDispl=((Integer JavaDoc)escapes.get(++escapesIndex)).intValue();
157             if (escapes.size()<=escapesIndex+1) {
158                 nextEscapePosition = -1;
159                 return position+currentEscapeDispl;
160             }
161             nextEscapePosition=((Integer JavaDoc)escapes.get(++escapesIndex)).intValue();
162         }
163     }
164
165     public int read(char cbuf[], int off, int len) throws IOException {
166         int tokenLen;
167
168 // if ( !ready() ) return -1;
169
if (lastToken==null) {
170             lastToken = yylex();
171         }
172         tokenLen = lastToken.length;
173         if (tokenLen==0)
174             return -1;
175         if (len>=tokenLen) {
176             System.arraycopy(lastToken,0,cbuf,off,tokenLen);
177             lastToken=null;
178             return tokenLen;
179         }
180         char token[]=new char[lastToken.length-len];
181         System.arraycopy(lastToken,0,cbuf,off,len);
182         System.arraycopy(lastToken,len,token,0,token.length);
183         lastToken=token;
184         return len;
185     }
186
187     public boolean markSupported() {
188         return false;
189     }
190
191     public boolean ready() throws IOException {
192         return lastToken!=null || (!yy_atEOF && (yy_currentPos < yy_endRead || yy_reader.ready()));
193     }
194
195
196
197   /**
198    * Creates a new scanner
199    * There is also a java.io.InputStream version of this constructor.
200    *
201    * @param in the java.io.Reader to read input from.
202    */

203   UnicodeEscapes(java.io.Reader JavaDoc in) {
204     super(in);
205     this.yy_reader = in;
206   }
207
208   /**
209    * Creates a new scanner.
210    * There is also java.io.Reader version of this constructor.
211    *
212    * @param in the java.io.Inputstream to read input from.
213    */

214   UnicodeEscapes(java.io.InputStream JavaDoc in) {
215     this(new java.io.InputStreamReader JavaDoc(in));
216   }
217
218   /**
219    * Unpacks the compressed character translation table.
220    *
221    * @param packed the packed character translation table
222    * @return the unpacked character translation table
223    */

224   private static char [] yy_unpack_cmap(String JavaDoc packed) {
225     char [] map = new char[0x10000];
226     int i = 0; /* index in packed string */
227     int j = 0; /* index in unpacked array */
228     while (i < 26) {
229       int count = packed.charAt(i++);
230       char value = packed.charAt(i++);
231       do map[j++] = value; while (--count > 0);
232     }
233     return map;
234   }
235
236
237   /**
238    * Refills the input buffer.
239    *
240    * @return <code>false</code>, iff there was new input.
241    *
242    * @exception IOException if any I/O-Error occurs
243    */

244   private boolean yy_refill() throws java.io.IOException JavaDoc {
245
246     /* first: make room (if you can) */
247     if (yy_startRead > 0) {
248       System.arraycopy(yy_buffer, yy_startRead,
249                        yy_buffer, 0,
250                        yy_endRead-yy_startRead);
251
252       /* translate stored positions */
253       yy_endRead-= yy_startRead;
254       yy_currentPos-= yy_startRead;
255       yy_markedPos-= yy_startRead;
256       yy_pushbackPos-= yy_startRead;
257       yy_startRead = 0;
258     }
259
260     /* is the buffer big enough? */
261     if (yy_currentPos >= yy_buffer.length) {
262       /* if not: blow it up */
263       char newBuffer[] = new char[yy_currentPos*2];
264       System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length);
265       yy_buffer = newBuffer;
266     }
267
268     /* finally: fill the buffer with new input */
269     int numRead = yy_reader.read(yy_buffer, yy_endRead,
270                                             yy_buffer.length-yy_endRead);
271
272     if (numRead < 0) {
273       return true;
274     }
275     else {
276       yy_endRead+= numRead;
277       return false;
278     }
279   }
280
281
282   /**
283    * Closes the input stream.
284    */

285   final public void yyclose() throws java.io.IOException JavaDoc {
286     yy_atEOF = true; /* indicate end of file */
287     yy_endRead = yy_startRead; /* invalidate buffer */
288
289     if (yy_reader != null)
290       yy_reader.close();
291   }
292
293
294   /**
295    * Closes the current stream, and resets the
296    * scanner to read from a new input stream.
297    *
298    * All internal variables are reset, the old input stream
299    * <b>cannot</b> be reused (internal buffer is discarded and lost).
300    * Lexical state is set to <tt>YY_INITIAL</tt>.
301    *
302    * @param reader the new input stream
303    */

304   final public void yyreset(java.io.Reader JavaDoc reader) throws java.io.IOException JavaDoc {
305     yyclose();
306     yy_reader = reader;
307     yy_atBOL = true;
308     yy_atEOF = false;
309     yy_endRead = yy_startRead = 0;
310     yy_currentPos = yy_markedPos = yy_pushbackPos = 0;
311     yyline = yychar = yycolumn = 0;
312     yy_lexical_state = YYINITIAL;
313   }
314
315
316   /**
317    * Returns the current lexical state.
318    */

319   final public int yystate() {
320     return yy_lexical_state;
321   }
322
323
324   /**
325    * Enters a new lexical state
326    *
327    * @param newState the new lexical state
328    */

329   final public void yybegin(int newState) {
330     yy_lexical_state = newState;
331   }
332
333
334   /**
335    * Returns the text matched by the current regular expression.
336    */

337   final public String JavaDoc yytext() {
338     return new String JavaDoc( yy_buffer, yy_startRead, yy_markedPos-yy_startRead );
339   }
340
341
342   /**
343    * Returns the character at position <tt>pos</tt> from the
344    * matched text.
345    *
346    * It is equivalent to yytext().charAt(pos), but faster
347    *
348    * @param pos the position of the character to fetch.
349    * A value from 0 to yylength()-1.
350    *
351    * @return the character at position pos
352    */

353   final public char yycharat(int pos) {
354     return yy_buffer[yy_startRead+pos];
355   }
356
357
358   /**
359    * Returns the length of the matched text region.
360    */

361   final public int yylength() {
362     return yy_markedPos-yy_startRead;
363   }
364
365
366   /**
367    * Reports an error that occured while scanning.
368    *
369    * In a wellformed scanner (no or only correct usage of
370    * yypushback(int) and a match-all fallback rule) this method
371    * will only be called with things that "Can't Possibly Happen".
372    * If this method is called, something is seriously wrong
373    * (e.g. a JFlex bug producing a faulty scanner etc.).
374    *
375    * Usual syntax/scanner level error handling should be done
376    * in error fallback rules.
377    *
378    * @param errorCode the code of the errormessage to display
379    */

380   private void yy_ScanError(int errorCode) {
381     String JavaDoc message;
382     try {
383       message = YY_ERROR_MSG[errorCode];
384     }
385     catch (ArrayIndexOutOfBoundsException JavaDoc e) {
386       message = YY_ERROR_MSG[YY_UNKNOWN_ERROR];
387     }
388
389     throw new Error JavaDoc(message);
390   }
391
392
393   /**
394    * Pushes the specified amount of characters back into the input stream.
395    *
396    * They will be read again by then next call of the scanning method
397    *
398    * @param number the number of characters to be read again.
399    * This number must not be greater than yylength()!
400    */

401   private void yypushback(int number) {
402     if ( number > yylength() )
403       yy_ScanError(YY_PUSHBACK_2BIG);
404
405     yy_markedPos -= number;
406   }
407
408
409   /**
410    * Resumes scanning until the next regular expression is matched,
411    * the end of input is encountered or an I/O-Error occurs.
412    *
413    * @return the next token
414    * @exception IOException if any I/O-Error occurs
415    */

416   public char[] yylex() throws java.io.IOException JavaDoc {
417     int yy_input;
418     int yy_action;
419
420     // cached fields:
421
int yy_currentPos_l;
422     int yy_startRead_l;
423     int yy_markedPos_l;
424     int yy_endRead_l = yy_endRead;
425     char [] yy_buffer_l = yy_buffer;
426     char [] yycmap_l = yycmap;
427
428
429     while (true) {
430       yy_markedPos_l = yy_markedPos;
431
432       yychar+= yy_markedPos_l-yy_startRead;
433
434       yy_action = -1;
435
436       yy_startRead_l = yy_currentPos_l = yy_currentPos =
437                        yy_startRead = yy_markedPos_l;
438
439       yy_state = yy_lexical_state;
440
441
442       yy_forAction: {
443         while (true) {
444
445           if (yy_currentPos_l < yy_endRead_l)
446             yy_input = yy_buffer_l[yy_currentPos_l++];
447           else if (yy_atEOF) {
448             yy_input = YYEOF;
449             break yy_forAction;
450           }
451           else {
452             // store back cached positions
453
yy_currentPos = yy_currentPos_l;
454             yy_markedPos = yy_markedPos_l;
455             boolean eof = yy_refill();
456             // get translated positions and possibly new buffer
457
yy_currentPos_l = yy_currentPos;
458             yy_markedPos_l = yy_markedPos;
459             yy_buffer_l = yy_buffer;
460             yy_endRead_l = yy_endRead;
461             if (eof) {
462               yy_input = YYEOF;
463               break yy_forAction;
464             }
465             else {
466               yy_input = yy_buffer_l[yy_currentPos_l++];
467             }
468           }
469           yy_input = yycmap_l[yy_input];
470
471           boolean yy_isFinal = false;
472           boolean yy_noLookAhead = false;
473
474           yy_forNext: { switch (yy_state) {
475             case 0:
476               switch (yy_input) {
477                 case 2: yy_isFinal = true; yy_state = 3; break yy_forNext;
478                 default: yy_isFinal = true; yy_state = 2; break yy_forNext;
479               }
480
481             case 1:
482               switch (yy_input) {
483                 case 1: yy_isFinal = true; yy_state = 5; break yy_forNext;
484                 case 3: yy_isFinal = true; yy_state = 6; break yy_forNext;
485                 default: yy_isFinal = true; yy_noLookAhead = true; yy_state = 4; break yy_forNext;
486               }
487
488             case 2:
489               switch (yy_input) {
490                 case 2: break yy_forAction;
491                 default: yy_isFinal = true; yy_state = 2; break yy_forNext;
492               }
493
494             case 3:
495               switch (yy_input) {
496                 case 2: yy_isFinal = true; yy_state = 7; break yy_forNext;
497                 case 3: yy_isFinal = true; yy_noLookAhead = true; yy_state = 8; break yy_forNext;
498                 default: break yy_forAction;
499               }
500
501             case 5:
502               switch (yy_input) {
503                 case 1: yy_state = 9; break yy_forNext;
504                 default: break yy_forAction;
505               }
506
507             case 6:
508               switch (yy_input) {
509                 case 1: yy_state = 10; break yy_forNext;
510                 case 3: yy_state = 11; break yy_forNext;
511                 default: break yy_forAction;
512               }
513
514             case 7:
515               switch (yy_input) {
516                 case 2: yy_isFinal = true; yy_state = 3; break yy_forNext;
517                 default: break yy_forAction;
518               }
519
520             case 9:
521               switch (yy_input) {
522                 case 1: yy_state = 12; break yy_forNext;
523                 default: break yy_forAction;
524               }
525
526             case 10:
527               switch (yy_input) {
528                 case 1: yy_state = 9; break yy_forNext;
529                 default: break yy_forAction;
530               }
531
532             case 11:
533               switch (yy_input) {
534                 case 1: yy_state = 10; break yy_forNext;
535                 case 3: yy_state = 11; break yy_forNext;
536                 default: break yy_forAction;
537               }
538
539             case 12:
540               switch (yy_input) {
541                 case 1: yy_isFinal = true; yy_noLookAhead = true; yy_state = 13; break yy_forNext;
542                 default: break yy_forAction;
543               }
544
545             default:
546               yy_ScanError(YY_ILLEGAL_STATE);
547               break;
548           } }
549
550           if ( yy_isFinal ) {
551             yy_action = yy_state;
552             yy_markedPos_l = yy_currentPos_l;
553             if ( yy_noLookAhead ) break yy_forAction;
554           }
555
556         }
557       }
558
559       // store back cached position
560
yy_markedPos = yy_markedPos_l;
561
562       switch (yy_action) {
563
564         case 13:
565           { yybegin(YYINITIAL);
566                        escapeOffset+=yylength()-1;
567                        escapes.add(new Integer JavaDoc(escapeOffset));
568                        return new char[]{value()};
569                       }
570         case 15: break;
571         case 4:
572         case 5:
573         case 6:
574           { throw new Error JavaDoc("incorrect Unicode escape"); }
575         case 16: break;
576         case 8:
577           { yybegin(DIGITS);
578                   escapes.add(new Integer JavaDoc(yychar-escapeOffset));
579                   escapeOffset+=yylength();
580                  }
581         case 17: break;
582         case 3:
583         case 7:
584           { return yytext().toCharArray(); }
585         case 18: break;
586         case 2:
587           { return yytext().toCharArray(); }
588         case 19: break;
589         default:
590           if (yy_input == YYEOF && yy_startRead == yy_currentPos) {
591             yy_atEOF = true;
592             switch (yy_lexical_state) {
593             case DIGITS:
594               { throw new Error JavaDoc("EOF in Unicode escape"); }
595             case 15: break;
596             case YYINITIAL:
597               { return new char[0]; }
598             case 16: break;
599             default:
600             return null;
601             }
602           }
603           else {
604             yy_ScanError(YY_NO_MATCH);
605           }
606       }
607     }
608   }
609
610
611 }
612
Popular Tags