Skip to content

Commit 1d46ca2

Browse files
Add support for pulling text from node
1 parent 6c752ab commit 1d46ca2

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/tree_sitter/capture.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ module TreeSitter
1313
node.to_s(io)
1414
end
1515

16+
def text(source : String) : String
17+
node.text(source)
18+
end
19+
1620
def inspect(io : IO)
1721
io << "#<Capture "
1822
to_s(io)

src/tree_sitter/node.cr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ module TreeSitter
122122
io.write(bytes)
123123
end
124124

125+
def text(source : String) : String
126+
start_pos = start_byte
127+
end_pos = end_byte
128+
slice = source.byte_slice(start_pos, end_pos - start_pos)
129+
@@string_pool.get(slice)
130+
end
131+
125132
# :nodoc:
126133
def to_unsafe
127134
@node

0 commit comments

Comments
 (0)