Package anvil.java.io

Examples of anvil.java.io.GenericInputStream


  {
    super(null, null);
    _envelope = envelope;
    _namespace = namespace;
    _url = url;
    _input = new GenericInputStream(content);
  }
View Full Code Here


  private GenericInputStream _input;
 
 
  public AnyInputStream(InputStream input)
  {
    _input = new GenericInputStream(input);
  }
View Full Code Here

  private Token _previous = null;
 

  public Tokenizer(byte[] array)
  {
    _input = new GenericInputStream(array);
  }
View Full Code Here

  }


  public Tokenizer(InputStream input)
  {
    _input = new GenericInputStream(input);
  }
View Full Code Here

  }


  public Tokenizer(String code)
  {
    _input = new GenericInputStream(new ByteArrayInputStream(
      anvil.util.Conversions.getBytes(code)));
  }
View Full Code Here

  }


  private Token skipToEndOfComment() throws IOException
  {
    GenericInputStream input = _input;
    int ch;
    StringBuffer image = _image;
    image.setLength(0);
    image.append("/*");
    boolean star = false;
    for(;;) {
      ch = input.read();
      if (ch == -1) {
        _parser.error(_parser.toLocation(input.getLineNumber(),
           input.getColumnNumber()), "Unexcepted end of comment");
        break;
      } else if (ch == '*') {
        star = true;
      } else if (ch == '/') {
        if (star) {
          image.append('/');
          break;
        } else {
          star = false;
        }
      } else {
        star = false;
      }
      image.append((char)ch);
    }
    String s = image.toString();
    Token c = createToken((s.length() > 4 && s.startsWith("/**")) ?
      DOC_COMMENT : COMMENT);
    c.image = s;
    c.endLine = input.getLineNumber();
    c.endColumn = input.getColumnNumber() -1;
    return c;
  }
View Full Code Here

  private Token readSymbol(int ch) throws IOException
  {
    _allowPattern = false;
    Token token = createToken(SYMBOL);
    GenericInputStream input = _input;
    StringBuffer image = _image;
    int line;
    int column;
    boolean doLookup = (ch > 0);

    image.setLength(0);
    if (doLookup) {
      image.append((char)ch);
    } else {
      token.beginColumn++;
    }
   
    for(;;) {
      line = input.getLineNumber();
      column = input.getColumnNumber();
      ch = input.read();
      if (ch == -1) {
        break;
      } else if (ch == '$') {
        backup(ch, line, column);
        break;
      } else if (Character.isJavaIdentifierPart((char)ch)) {
        image.append((char)ch);
      } else {
        backup(ch, line, column);
        break;
      }
    }

    token.image = image.toString();
   
    if (token.image.length() == 0) {
      _parser.error(_parser.toLocation(input.getLineNumber(),
         input.getColumnNumber()), "Empty symbols not allowed");
    } else {
      if (doLookup) {
        Integer kind = (Integer)_symbols.get(token.image);
        if (kind != null) {
          token.kind = kind.intValue();
View Full Code Here

  }


  private Token readLongString(Token token) throws IOException
  {
    GenericInputStream input = _input;
    StringBuffer image = _image;
    boolean escaped = false;
    int state = 0;
    int line;
    int column;
    int ch;
   
    image.setLength(0);
    image.append('"');

    finished:
    for(;;) {
      line = input.getLineNumber();
      column = input.getColumnNumber();
      ch = input.read();
      switch(ch) {
      case -1:
        if (state > 0) {
          while(state-->0) {
            image.append('"');
View Full Code Here

  private Token readString(int stringquote) throws IOException
  {
    _allowPattern = false;
    Token token = createToken(STRING_LITERAL);
    GenericInputStream input = _input;
    StringBuffer image = _image;
    int line;
    int column;
    int quote = stringquote;
    int ch = stringquote;
    boolean escaped = false;

    image.setLength(0);
    image.append((char)ch);

    finished:
    for(;;) {
      line = input.getLineNumber();
      column = input.getColumnNumber();
      switch(ch = input.read()) {
      case -1:
        _parser.error(_parser.toLocation(line, column),
          "Unexcepted end of string literal");
        break finished;

      case '\\':
        escaped = !escaped;
        image.append('\\');
        break;

      case '\n':
      case '\r':
        _parser.error(_parser.toLocation(line, column),
          "String literal cannot span over lines");
        break finished;

      default:
        image.append((char)ch);
        if (!escaped) {
          if (ch == quote) {
            break finished;
          }
        }
        escaped = false;
        break;
      }
    }
    String img = image.toString();
    if (img.equals("\"\"")) {
      ch = input.read();
      if (ch == '"') {
        return readLongString(token);
      } else {
        _backup = ch;
      }
View Full Code Here

  private Token readNumber(int ch) throws IOException
  {
    _allowPattern = false;
    Token token = createToken();
    GenericInputStream input = _input;
    StringBuffer image = _image;
    int line;
    int column;
    int state;
    int kind = INTEGER_LITERAL;

    image.setLength(0);
    image.append((char)ch);
    if (ch == '0') {
      state = STATE_START;
    } else {
      state = STATE_DECIMAL;
    }
   
    finished:
    for(;;) {
      line = input.getLineNumber();
      column = input.getColumnNumber();
      ch = input.read();
      if (ch == -1) {
        break;
      }
      switch(state) {
      case STATE_START:
        switch(ch) {
        case 'x':
        case 'X':
          state = STATE_HEX;
          break;

        case 'b':
        case 'B':
          state = STATE_BINARY;
          break;

        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
          state = STATE_DECIMAL;
          break;

        case '.':
          state = STATE_FRACTION_START;
          kind = FLOATING_POINT_LITERAL;
          break;

        default:
          break finished;
        }
        break;

      case STATE_DECIMAL:
        switch(ch) {
        case '.':
          state = STATE_FRACTION_START;
          kind = FLOATING_POINT_LITERAL;
          break;

        case 'e':
        case 'E':
          state = STATE_EXPONENT_START;
          kind = FLOATING_POINT_LITERAL;
          break;

        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
          break;

        default:
          break finished;
        }
        break;

      case STATE_HEX:
        switch(ch) {
        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
        case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
        case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
          break;

        default:
          if (Character.isJavaIdentifierPart((char)ch)) {
            _parser.error(_parser.toLocation(line, column),
              "Invalid hexadecimal number");
          }
          break finished;
        }
        break;

      case STATE_BINARY:
        switch(ch) {
        case '0': case '1':
          break;

        default:
          if (Character.isJavaIdentifierPart((char)ch)) {
            _parser.error(_parser.toLocation(line, column),
              "Invalid binary number");
          }
          break finished;
        }
        break;

      case STATE_FRACTION_START:
        if (ch == '.') {
          Token range = new Token();
          range.kind = RANGE;
          range.image = "..";
          range.beginLine = line;
          range.beginColumn = column - 1;
          range.endLine = line;
          range.endColumn = column;
          token.next = range;

          line = input.getLineNumber();
          column = input.getColumnNumber();         
          ch = input.read();
         
          kind = INTEGER_LITERAL;
          image.setLength(image.length() - 1);
          break finished;
         
View Full Code Here

TOP

Related Classes of anvil.java.io.GenericInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.