Skip to content

Commit 2a3b5b4

Browse files
committed
Don't consume RSQUAREs when closer.square is true
1 parent 5759e03 commit 2a3b5b4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/CSTParser.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ function parse_expression(ps::ParseState, esc_on_error = false)
4444
elseif (esc_on_error && ps.nt.kind == Tokens.ERROR)
4545
ret = EXPR(:errortoken, 0, 0)
4646
elseif kindof(ps.nt) term_c && !(kindof(ps.nt) === Tokens.END && ps.closer.square)
47-
ret = mErrorToken(ps, EXPR(next(ps)), UnexpectedToken)
47+
if ps.closer.square && kindof(ps.nt) === Tokens.RSQUARE
48+
ret = mErrorToken(ps, UnexpectedToken)
49+
else
50+
ret = mErrorToken(ps, EXPR(next(ps)), UnexpectedToken)
51+
end
4852
else
4953
next(ps)
5054
if iskeyword(kindof(ps.t)) && kindof(ps.t) != Tokens.DO

test/parser.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ end
478478
@test "[(1,2)]" |> test_expr
479479
@test "[x...]" |> test_expr
480480
@test "[1,2,3,4,5]" |> test_expr
481+
# this is nonsensical, but iteration should still work
482+
@test traverse(CSTParser.parse(raw"""[[:alpha:]a←-]"""))
481483
end
482484

483485
@testset "ref" begin

0 commit comments

Comments
 (0)