| 189 | } |
| 190 | |
| 191 | std::size_t LuaSyntaxTree::GetStartOffset(std::size_t index) const { |
| 192 | if (index == 0) { |
| 193 | return 0; |
| 194 | } |
| 195 | if (index < _nodeOrTokens.size()) { |
| 196 | auto &n = _nodeOrTokens[index]; |
| 197 | if (n.Type == NodeOrTokenType::Node) { |
| 198 | auto child = n.FirstChild; |
| 199 | while (IsNode(child)) { |
| 200 | child = GetFirstChild(child); |
| 201 | } |
| 202 | if (child != 0) { |
| 203 | return _tokens[_nodeOrTokens[child].Data.TokenIndex].Start; |
| 204 | } else { |
| 205 | for (auto prevToken = index - 1; prevToken > 0; prevToken--) { |
| 206 | if (_nodeOrTokens[prevToken].Type == NodeOrTokenType::Token) { |
| 207 | auto &token = _tokens[_nodeOrTokens[prevToken].Data.TokenIndex]; |
| 208 | return token.Start + token.Length; |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } else { |
| 213 | return _tokens[n.Data.TokenIndex].Start; |
| 214 | } |
| 215 | } |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | std::size_t LuaSyntaxTree::GetEndOffset(std::size_t index) const { |
| 220 | if (index == 0) { |
no test coverage detected