Gets the next token from a tokenizer. @param wantWhitespace If true, leading whitespace will be returned as a token. @param wantComment If true, comments are returned as tokens. @return The next token in the stream. @throws TextParseException The input was invalid. @throws IOException An I/O error o
(boolean wantWhitespace, boolean wantComment)
| 231 | * @throws IOException An I/O error occurred. |
| 232 | */ |
| 233 | public Token |
| 234 | get(boolean wantWhitespace, boolean wantComment) throws IOException { |
| 235 | int type; |
| 236 | int c; |
| 237 | |
| 238 | if (ungottenToken) { |
| 239 | ungottenToken = false; |
| 240 | if (current.type == WHITESPACE) { |
| 241 | if (wantWhitespace) |
| 242 | return current; |
| 243 | } else if (current.type == COMMENT) { |
| 244 | if (wantComment) |
| 245 | return current; |
| 246 | } else { |
| 247 | if (current.type == EOL) |
| 248 | line++; |
| 249 | return current; |
| 250 | } |
| 251 | } |
| 252 | int skipped = skipWhitespace(); |
| 253 | if (skipped > 0 && wantWhitespace) |
| 254 | return current.set(WHITESPACE, null); |
| 255 | type = IDENTIFIER; |
| 256 | sb.setLength(0); |
| 257 | while (true) { |
| 258 | c = getChar(); |
| 259 | if (c == -1 || delimiters.indexOf(c) != -1) { |
| 260 | if (c == -1) { |
| 261 | if (quoting) |
| 262 | throw exception("EOF in " + |
| 263 | "quoted string"); |
| 264 | else if (sb.length() == 0) |
| 265 | return current.set(EOF, null); |
| 266 | else |
| 267 | return current.set(type, sb); |
| 268 | } |
| 269 | if (sb.length() == 0 && type != QUOTED_STRING) { |
| 270 | if (c == '(') { |
| 271 | multiline++; |
| 272 | skipWhitespace(); |
| 273 | continue; |
| 274 | } else if (c == ')') { |
| 275 | if (multiline <= 0) |
| 276 | throw exception("invalid " + |
| 277 | "close " + |
| 278 | "parenthesis"); |
| 279 | multiline--; |
| 280 | skipWhitespace(); |
| 281 | continue; |
| 282 | } else if (c == '"') { |
| 283 | if (!quoting) { |
| 284 | quoting = true; |
| 285 | delimiters = quotes; |
| 286 | type = QUOTED_STRING; |
| 287 | } else { |
| 288 | quoting = false; |
| 289 | delimiters = delim; |
| 290 | skipWhitespace(); |