| 136 | } |
| 137 | |
| 138 | GDScriptV2TokenizerCompat::Token GDScriptV2TokenizerCompatText::make_token(Token::Type p_type) { |
| 139 | Token token(p_type); |
| 140 | DEV_ASSERT(decomp->get_local_token_val(p_type) != -1); |
| 141 | token.start_line = start_line; |
| 142 | token.end_line = line; |
| 143 | token.start_column = start_column; |
| 144 | token.end_column = column; |
| 145 | token.leftmost_column = leftmost_column; |
| 146 | token.rightmost_column = rightmost_column; |
| 147 | token.source = String::utf32(Span(_start, _current - _start)); |
| 148 | |
| 149 | if (p_type != Token::Type::G_TK_ERROR && cursor_line > -1) { |
| 150 | // Also count whitespace after token. |
| 151 | int offset = 0; |
| 152 | while (_peek(offset) == ' ' || _peek(offset) == '\t') { |
| 153 | offset++; |
| 154 | } |
| 155 | int last_column = column + offset; |
| 156 | // Check cursor position in token. |
| 157 | if (start_line == line) { |
| 158 | // Single line token. |
| 159 | if (cursor_line == start_line && cursor_column >= start_column && cursor_column <= last_column) { |
| 160 | token.cursor_position = cursor_column - start_column; |
| 161 | if (cursor_column == start_column) { |
| 162 | token.cursor_place = CURSOR_BEGINNING; |
| 163 | } else if (cursor_column < column) { |
| 164 | token.cursor_place = CURSOR_MIDDLE; |
| 165 | } else { |
| 166 | token.cursor_place = CURSOR_END; |
| 167 | } |
| 168 | } |
| 169 | } else { |
| 170 | // Multi line token. |
| 171 | if (cursor_line == start_line && cursor_column >= start_column) { |
| 172 | // Is in first line. |
| 173 | token.cursor_position = cursor_column - start_column; |
| 174 | if (cursor_column == start_column) { |
| 175 | token.cursor_place = CURSOR_BEGINNING; |
| 176 | } else { |
| 177 | token.cursor_place = CURSOR_MIDDLE; |
| 178 | } |
| 179 | } else if (cursor_line == line && cursor_column <= last_column) { |
| 180 | // Is in last line. |
| 181 | token.cursor_position = cursor_column - start_column; |
| 182 | if (cursor_column < column) { |
| 183 | token.cursor_place = CURSOR_MIDDLE; |
| 184 | } else { |
| 185 | token.cursor_place = CURSOR_END; |
| 186 | } |
| 187 | } else if (cursor_line > start_line && cursor_line < line) { |
| 188 | // Is in middle line. |
| 189 | token.cursor_position = CURSOR_MIDDLE; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | last_token = token; |
| 195 | return token; |
nothing calls this directly
no test coverage detected