| 217 | } |
| 218 | |
| 219 | std::size_t LuaSyntaxTree::GetEndOffset(std::size_t index) const { |
| 220 | if (index == 0) { |
| 221 | return 0; |
| 222 | } |
| 223 | std::size_t nodeOrTokenIndex = index; |
| 224 | if (index < _nodeOrTokens.size()) { |
| 225 | auto &n = _nodeOrTokens[index]; |
| 226 | if (n.Type == NodeOrTokenType::Node) { |
| 227 | auto child = n.LastChild; |
| 228 | while (IsNode(child)) { |
| 229 | child = GetLastChild(child); |
| 230 | } |
| 231 | if (child != 0) { |
| 232 | nodeOrTokenIndex = child; |
| 233 | } else { |
| 234 | for (auto prevToken = index - 1; prevToken > 0; prevToken--) { |
| 235 | if (_nodeOrTokens[prevToken].Type == NodeOrTokenType::Token) { |
| 236 | auto &token = _tokens[_nodeOrTokens[prevToken].Data.TokenIndex]; |
| 237 | return token.Start + token.Length; |
| 238 | } |
| 239 | } |
| 240 | nodeOrTokenIndex = 0; |
| 241 | } |
| 242 | } |
| 243 | } else if (!_nodeOrTokens.empty()) { |
| 244 | nodeOrTokenIndex = _nodeOrTokens.size() - 1; |
| 245 | } else { |
| 246 | nodeOrTokenIndex = 0; |
| 247 | }; |
| 248 | |
| 249 | if (nodeOrTokenIndex != 0) { |
| 250 | auto &token = _tokens[_nodeOrTokens[nodeOrTokenIndex].Data.TokenIndex]; |
| 251 | if (token.Length != 0) { |
| 252 | return token.Start + token.Length - 1; |
| 253 | } else { |
| 254 | return token.Start; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | TextRange LuaSyntaxTree::GetTokenRange(std::size_t index) const { |
| 262 | if (index < _nodeOrTokens.size()) { |
no test coverage detected