| 230 | } |
| 231 | |
| 232 | int GDScriptLanguage::find_function(const String &p_function, const String &p_code) const { |
| 233 | GDScriptTokenizerText tokenizer; |
| 234 | tokenizer.set_source_code(p_code); |
| 235 | int indent = 0; |
| 236 | GDScriptTokenizer::Token current = tokenizer.scan(); |
| 237 | while (current.type != GDScriptTokenizer::Token::TK_EOF && current.type != GDScriptTokenizer::Token::ERROR) { |
| 238 | if (current.type == GDScriptTokenizer::Token::INDENT) { |
| 239 | indent++; |
| 240 | } else if (current.type == GDScriptTokenizer::Token::DEDENT) { |
| 241 | indent--; |
| 242 | } |
| 243 | if (indent == 0 && current.type == GDScriptTokenizer::Token::FUNC) { |
| 244 | current = tokenizer.scan(); |
| 245 | if (current.is_identifier()) { |
| 246 | String identifier = current.get_identifier(); |
| 247 | if (identifier == p_function) { |
| 248 | return current.start_line; |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | current = tokenizer.scan(); |
| 253 | } |
| 254 | return -1; |
| 255 | } |
| 256 | |
| 257 | Script *GDScriptLanguage::create_script() const { |
| 258 | return memnew(GDScript); |
no test coverage detected