Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/tests/AstQueryDsl.cpp
2723 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
3
#include "AstQueryDsl.h"
4
5
namespace Luau
6
{
7
8
FindNthOccurenceOf::FindNthOccurenceOf(Nth nth)
9
: requestedNth(nth)
10
{
11
}
12
13
bool FindNthOccurenceOf::checkIt(AstNode* n)
14
{
15
if (theNode)
16
return false;
17
18
if (n->classIndex == requestedNth.classIndex)
19
{
20
// Human factor: the requestedNth starts from 1 because of the term `nth`.
21
if (currentOccurrence + 1 != requestedNth.nth)
22
++currentOccurrence;
23
else
24
theNode = n;
25
}
26
27
return !theNode; // once found, returns false and stops traversal
28
}
29
30
bool FindNthOccurenceOf::visit(AstNode* n)
31
{
32
return checkIt(n);
33
}
34
35
bool FindNthOccurenceOf::visit(AstType* t)
36
{
37
return checkIt(t);
38
}
39
40
bool FindNthOccurenceOf::visit(AstTypePack* t)
41
{
42
return checkIt(t);
43
}
44
45
} // namespace Luau
46
47