Example #1
0
  /**
   * skip space and tabulation and comment
   *
   * @return true if success, false if end of file
   */
  protected boolean skipInvalid() throws IOException {
    if (strLine == null) return false;

    boolean ret = false;
    int emtyLines = 0;
    CommentBlock cb = null;
    out:
    while (true) {
      // read until not empty line
      while (column >= strLine.length()) {
        strLine = stream.readLine();
        if (strLine == null) break out; // end of file
        column = 0;
        line++;
        if (line > 1) emtyLines++;
      }

      // check comment
      if (column < (strLine.length() - 1)
          && strLine.charAt(column) == '/'
          && (strLine.charAt(column + 1) == '/' || strLine.charAt(column + 1) == '*')) {
        if (strLine.charAt(column + 1) == '/') {
          // line comment
          if (!parseSymbol) {
            if (cb == null) {
              cb = new CommentBlock(line);
            }

            // for(int i =0; i < emtyLines; i++) {
            if (emtyLines > 0) {
              cb.commentLines.add(""); // add empty lines as comment
            }
            emtyLines = 0;
            cb.commentLines.add(strLine.substring(column));
          }
          strLine = stream.readLine();
          if (strLine == null) break out; // read end of file
          column = -1;
          line++;
        } else {
          // block comment
          while (true) {
            if (!parseSymbol) {
              if (cb == null) {
                cb = new CommentBlock(line);
              }

              emtyLines = 0;
              cb.commentLines.add(strLine.substring(column));
            }

            column = strLine.indexOf("*/");
            if (column >= 0) {
              column += 2; // skip comment end
              break;
            }

            strLine = stream.readLine();
            if (strLine == null) break out; // read end of file
            column = 0;
            line++;
          }
        }
      } else if (lastToken != null
          && lastToken.kind == SEMICOLON
          && strLine.charAt(column) == ';') {
        continue; // ignore several continuous semicolon
      } else if (!Character.isWhitespace(strLine.charAt(column))) {
        ret = true;
        break; // break when not white space character
      }

      column++;
    }

    if (cb != null) {
      // for(int i =0; i < emtyLines; i++) {
      if (emtyLines > 0) {
        cb.commentLines.add(""); // add empty lines as comment
      }
      cb.endLine = line - 1;
      comments.add(cb);
    }
    return ret;
  }