/** * Peeks a non-whitespace character and returns it. The only difference * between this and {@code readChar} is that this doesn't consume the char. */ public char peekChar() { skipWhitespace(true); if (pos == data.length) throw unexpected("unexpected end of file"); return data[pos]; }
/** * Like {@link #skipWhitespace}, but this returns a string containing all * comment text. By convention, comments before a declaration document that * declaration. */ public String readDocumentation() { String result = null; while (true) { skipWhitespace(false); if (pos == data.length || data[pos] != '/') { return result != null ? result : ""; } String comment = readComment(); result = (result == null) ? comment : (result + "\n" + comment); } }
/** Reads a non-empty word and returns it. */ public String readWord() { skipWhitespace(true); int start = pos; while (pos < data.length) { char c = data[pos]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_') || (c == '-') || (c == '.')) { pos++; } else { break; } } if (start == pos) { throw unexpected("expected a word"); } return new String(data, start, pos - start); }
/** Reads a quoted or unquoted string and returns it. */ public String readString() { skipWhitespace(true); char c = peekChar(); return c == '"' || c == '\'' ? readQuotedString() : readWord(); }
/** * Peeks a non-whitespace character and returns it. The only difference * between this and {@code readChar} is that this doesn't consume the char. */ public char peekChar() { skipWhitespace(true); if (pos == data.length) throw unexpected("unexpected end of file"); return data[pos]; }
/** * Like {@link #skipWhitespace}, but this returns a string containing all * comment text. By convention, comments before a declaration document that * declaration. */ public String readDocumentation() { String result = null; while (true) { skipWhitespace(false); if (pos == data.length || data[pos] != '/') { return result != null ? result : ""; } String comment = readComment(); result = (result == null) ? comment : (result + "\n" + comment); } }
/** Reads a non-empty word and returns it. */ public String readWord() { skipWhitespace(true); int start = pos; while (pos < data.length) { char c = data[pos]; if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_') || (c == '-') || (c == '.')) { pos++; } else { break; } } if (start == pos) { throw unexpected("expected a word"); } return new String(data, start, pos - start); }
/** Reads a quoted or unquoted string and returns it. */ public String readString() { skipWhitespace(true); char c = peekChar(); return c == '"' || c == '\'' ? readQuotedString() : readWord(); }