* @param {boolean} convertValues * @return {!{type: TokenType_Enum, value: *, index: number}}
(convertValues)
| 1274 | * @return {!{type: TokenType_Enum, value: *, index: number}} |
| 1275 | */ |
| 1276 | next_(convertValues) { |
| 1277 | let newIndex = this.index_ + 1; |
| 1278 | if (newIndex >= this.str_.length) { |
| 1279 | return {type: TokenType_Enum.EOF, index: this.index_}; |
| 1280 | } |
| 1281 | |
| 1282 | let c = this.str_.charAt(newIndex); |
| 1283 | |
| 1284 | // Whitespace: standard set. |
| 1285 | if (WHITESPACE_SET.indexOf(c) != -1) { |
| 1286 | newIndex++; |
| 1287 | for (; newIndex < this.str_.length; newIndex++) { |
| 1288 | if (WHITESPACE_SET.indexOf(this.str_.charAt(newIndex)) == -1) { |
| 1289 | break; |
| 1290 | } |
| 1291 | } |
| 1292 | if (newIndex >= this.str_.length) { |
| 1293 | return {type: TokenType_Enum.EOF, index: newIndex}; |
| 1294 | } |
| 1295 | c = this.str_.charAt(newIndex); |
| 1296 | } |
| 1297 | |
| 1298 | // A numeric. Notice that it steals the `.` from separators. |
| 1299 | if ( |
| 1300 | convertValues && |
| 1301 | (isNum(c) || |
| 1302 | (c == '.' && |
| 1303 | newIndex + 1 < this.str_.length && |
| 1304 | isNum(this.str_[newIndex + 1]))) |
| 1305 | ) { |
| 1306 | let hasFraction = c == '.'; |
| 1307 | let end = newIndex + 1; |
| 1308 | for (; end < this.str_.length; end++) { |
| 1309 | const c2 = this.str_.charAt(end); |
| 1310 | if (c2 == '.') { |
| 1311 | hasFraction = true; |
| 1312 | continue; |
| 1313 | } |
| 1314 | if (!isNum(c2)) { |
| 1315 | break; |
| 1316 | } |
| 1317 | } |
| 1318 | const s = this.str_.substring(newIndex, end); |
| 1319 | const value = hasFraction ? parseFloat(s) : parseInt(s, 10); |
| 1320 | newIndex = end - 1; |
| 1321 | return {type: TokenType_Enum.LITERAL, value, index: newIndex}; |
| 1322 | } |
| 1323 | |
| 1324 | // Different separators. |
| 1325 | if (SEPARATOR_SET.indexOf(c) != -1) { |
| 1326 | return {type: TokenType_Enum.SEPARATOR, value: c, index: newIndex}; |
| 1327 | } |
| 1328 | |
| 1329 | // String literal. |
| 1330 | if (STRING_SET.indexOf(c) != -1) { |
| 1331 | let end = -1; |
| 1332 | for (let i = newIndex + 1; i < this.str_.length; i++) { |
| 1333 | if (this.str_.charAt(i) == c) { |