Skip to content

Commit 2e508a7

Browse files
committed
Store last byte in SourceRef and allow removing green_tree
Exactly what information we want to prune in the final implementation is not determined, but `green_tree` is probably part of it.
1 parent 06ba024 commit 2e508a7

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/syntax_graph.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,15 @@ end
319319
struct SourceRef
320320
file::SourceFile
321321
first_byte::Int
322-
# TODO: Do we need the green node, or would last_byte suffice?
323-
green_tree::JuliaSyntax.GreenNode
322+
last_byte::Int
323+
green_tree::Union{Nothing, JuliaSyntax.GreenNode}
324324
end
325325

326+
SourceRef(file::SourceFile, first_byte::Int, green_tree::Union{Nothing, JuliaSyntax.GreenNode}) =
327+
SourceRef(file, first_byte, first_byte + span(green_tree) - 1, green_tree)
328+
326329
JuliaSyntax.sourcefile(src::SourceRef) = src.file
327-
JuliaSyntax.byte_range(src::SourceRef) = src.first_byte:(src.first_byte + span(src.green_tree) - 1)
330+
JuliaSyntax.byte_range(src::SourceRef) = src.first_byte:src.last_byte
328331

329332
# TODO: Adding these methods to support LineNumberNode is kind of hacky but we
330333
# can remove these after JuliaLowering becomes self-bootstrapping for macros

0 commit comments

Comments
 (0)