Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/components/internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ function parse_importexport_item(ps, is_colon = false)
pushtotrivia!(a, accept_rparen(ps))
a
elseif kindof(ps.nt) === Tokens.EX_OR
parse_unary(ps, INSTANCE(next(ps)))
@closer ps :ws parse_unary(ps, INSTANCE(next(ps)))
elseif !is_colon && isoperator(ps.nt)
next(ps)
EXPR(:OPERATOR, ps.nt.startbyte - ps.t.startbyte, 1 + ps.t.endbyte - ps.t.startbyte, val(ps.t, ps))
Expand Down
8 changes: 7 additions & 1 deletion src/components/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,14 @@ function parse_operator_dot(ps::ParseState, ret::EXPR, op::EXPR)

if isidentifier(nextarg) || isinterpolant(nextarg)
ret = EXPR(op, EXPR[ret, EXPR(:quotenode, EXPR[nextarg], nothing)], nothing)
elseif headof(nextarg) === :vect || headof(nextarg) === :braces
elseif headof(nextarg) === :vect
ret = EXPR(op, EXPR[ret, EXPR(:quote, EXPR[nextarg], nothing)], nothing)
elseif headof(nextarg) === :braces
@static if VERSION >= v"1.12-"
ret = EXPR(op, EXPR[ret, EXPR(:quotenode, EXPR[nextarg], nothing)], nothing)
else
ret = EXPR(op, EXPR[ret, EXPR(:quote, EXPR[nextarg], nothing)], nothing)
end
elseif headof(nextarg) === :macrocall
ret = rewrite_macrocall_quotenode(op, ret, nextarg)
elseif VERSION >= v"1.8.0-" && headof(nextarg) === :do && headof(nextarg.args[1]) === :macrocall
Expand Down
8 changes: 8 additions & 0 deletions src/lexer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ mutable struct Closer
end
Closer() = Closer(true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, -1)

function Base.show(io::IO, c::Closer)
println(io, "Closer(")
for f in fieldnames(Closer)
println(io, " ", f, " = ", getfield(c, f), ",")
end
print(io, ")")
end

const IOT = typeof(IOBuffer().data)
mutable struct ParseState
l::Lexer{Base.GenericIOBuffer{IOT},RawToken}
Expand Down
31 changes: 27 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,33 @@ function closer(ps::ParseState)
!(!ps.closer.inmacro && kindof(ps.nt) === Tokens.FOR) &&
!(kindof(ps.nt) === Tokens.DO) &&
!(
(isbinaryop(ps.nt) && !(ps.closer.wsop && isemptyws(ps.nws) && isunaryop(ps.nt) && precedence(ps.nt) > 7)) ||
(isunaryop(ps.t) && kindof(ps.ws) == WS && kindof(ps.lt) !== CSTParser.Tokens.COLON)
)) ||
(ps.closer.unary && (kindof(ps.t) in (Tokens.INTEGER, Tokens.FLOAT, Tokens.RPAREN, Tokens.RSQUARE, Tokens.RBRACE) && isidentifier(ps.nt)))
(
isbinaryop(ps.nt) && (
!(
ps.closer.wsop &&
isemptyws(ps.nws) &&
isunaryop(ps.nt) &&
precedence(ps.nt) > 7
)
)
) || (
isunaryop(ps.t) &&
kindof(ps.ws) == WS &&
kindof(ps.lt) !== CSTParser.Tokens.COLON
)
)
) ||
(
ps.closer.unary && (
kindof(ps.t) in (
Tokens.INTEGER,
Tokens.FLOAT,
Tokens.RPAREN,
Tokens.RSQUARE,
Tokens.RBRACE
) && isidentifier(ps.nt)
)
)
end

"""
Expand Down
4 changes: 3 additions & 1 deletion test/parser/test_keyword_blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ end
@test "for outer i = 1:3 end" |> test_expr
if VERSION >= v"1.6"
@test "for outer \$i = 1:3 end" |> test_expr
@test "for outer \$ i = 1:3 end" |> test_expr
if VERSION < v"1.12-"
@test "for outer \$ i = 1:3 end" |> test_expr
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/parser/test_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ end
@test "3//a^b" |> test_expr
@test "3^b//a^b" |> test_expr
@test "3^b//a" |> test_expr
@test_broken "@a b ^ -c(d)^e" |> test_expr
@test_broken "[a b ^ -c(d)^e f]" |> test_expr
@test "a::b..." |> test_expr
@test "a where b..." |> test_expr
@test "a.b..." |> test_expr
Expand Down
1 change: 1 addition & 0 deletions test/parser/test_parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ end
@test CSTParser.parse("using a as b")[2].head === :errortoken
@test test_expr("using M: a as b")
@test test_expr("using M: a as b, c")
@test test_expr(raw":(import $foo as $bar)")
end
end
@testitem "exor #201" begin
Expand Down
2 changes: 2 additions & 0 deletions test/parser/test_square.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@test traverse(CSTParser.parse("[\"hi\"\""))
@test traverse(CSTParser.parse("[\"hi\"\"\n"))
@test traverse(CSTParser.parse("[(1,2,3])"))

@test "[2.0^53 2.0^53+2]" |> test_expr
end

@testitem "ref" begin
Expand Down
11 changes: 7 additions & 4 deletions test/test_check_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,24 @@

if cst_err || meta_err
if cst_err && !meta_err
@error "CSTParser.parse errored, but Meta.parse didn't." file = file
@error "CSTParser.parse errored, but Meta.parse didn't." file
elseif !cst_err && meta_err
@error "Meta.parse errored, but CSTParser.parse didn't." file = file
@error "Meta.parse errored, but CSTParser.parse didn't." file
end
@test false
else
if cst_expr == meta_expr
@test true
else
@error "parsing difference" file = file
_compare(cst_expr, meta_expr)
# _compare(cst_expr, meta_expr)
# 1.10 introduced a bunch of changes to the canonical AST, which
# CSTParser does not support right now. This does not mean that we
# cannot parse that file though, just that Expr conversion doesn't
# work well
if v"1.10-" <= VERSION < v"1.12-" && basename(file) == "syntax.jl"
if v"1.10-" <= VERSION < v"1.13-" && basename(file) == "syntax.jl"
@test_broken false
elseif VERSION >= v"1.12-"
@test_broken false
else
@test false
Expand Down
6 changes: 5 additions & 1 deletion test/test_spec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ end
include("shared.jl")

test_expr("f(a=1)", :call, 4, false)
test_expr("f(::typeof(a)=1)", :call, 4, false)
if VERSION <= v"1.12-"
# currently broken due to JuliaSyntax inserting a begin-end block
# on the RHS of the kwarg
test_expr("f(::typeof(a)=1)", :call, 4, false)
end
test_expr("f(a::typeof(a)=1)", :call, 4, false)
test_expr("f(::a=1)", :call, 4, false)
test_expr("f(a::a=1)", :call, 4, false)
Expand Down
Loading