MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / GetEndOffset

Method GetEndOffset

LuaParser/src/Ast/LuaSyntaxTree.cpp:219–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219std::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
261TextRange LuaSyntaxTree::GetTokenRange(std::size_t index) const {
262 if (index < _nodeOrTokens.size()) {

Callers 4

EatInlineCommentMethod · 0.45
GetTextRangeMethod · 0.45
GetEndLineMethod · 0.45
GetEndColMethod · 0.45

Calls 2

sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected