Skip to content

Commit 5c134f4

Browse files
authored
Terminate :statement parsing at newlines (#493)
Addresses a portion of #316
1 parent 87fcdf0 commit 5c134f4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/hooks.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ function core_parser_hook(code, filename::String, lineno::Int, offset::Int, opti
171171
end
172172
parse!(stream; rule=options)
173173
if options === :statement
174-
bump_trivia(stream)
174+
bump_trivia(stream; skip_newlines=false)
175+
if peek(stream) == K"NewlineWs"
176+
bump(stream)
177+
end
175178
end
176179

177180
if any_error(stream)

test/hooks.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function _unwrap_parse_error(core_hook_result)
1111
end
1212

1313
@testset "Hooks for Core integration" begin
14-
@testset "whitespace parsing" begin
14+
@testset "whitespace and comment parsing" begin
1515
@test JuliaSyntax.core_parser_hook("", "somefile", 1, 0, :statement) == Core.svec(nothing, 0)
1616
@test JuliaSyntax.core_parser_hook("", "somefile", 1, 0, :statement) == Core.svec(nothing, 0)
1717

@@ -20,6 +20,16 @@ end
2020

2121
@test JuliaSyntax.core_parser_hook(" x \n", "somefile", 1, 0, :statement) == Core.svec(:x,4)
2222
@test JuliaSyntax.core_parser_hook(" x \n", "somefile", 1, 0, :atom) == Core.svec(:x,2)
23+
24+
# https://github.com/JuliaLang/JuliaSyntax.jl/issues/316#issuecomment-1870294857
25+
stmtstr =
26+
"""
27+
plus(a, b) = a + b
28+
29+
# Issue #81
30+
f() = nothing
31+
"""
32+
@test JuliaSyntax.core_parser_hook(stmtstr, "somefile", 1, 0, :statement)[2] == 19
2333
end
2434

2535
@testset "filename and lineno" begin

0 commit comments

Comments
 (0)