Skip to content

Commit 77eaac3

Browse files
author
oscarddssmith
committed
fixes
1 parent 2edb531 commit 77eaac3

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/expr.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ end
580580

581581
function build_tree(::Type{Tuple{Expr, SyntaxNode}}, stream::ParseStream;
582582
filename=nothing, first_line=1, kws...)
583-
syntaxtree = build_tree(SyntaxNode, stream, filename, first_line, kws...)
584-
Expr.(syntaxtree)
583+
syntaxtree = build_tree(SyntaxNode, stream; filename, first_line, kws...)
584+
Expr(:toplevel, map(Expr, syntaxtree))
585585
end
586586

587587
function _to_expr(node)

src/hooks.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ _default_system_parser = _has_v1_6_hooks ? Core._parse : nothing
296296

297297

298298
# hook into InteractiveUtils.@activate
299-
activate!(enable=true) = enable_in_core!(enable)
299+
activate!(enable=true; for_lowering=false) = enable_in_core!(enable, for_lowering)
300300

301301
"""
302302
enable_in_core!([enable=true; freeze_world_age=true, debug_filename=nothing])
@@ -312,7 +312,7 @@ Keyword arguments:
312312
* `debug_filename` - File name of parser debug log (defaults to `nothing` or
313313
the value of `ENV["JULIA_SYNTAX_DEBUG_FILE"]`).
314314
"""
315-
function enable_in_core!(enable=true; freeze_world_age = true,
315+
function enable_in_core!(enable=true, for_lowering=false; freeze_world_age = true,
316316
debug_filename = get(ENV, "JULIA_SYNTAX_DEBUG_FILE", nothing))
317317
if !_has_v1_6_hooks
318318
error("Cannot use JuliaSyntax as the main Julia parser in Julia version $VERSION < 1.6")
@@ -323,12 +323,10 @@ function enable_in_core!(enable=true; freeze_world_age = true,
323323
close(_debug_log[])
324324
_debug_log[] = nothing
325325
end
326-
if enable == :JuliaLowering
326+
if enable
327+
hook = for_lowering ? core_parser_hook_for_lowering : core_parser_hook
327328
world_age = freeze_world_age ? Base.get_world_counter() : typemax(UInt)
328-
_set_core_parse_hook(fix_world_age(core_parser_hook_for_lowering, world_age))
329-
elseif enable
330-
world_age = freeze_world_age ? Base.get_world_counter() : typemax(UInt)
331-
_set_core_parse_hook(fix_world_age(core_parser_hook, world_age))
329+
_set_core_parse_hook(fix_world_age(hook, world_age))
332330
else
333331
@assert !isnothing(_default_system_parser)
334332
_set_core_parse_hook(_default_system_parser)

src/syntax_tree.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,17 @@ numchildren(node::TreeNode) = (isnothing(node.children) ? 0 : length(node.childr
131131
Base.getindex(node::AbstractSyntaxNode, i::Int) = children(node)[i]
132132
Base.getindex(node::AbstractSyntaxNode, rng::UnitRange) = view(children(node), rng)
133133
Base.firstindex(node::AbstractSyntaxNode) = 1
134-
Base.lastindex(node::AbstractSyntaxNode) = length(children(node))
134+
Base.length(node::AbstractSyntaxNode) = length(children(node))
135+
Base.lastindex(node::AbstractSyntaxNode) = length(node)
135136

136137
function Base.setindex!(node::SN, x::SN, i::Int) where {SN<:AbstractSyntaxNode}
137138
children(node)[i] = x
138139
end
139140

141+
function Base.iterate(A::AbstractSyntaxNode, i=1)
142+
(@inline; (i - 1)%UInt < length(A)%UInt ? (@inbounds A[i], i + 1) : nothing)
143+
end
144+
140145
"""
141146
head(x)
142147

0 commit comments

Comments
 (0)