Skip to content

Parse arr[end] differently from arr[var"end"] #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix version (1.13) and tests
  • Loading branch information
mlechu committed Apr 28, 2025
commit 17be4e33b713d4e0f41f5ae3c5abcaef68bd9c90
2 changes: 1 addition & 1 deletion src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3627,7 +3627,7 @@ function parse_atom(ps::ParseState, check_identifiers=true, has_unary_prefix=fal
elseif check_identifiers && is_closing_token(ps, leading_kind)
# :(end) ==> (quote-: (error end))
bump(ps, error="invalid identifier")
elseif ps.end_symbol && leading_kind in KSet"begin end" && ps.stream.version >= (1, 12)
elseif ps.end_symbol && leading_kind in KSet"begin end" && ps.stream.version >= (1, 13)
# https://github.com/JuliaLang/julia/issues/57269
# Parse a[begin] differently from a[var"begin"]
bump(ps)
Expand Down
13 changes: 9 additions & 4 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1156,14 +1156,19 @@ parsestmt_with_kind_tests = [
"a >>= b" => "(op= a::Identifier >>::Identifier b::Identifier)"
":+=" => "(quote-: +=::op=)"
":.+=" => "(quote-: (. +=::op=))"
# TODO: specify version 1.12
# "a[begin]" => "(ref a::Identifier begin::begin)"
# "a[end]" => "(ref a::Identifier end::end)"
((v=v"1.13",), "a[begin]") => "(ref a::Identifier begin::begin)"
((v=v"1.13",), "a[end]") => "(ref a::Identifier end::end)"
]

@testset "parser `Kind` remapping" begin
@testset "$(repr(input))" for (input, output) in parsestmt_with_kind_tests
input = ((show_kind=true,), input)
if !(input isa AbstractString)
opts, input_s = input
else
opts = NamedTuple()
input_s = input
end
input = ((show_kind=true, opts...), input_s)
test_parse(JuliaSyntax.parse_stmts, input, output)
end
end
Expand Down
Loading