MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / check_indent

Method check_indent

modules/gdscript/gdscript_tokenizer.cpp:1135–1296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1133}
1134
1135void GDScriptTokenizerText::check_indent() {
1136 ERR_FAIL_COND_MSG(column != 1, "Checking tokenizer indentation in the middle of a line.");
1137
1138 if (_is_at_end()) {
1139 // Send dedents for every indent level.
1140 pending_indents -= indent_level();
1141 indent_stack.clear();
1142 return;
1143 }
1144
1145 for (;;) {
1146 char32_t current_indent_char = _peek();
1147 int indent_count = 0;
1148
1149 if (current_indent_char != ' ' && current_indent_char != '\t' && current_indent_char != '\r' && current_indent_char != '\n' && current_indent_char != '#') {
1150 // First character of the line is not whitespace, so we clear all indentation levels.
1151 // Unless we are in a continuation or in multiline mode (inside expression).
1152 if (line_continuation || multiline_mode) {
1153 return;
1154 }
1155 pending_indents -= indent_level();
1156 indent_stack.clear();
1157 return;
1158 }
1159
1160 if (_peek() == '\r') {
1161 _advance();
1162 if (_peek() != '\n') {
1163 push_error("Stray carriage return character in source code.");
1164 }
1165 }
1166 if (_peek() == '\n') {
1167 // Empty line, keep going.
1168 _advance();
1169 newline(false);
1170 continue;
1171 }
1172
1173 // Check indent level.
1174 bool mixed = false;
1175 while (!_is_at_end()) {
1176 char32_t space = _peek();
1177 if (space == '\t') {
1178 // Consider individual tab columns.
1179 column += tab_size - 1;
1180 indent_count += tab_size;
1181 } else if (space == ' ') {
1182 indent_count += 1;
1183 } else {
1184 break;
1185 }
1186 mixed = mixed || space != current_indent_char;
1187 _advance();
1188 }
1189
1190 if (_is_at_end()) {
1191 // Reached the end with an empty line, so just dedent as much as needed.
1192 pending_indents -= indent_level();

Callers

nothing calls this directly

Calls 7

CommentDataClass · 0.85
vformatFunction · 0.85
clearMethod · 0.45
getMethod · 0.45
backMethod · 0.45
push_backMethod · 0.45
pop_backMethod · 0.45

Tested by

no test coverage detected