MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / scan

Method scan

bytecode/gdscript_v2_tokenizer_buffer.cpp:450–527  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

448}
449
450GDScriptV2TokenizerCompat::Token GDScriptV2TokenizerBufferCompat::scan() {
451 // Add final newline.
452 if (current >= tokens.size() && !last_token_was_newline) {
453 Token newline;
454 newline.type = Token::Type::G_TK_NEWLINE;
455 newline.start_line = current_line;
456 newline.end_line = current_line;
457 last_token_was_newline = true;
458 return newline;
459 }
460
461 // Resolve pending indentation change.
462 if (pending_indents > 0) {
463 pending_indents--;
464 Token indent;
465 indent.type = Token::Type::G_TK_INDENT;
466 indent.start_line = current_line;
467 indent.end_line = current_line;
468 return indent;
469 } else if (pending_indents < 0) {
470 pending_indents++;
471 Token dedent;
472 dedent.type = Token::Type::G_TK_DEDENT;
473 dedent.start_line = current_line;
474 dedent.end_line = current_line;
475 return dedent;
476 }
477
478 if (current >= tokens.size()) {
479 if (!indent_stack.is_empty()) {
480 pending_indents -= indent_stack.size();
481 indent_stack.clear();
482 return scan();
483 }
484 Token eof;
485 eof.type = Token::Type::G_TK_EOF;
486 return eof;
487 };
488
489 if (!last_token_was_newline && token_lines.has(current)) {
490 current_line = token_lines[current];
491 uint32_t current_column = token_columns[current];
492
493 // Check if there's a need to indent/dedent.
494 if (!multiline_mode) {
495 uint32_t previous_indent = 0;
496 if (!indent_stack.is_empty()) {
497 previous_indent = indent_stack.back()->get();
498 }
499 if (current_column - 1 > previous_indent) {
500 pending_indents++;
501 indent_stack.push_back(current_column - 1);
502 } else {
503 while (current_column - 1 < previous_indent) {
504 pending_indents--;
505 indent_stack.pop_back();
506 if (indent_stack.is_empty()) {
507 break;

Callers 3

parse_code_stringMethod · 0.45
get_tokenMethod · 0.45

Calls 7

scanFunction · 0.85
backMethod · 0.80
push_backMethod · 0.80
pop_backMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected