| 1364 | } |
| 1365 | |
| 1366 | GDScriptTokenizer::Token GDScriptTokenizerText::scan() { |
| 1367 | if (has_error()) { |
| 1368 | return pop_error(); |
| 1369 | } |
| 1370 | |
| 1371 | _skip_whitespace(); |
| 1372 | |
| 1373 | if (pending_newline) { |
| 1374 | pending_newline = false; |
| 1375 | if (!multiline_mode) { |
| 1376 | // Don't return newline tokens on multiline mode. |
| 1377 | return last_newline; |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | // Check for potential errors after skipping whitespace(). |
| 1382 | if (has_error()) { |
| 1383 | return pop_error(); |
| 1384 | } |
| 1385 | |
| 1386 | _start = _current; |
| 1387 | start_line = line; |
| 1388 | start_column = column; |
| 1389 | |
| 1390 | if (pending_indents != 0) { |
| 1391 | // Adjust position for indent. |
| 1392 | _start -= start_column - 1; |
| 1393 | start_column = 1; |
| 1394 | if (pending_indents > 0) { |
| 1395 | // Indents. |
| 1396 | pending_indents--; |
| 1397 | return make_token(Token::INDENT); |
| 1398 | } else { |
| 1399 | // Dedents. |
| 1400 | pending_indents++; |
| 1401 | Token dedent = make_token(Token::DEDENT); |
| 1402 | dedent.end_column += 1; |
| 1403 | return dedent; |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | if (_is_at_end()) { |
| 1408 | return make_token(Token::TK_EOF); |
| 1409 | } |
| 1410 | |
| 1411 | const char32_t c = _advance(); |
| 1412 | |
| 1413 | if (c == '\\') { |
| 1414 | // Line continuation with backslash. |
| 1415 | if (_peek() == '\r') { |
| 1416 | if (_peek(1) != '\n') { |
| 1417 | return make_error("Unexpected carriage return character."); |
| 1418 | } |
| 1419 | _advance(); |
| 1420 | } |
| 1421 | if (_peek() != '\n') { |
| 1422 | return make_error("Expected new line after \"\\\"."); |
| 1423 | } |