alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/* The following code was generated by JFlex 1.3.5 on 8/30/02 3:00 PM */

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.lib.java.parser;

import java.io.*;
import java.util.ArrayList;


/**
 * This class is a scanner generated by 
 * JFlex 1.3.5
 * on 8/30/02 3:00 PM from the specification file
 * file:/home/th125165/Projects/Source/netbeans-cvs/nb_all/java_meta_2/libsrc/org/netbeans/lib/java/parser/unicode.l
 */
final class UnicodeEscapes extends FilterReader {

  /** This character denotes the end of file */
  final public static int YYEOF = -1;

  /** initial size of the lookahead buffer */
  final private static int YY_BUFFERSIZE = 16384;

  /** lexical states */
  final public static int DIGITS = 1;
  final public static int YYINITIAL = 0;

  /** 
   * Translates characters to character classes
   */
  final private static String yycmap_packed = 
    "\12\0\1\0\45\0\12\1\7\0\6\1\25\0\1\2\4\0\6\1"+
    "\16\0\1\3\uff8a\0";

  /** 
   * Translates characters to character classes
   */
  final private static char [] yycmap = yy_unpack_cmap(yycmap_packed);


  /* error codes */
  final private static int YY_UNKNOWN_ERROR = 0;
  final private static int YY_ILLEGAL_STATE = 1;
  final private static int YY_NO_MATCH = 2;
  final private static int YY_PUSHBACK_2BIG = 3;

  /* error messages for the codes above */
  final private static String YY_ERROR_MSG[] = {
    "Unkown internal scanner error",
    "Internal error: unknown state",
    "Error: could not match input",
    "Error: pushback value was too large"
  };

  /** the input device */
  private java.io.Reader yy_reader;

  /** the current state of the DFA */
  private int yy_state;

  /** the current lexical state */
  private int yy_lexical_state = YYINITIAL;

  /** this buffer contains the current text to be matched and is
      the source of the yytext() string */
  private char yy_buffer[] = new char[YY_BUFFERSIZE];

  /** the textposition at the last accepting state */
  private int yy_markedPos;

  /** the textposition at the last state to be included in yytext */
  private int yy_pushbackPos;

  /** the current text position in the buffer */
  private int yy_currentPos;

  /** startRead marks the beginning of the yytext() string in the buffer */
  private int yy_startRead;

  /** endRead marks the last character in the buffer, that has been read
      from input */
  private int yy_endRead;

  /** number of newlines encountered up to the start of the matched text */
  private int yyline;

  /** the number of characters up to the start of the matched text */
  private int yychar;

  /**
   * the number of characters from the last newline up to the start of the 
   * matched text
   */
  private int yycolumn; 

  /** 
   * yy_atBOL == true <=> the scanner is currently at the beginning of a line
   */
  private boolean yy_atBOL = true;

  /** yy_atEOF == true <=> the scanner is at the EOF */
  private boolean yy_atEOF;

  /* user code: */
    private char lastToken[]=null;

    private int escapeOffset = 0;
    private ArrayList escapes = new ArrayList(); 
    private int escapesIndex = -1;
    private int nextEscapePosition = -1;
    private int currentEscapeDispl = 0;

    private char value() {
        char r=0;
        String token = yytext();

        for (int k = token.length()-4; k < token.length(); k++) {
            int c = token.charAt(k);
            if (c >= 'a') 
                c-= 'a'-10;
            else if (c >= 'A')
                c-= 'A'-10;
            else
                c-= '0';
            r <<= 4;
            r += c;
	    }
        return r;
    }

    int convertPosition(int position) {
        if (escapes.isEmpty())
            return position;
        for (;;) {
            if (position <= nextEscapePosition)
                return position+currentEscapeDispl;
            if (nextEscapePosition != -1)
                currentEscapeDispl=((Integer)escapes.get(++escapesIndex)).intValue();
            if (escapes.size()<=escapesIndex+1) {
                nextEscapePosition = -1;
                return position+currentEscapeDispl;
            }
            nextEscapePosition=((Integer)escapes.get(++escapesIndex)).intValue();
        }        
    }

    public int read(char cbuf[], int off, int len) throws IOException {
        int tokenLen;

//        if ( !ready() ) return -1;
        if (lastToken==null) {    
            lastToken = yylex();
        }
        tokenLen = lastToken.length;
        if (tokenLen==0)
            return -1;
        if (len>=tokenLen) {
            System.arraycopy(lastToken,0,cbuf,off,tokenLen);
            lastToken=null;
            return tokenLen;
        }
        char token[]=new char[lastToken.length-len];
        System.arraycopy(lastToken,0,cbuf,off,len);
        System.arraycopy(lastToken,len,token,0,token.length);
        lastToken=token;
        return len;
    }

    public boolean markSupported() { 
        return false; 
    }

    public boolean ready() throws IOException {
        return lastToken!=null || (!yy_atEOF && (yy_currentPos < yy_endRead || yy_reader.ready()));
    }



  /**
   * Creates a new scanner
   * There is also a java.io.InputStream version of this constructor.
   *
   * @param   in  the java.io.Reader to read input from.
   */
  UnicodeEscapes(java.io.Reader in) {
    super(in);
    this.yy_reader = in;
  }

  /**
   * Creates a new scanner.
   * There is also java.io.Reader version of this constructor.
   *
   * @param   in  the java.io.Inputstream to read input from.
   */
  UnicodeEscapes(java.io.InputStream in) {
    this(new java.io.InputStreamReader(in));
  }

  /** 
   * Unpacks the compressed character translation table.
   *
   * @param packed   the packed character translation table
   * @return         the unpacked character translation table
   */
  private static char [] yy_unpack_cmap(String packed) {
    char [] map = new char[0x10000];
    int i = 0;  /* index in packed string  */
    int j = 0;  /* index in unpacked array */
    while (i < 26) {
      int  count = packed.charAt(i++);
      char value = packed.charAt(i++);
      do map[j++] = value; while (--count > 0);
    }
    return map;
  }


  /**
   * Refills the input buffer.
   *
   * @return      false, iff there was new input.
   * 
   * @exception   IOException  if any I/O-Error occurs
   */
  private boolean yy_refill() throws java.io.IOException {

    /* first: make room (if you can) */
    if (yy_startRead > 0) {
      System.arraycopy(yy_buffer, yy_startRead, 
                       yy_buffer, 0, 
                       yy_endRead-yy_startRead);

      /* translate stored positions */
      yy_endRead-= yy_startRead;
      yy_currentPos-= yy_startRead;
      yy_markedPos-= yy_startRead;
      yy_pushbackPos-= yy_startRead;
      yy_startRead = 0;
    }

    /* is the buffer big enough? */
    if (yy_currentPos >= yy_buffer.length) {
      /* if not: blow it up */
      char newBuffer[] = new char[yy_currentPos*2];
      System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length);
      yy_buffer = newBuffer;
    }

    /* finally: fill the buffer with new input */
    int numRead = yy_reader.read(yy_buffer, yy_endRead, 
                                            yy_buffer.length-yy_endRead);

    if (numRead < 0) {
      return true;
    }
    else {
      yy_endRead+= numRead;  
      return false;
    }
  }


  /**
   * Closes the input stream.
   */
  final public void yyclose() throws java.io.IOException {
    yy_atEOF = true;            /* indicate end of file */
    yy_endRead = yy_startRead;  /* invalidate buffer    */

    if (yy_reader != null)
      yy_reader.close();
  }


  /**
   * Closes the current stream, and resets the
   * scanner to read from a new input stream.
   *
   * All internal variables are reset, the old input stream 
   * cannot be reused (internal buffer is discarded and lost).
   * Lexical state is set to YY_INITIAL.
   *
   * @param reader   the new input stream 
   */
  final public void yyreset(java.io.Reader reader) throws java.io.IOException {
    yyclose();
    yy_reader = reader;
    yy_atBOL  = true;
    yy_atEOF  = false;
    yy_endRead = yy_startRead = 0;
    yy_currentPos = yy_markedPos = yy_pushbackPos = 0;
    yyline = yychar = yycolumn = 0;
    yy_lexical_state = YYINITIAL;
  }


  /**
   * Returns the current lexical state.
   */
  final public int yystate() {
    return yy_lexical_state;
  }


  /**
   * Enters a new lexical state
   *
   * @param newState the new lexical state
   */
  final public void yybegin(int newState) {
    yy_lexical_state = newState;
  }


  /**
   * Returns the text matched by the current regular expression.
   */
  final public String yytext() {
    return new String( yy_buffer, yy_startRead, yy_markedPos-yy_startRead );
  }


  /**
   * Returns the character at position pos from the 
   * matched text. 
   * 
   * It is equivalent to yytext().charAt(pos), but faster
   *
   * @param pos the position of the character to fetch. 
   *            A value from 0 to yylength()-1.
   *
   * @return the character at position pos
   */
  final public char yycharat(int pos) {
    return yy_buffer[yy_startRead+pos];
  }


  /**
   * Returns the length of the matched text region.
   */
  final public int yylength() {
    return yy_markedPos-yy_startRead;
  }


  /**
   * Reports an error that occured while scanning.
   *
   * In a wellformed scanner (no or only correct usage of 
   * yypushback(int) and a match-all fallback rule) this method 
   * will only be called with things that "Can't Possibly Happen".
   * If this method is called, something is seriously wrong
   * (e.g. a JFlex bug producing a faulty scanner etc.).
   *
   * Usual syntax/scanner level error handling should be done
   * in error fallback rules.
   *
   * @param   errorCode  the code of the errormessage to display
   */
  private void yy_ScanError(int errorCode) {
    String message;
    try {
      message = YY_ERROR_MSG[errorCode];
    }
    catch (ArrayIndexOutOfBoundsException e) {
      message = YY_ERROR_MSG[YY_UNKNOWN_ERROR];
    }

    throw new Error(message);
  } 


  /**
   * Pushes the specified amount of characters back into the input stream.
   *
   * They will be read again by then next call of the scanning method
   *
   * @param number  the number of characters to be read again.
   *                This number must not be greater than yylength()!
   */
  private void yypushback(int number)  {
    if ( number > yylength() )
      yy_ScanError(YY_PUSHBACK_2BIG);

    yy_markedPos -= number;
  }


  /**
   * Resumes scanning until the next regular expression is matched,
   * the end of input is encountered or an I/O-Error occurs.
   *
   * @return      the next token
   * @exception   IOException  if any I/O-Error occurs
   */
  public char[] yylex() throws java.io.IOException {
    int yy_input;
    int yy_action;

    // cached fields:
    int yy_currentPos_l;
    int yy_startRead_l;
    int yy_markedPos_l;
    int yy_endRead_l = yy_endRead;
    char [] yy_buffer_l = yy_buffer;
    char [] yycmap_l = yycmap;


    while (true) {
      yy_markedPos_l = yy_markedPos;

      yychar+= yy_markedPos_l-yy_startRead;

      yy_action = -1;

      yy_startRead_l = yy_currentPos_l = yy_currentPos = 
                       yy_startRead = yy_markedPos_l;

      yy_state = yy_lexical_state;


      yy_forAction: {
        while (true) {

          if (yy_currentPos_l < yy_endRead_l)
            yy_input = yy_buffer_l[yy_currentPos_l++];
          else if (yy_atEOF) {
            yy_input = YYEOF;
            break yy_forAction;
          }
          else {
            // store back cached positions
            yy_currentPos  = yy_currentPos_l;
            yy_markedPos   = yy_markedPos_l;
            boolean eof = yy_refill();
            // get translated positions and possibly new buffer
            yy_currentPos_l  = yy_currentPos;
            yy_markedPos_l   = yy_markedPos;
            yy_buffer_l      = yy_buffer;
            yy_endRead_l     = yy_endRead;
            if (eof) {
              yy_input = YYEOF;
              break yy_forAction;
            }
            else {
              yy_input = yy_buffer_l[yy_currentPos_l++];
            }
          }
          yy_input = yycmap_l[yy_input];

          boolean yy_isFinal = false;
          boolean yy_noLookAhead = false;

          yy_forNext: { switch (yy_state) {
            case 0:
              switch (yy_input) {
                case 2: yy_isFinal = true; yy_state = 3; break yy_forNext;
                default: yy_isFinal = true; yy_state = 2; break yy_forNext;
              }

            case 1:
              switch (yy_input) {
                case 1: yy_isFinal = true; yy_state = 5; break yy_forNext;
                case 3: yy_isFinal = true; yy_state = 6; break yy_forNext;
                default: yy_isFinal = true; yy_noLookAhead = true; yy_state = 4; break yy_forNext;
              }

            case 2:
              switch (yy_input) {
                case 2: break yy_forAction;
                default: yy_isFinal = true; yy_state = 2; break yy_forNext;
              }

            case 3:
              switch (yy_input) {
                case 2: yy_isFinal = true; yy_state = 7; break yy_forNext;
                case 3: yy_isFinal = true; yy_noLookAhead = true; yy_state = 8; break yy_forNext;
                default: break yy_forAction;
              }

            case 5:
              switch (yy_input) {
                case 1: yy_state = 9; break yy_forNext;
                default: break yy_forAction;
              }

            case 6:
              switch (yy_input) {
                case 1: yy_state = 10; break yy_forNext;
                case 3: yy_state = 11; break yy_forNext;
                default: break yy_forAction;
              }

            case 7:
              switch (yy_input) {
                case 2: yy_isFinal = true; yy_state = 3; break yy_forNext;
                default: break yy_forAction;
              }

            case 9:
              switch (yy_input) {
                case 1: yy_state = 12; break yy_forNext;
                default: break yy_forAction;
              }

            case 10:
              switch (yy_input) {
                case 1: yy_state = 9; break yy_forNext;
                default: break yy_forAction;
              }

            case 11:
              switch (yy_input) {
                case 1: yy_state = 10; break yy_forNext;
                case 3: yy_state = 11; break yy_forNext;
                default: break yy_forAction;
              }

            case 12:
              switch (yy_input) {
                case 1: yy_isFinal = true; yy_noLookAhead = true; yy_state = 13; break yy_forNext;
                default: break yy_forAction;
              }

            default:
              yy_ScanError(YY_ILLEGAL_STATE);
              break;
          } }

          if ( yy_isFinal ) {
            yy_action = yy_state; 
            yy_markedPos_l = yy_currentPos_l; 
            if ( yy_noLookAhead ) break yy_forAction;
          }

        }
      }

      // store back cached position
      yy_markedPos = yy_markedPos_l;

      switch (yy_action) {

        case 13: 
          {  yybegin(YYINITIAL);
                       escapeOffset+=yylength()-1;
                       escapes.add(new Integer(escapeOffset));
                       return new char[]{value()};
                      }
        case 15: break;
        case 4: 
        case 5: 
        case 6: 
          {  throw new Error("incorrect Unicode escape");  }
        case 16: break;
        case 8: 
          {  yybegin(DIGITS); 
                  escapes.add(new Integer(yychar-escapeOffset));
                  escapeOffset+=yylength();
                 }
        case 17: break;
        case 3: 
        case 7: 
          {  return yytext().toCharArray();  }
        case 18: break;
        case 2: 
          {  return yytext().toCharArray();  }
        case 19: break;
        default: 
          if (yy_input == YYEOF && yy_startRead == yy_currentPos) {
            yy_atEOF = true;
            switch (yy_lexical_state) {
            case DIGITS:
              {  throw new Error("EOF in Unicode escape");  }
            case 15: break;
            case YYINITIAL:
              {  return new char[0];  }
            case 16: break;
            default:
            return null;
            }
          } 
          else {
            yy_ScanError(YY_NO_MATCH);
          }
      }
    }
  }


}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.