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

Method parse

modules/gdscript/gdscript_parser.cpp:351–445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351Error GDScriptParser::parse(const String &p_source_code, const String &p_script_path, bool p_for_completion, bool p_parse_body) {
352 clear();
353
354 String source = p_source_code;
355 int cursor_line = -1;
356 int cursor_column = -1;
357 for_completion = p_for_completion;
358 parse_body = p_parse_body;
359
360 int tab_size = 4;
361#ifdef TOOLS_ENABLED
362 if (EditorSettings::get_singleton()) {
363 tab_size = EditorSettings::get_singleton()->get_setting("text_editor/behavior/indent/size");
364 }
365#endif // TOOLS_ENABLED
366
367 if (p_for_completion) {
368 // Remove cursor sentinel char.
369 const Vector<String> lines = p_source_code.split("\n");
370 cursor_line = 1;
371 cursor_column = 1;
372 for (int i = 0; i < lines.size(); i++) {
373 bool found = false;
374 const String &line = lines[i];
375 for (int j = 0; j < line.size(); j++) {
376 if (line[j] == char32_t(0xFFFF)) {
377 found = true;
378 break;
379 } else if (line[j] == '\t') {
380 cursor_column += tab_size - 1;
381 }
382 cursor_column++;
383 }
384 if (found) {
385 break;
386 }
387 cursor_line++;
388 cursor_column = 1;
389 }
390
391 source = source.replace_first(String::chr(0xFFFF), String());
392 }
393
394 GDScriptTokenizerText *text_tokenizer = memnew(GDScriptTokenizerText);
395 text_tokenizer->set_source_code(source);
396
397 tokenizer = text_tokenizer;
398
399 tokenizer->set_cursor_position(cursor_line, cursor_column);
400 script_path = p_script_path.simplify_path();
401 current = tokenizer->scan();
402 // Avoid error or newline as the first token.
403 // The latter can mess with the parser when opening files filled exclusively with comments and newlines.
404 while (current.type == GDScriptTokenizer::Token::ERROR || current.type == GDScriptTokenizer::Token::NEWLINE) {
405 if (current.type == GDScriptTokenizer::Token::ERROR) {
406 push_error(current.literal);
407 }
408 current = tokenizer->scan();

Callers 15

compile_glslang_shaderFunction · 0.45
_parse_jsonMethod · 0.45
_parse_glbMethod · 0.45
_parseMethod · 0.45
_update_exportsMethod · 0.45
reloadMethod · 0.45
get_global_class_nameMethod · 0.45
get_dependenciesMethod · 0.45
raise_statusMethod · 0.45
validateMethod · 0.45

Calls 12

clearFunction · 0.85
memdeleteFunction · 0.85
splitMethod · 0.80
replace_firstMethod · 0.80
sizeMethod · 0.65
StringClass · 0.50
get_settingMethod · 0.45
set_source_codeMethod · 0.45
set_cursor_positionMethod · 0.45
simplify_pathMethod · 0.45
scanMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected