Skip to content

Commit d0cdf29

Browse files
committed
Remove unique ref kinds, specify version
TODO: Tests need fixing
1 parent e57ecd3 commit d0cdf29

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/expr.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ function _leaf_to_Expr(source, txtbuf, txtbuf_offset, head, srcrange, node)
7676
return k == K"error" ?
7777
Expr(:error) :
7878
Expr(:error, "$(_token_error_descriptions[k]): `$(source[srcrange])`")
79-
elseif k == K"RefBegin"
79+
elseif k == K"begin" # begin/end as firstindex/lastindex
8080
return Expr(:begin)
81-
elseif k == K"RefEnd"
81+
elseif k == K"end"
8282
return Expr(:end)
8383
else
8484
val = isnothing(node) ?

src/kinds.jl

-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ register_kinds!(JuliaSyntax, 0, [
198198
# macro name may not appear as characters in the source: The `@` may be
199199
# detached from the macro name as in `@A.x` (ugh!!), or have a _str or _cmd
200200
# suffix appended.
201-
"BEGIN_REF_IDENTIFIERS"
202-
"RefBegin"
203-
"RefEnd"
204-
"BEGIN_REF_IDENTIFIERS"
205201
"BEGIN_MACRO_NAMES"
206202
"MacroName"
207203
"StringMacroName"

src/parser.jl

+2-6
Original file line numberDiff line numberDiff line change
@@ -3627,14 +3627,10 @@ function parse_atom(ps::ParseState, check_identifiers=true, has_unary_prefix=fal
36273627
elseif check_identifiers && is_closing_token(ps, leading_kind)
36283628
# :(end) ==> (quote-: (error end))
36293629
bump(ps, error="invalid identifier")
3630-
elseif ps.end_symbol && leading_kind in KSet"begin end"
3630+
elseif ps.end_symbol && leading_kind in KSet"begin end" && ps.stream.version >= (1, 12)
36313631
# https://github.com/JuliaLang/julia/issues/57269
36323632
# Parse a[begin] differently from a[var"begin"]
3633-
if leading_kind == K"begin"
3634-
bump(ps, remap_kind=K"RefBegin")
3635-
elseif leading_kind == K"end"
3636-
bump(ps, remap_kind=K"RefEnd")
3637-
end
3633+
bump(ps)
36383634
else
36393635
# Remap keywords to identifiers.
36403636
# :end ==> (quote-: end)

test/parser.jl

+6
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ tests = [
410410
"(a=1)[]" => "(ref (parens (= a 1)))"
411411
"a[end]" => "(ref a end)"
412412
"a[begin]" => "(ref a begin)"
413+
"a[var\"end\"]" => "(ref a (var end))"
414+
"a[var\"begin\"]" => "(ref a (var begin))"
415+
"a[var\"test\"]" => "(ref a (var test))"
413416
"a[:(end)]" => "(typed_hcat a (quote-: (parens (error-t))) (error-t))"
414417
"T[x y]" => "(typed_hcat T x y)"
415418
"T[x ; y]" => "(typed_vcat T x y)"
@@ -1153,6 +1156,9 @@ parsestmt_with_kind_tests = [
11531156
"a >>= b" => "(op= a::Identifier >>::Identifier b::Identifier)"
11541157
":+=" => "(quote-: +=::op=)"
11551158
":.+=" => "(quote-: (. +=::op=))"
1159+
# TODO: specify version 1.12
1160+
# "a[begin]" => "(ref a::Identifier begin::begin)"
1161+
# "a[end]" => "(ref a::Identifier end::end)"
11561162
]
11571163

11581164
@testset "parser `Kind` remapping" begin

0 commit comments

Comments
 (0)