-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathnode.cr
39 lines (33 loc) · 889 Bytes
/
node.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Mint
class Ast
class Node
property from : Parser::Location
property parent : Node?
getter to : Parser::Location
getter file : Parser::File
getter source : String do
file.contents[from.offset, to.offset - from.offset]
end
def initialize(@file, @from, @to)
end
def contains?(line : Int64)
from.line <= line <= to.line
end
def contains?(line : Int64, column : Int64)
case
when line == from.line == to.line # If on the only line
from.column <= column < to.column
when line == from.line # If on the first line
column >= from.column
when line == to.line # If on the last line
column < to.column
else
contains?(line)
end
end
def new_line?
to.line > from.line
end
end
end
end