Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Ast/include/Luau/Location.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
namespace Luau
5
{
6
7
struct Position
8
{
9
unsigned int line, column;
10
11
Position(unsigned int line, unsigned int column)
12
: line(line)
13
, column(column)
14
{
15
}
16
17
bool operator==(const Position& rhs) const
18
{
19
return this->column == rhs.column && this->line == rhs.line;
20
}
21
22
bool operator!=(const Position& rhs) const
23
{
24
return !(*this == rhs);
25
}
26
bool operator<(const Position& rhs) const
27
{
28
if (line == rhs.line)
29
return column < rhs.column;
30
else
31
return line < rhs.line;
32
}
33
bool operator>(const Position& rhs) const
34
{
35
if (line == rhs.line)
36
return column > rhs.column;
37
else
38
return line > rhs.line;
39
}
40
bool operator<=(const Position& rhs) const
41
{
42
return *this == rhs || *this < rhs;
43
}
44
bool operator>=(const Position& rhs) const
45
{
46
return *this == rhs || *this > rhs;
47
}
48
49
void shift(const Position& start, const Position& oldEnd, const Position& newEnd);
50
};
51
52
struct Location
53
{
54
Position begin, end;
55
56
Location()
57
: begin(0, 0)
58
, end(0, 0)
59
{
60
}
61
62
Location(const Position& begin, const Position& end)
63
: begin(begin)
64
, end(end)
65
{
66
}
67
68
Location(const Position& begin, unsigned int length)
69
: begin(begin)
70
, end(begin.line, begin.column + length)
71
{
72
}
73
74
Location(const Location& begin, const Location& end)
75
: begin(begin.begin)
76
, end(end.end)
77
{
78
}
79
80
bool operator==(const Location& rhs) const
81
{
82
return this->begin == rhs.begin && this->end == rhs.end;
83
}
84
bool operator!=(const Location& rhs) const
85
{
86
return !(*this == rhs);
87
}
88
89
bool encloses(const Location& l) const;
90
bool overlaps(const Location& l) const;
91
bool contains(const Position& p) const;
92
bool containsClosed(const Position& p) const;
93
void extend(const Location& other);
94
void shift(const Position& start, const Position& oldEnd, const Position& newEnd);
95
};
96
97
} // namespace Luau
98
99