Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix and test fullspan properly #298

Merged
merged 1 commit into from
Jul 26, 2021
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
7 changes: 5 additions & 2 deletions src/components/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,11 @@ function parse_unary_colon(ps::ParseState, op::EXPR)
unwrapped = unwrapbracket(arg)
if isoperator(unwrapped) || isidentifier(unwrapped) || isliteral(unwrapped)
ret = EXPR(:quotenode, EXPR[arg], EXPR[op])
elseif arg.head == :tuple && length(arg.args) == 1 && arg.args[1].head == :parameters && length(something(arg.args[1].args, [])) == 0 && arg.span > 3
ret = EXPR(:quote, EXPR[EXPR(:BLOCK, EXPR[], EXPR[])], EXPR[op])
elseif arg.head == :tuple && length(arg.args) == 1 && arg.args[1].head == :parameters && arg.args[1].args !== nothing && length(arg.args[1].args) == 0 && arg.span > 3
block = EXPR(:BLOCK, EXPR[], EXPR[])
block.span = arg.span
block.fullspan = arg.fullspan
ret = EXPR(:quote, EXPR[block], EXPR[op])
else
ret = EXPR(:quote, EXPR[arg], EXPR[op])
end
Expand Down
3 changes: 3 additions & 0 deletions test/check_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ end

str = read(file, String)

cst = CSTParser.parse(str, true)
cst_expr, cst_err = cst_parse_file(str)
meta_expr, meta_err = meta_parse_file(str)
@test cst_err == meta_err
@test cst.fullspan == sizeof(str)

if cst_err || meta_err
if cst_err && !meta_err
@error "CSTParser.parse errored, but Meta.parse didn't." file=file
Expand Down
1 change: 1 addition & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function test_expr(str, show_data=true)
@test isempty(check_span(x))
check_parents(x)
@test traverse(x)
@test x.fullspan == sizeof(str)

if CSTParser.has_error(ps) || x0 != x1
if show_data
Expand Down