Skip to content

Commit

Permalink
Merge pull request #298 from julia-vscode/sp/size-matters
Browse files Browse the repository at this point in the history
Fix and test fullspan properly
  • Loading branch information
davidanthoff authored Jul 26, 2021
2 parents 3aa5133 + ce8f763 commit 7583d06
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
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

0 comments on commit 7583d06

Please # to comment.