|
1 | 1 | using CSTParser
|
2 |
| -using CSTParser: EXPR, Call, Location, expr_location, charrange |
| 2 | +using CSTParser: EXPR, Call |
3 | 3 |
|
4 | 4 | expridx(x, ii) = (@assert isempty(ii); x)
|
5 | 5 | expridx(x::Expr, ii) = isempty(ii) ? x : expridx(x.args[ii[1]], ii[2:end])
|
6 | 6 |
|
7 | 7 | function precedence_level(cst::EXPR, loc::Location)
|
8 |
| - parent = cst[CSTParser.parent(loc)] |
| 8 | + parent = cst[MacroTools.parent(loc)] |
9 | 9 | if parent isa Union{CSTParser.BinaryOpCall,CSTParser.UnaryOpCall,CSTParser.ChainOpCall}
|
10 | 10 | Base.operator_precedence(Expr(parent).args[1])
|
11 | 11 | elseif parent isa Union{CSTParser.BinarySyntaxOpCall,CSTParser.UnarySyntaxOpCall}
|
|
18 | 18 | # Get the range at loc, including trailing trivia from the previous node.
|
19 | 19 | function separator_range(cst, loc)
|
20 | 20 | i = loc.ii[end]
|
21 |
| - loc = CSTParser.parent(loc) |
22 |
| - start = charrange(cst, CSTParser.child(loc, i-1))[1][1]+1 |
23 |
| - stop = charrange(cst, CSTParser.child(loc, i))[1][end] |
| 21 | + loc = MacroTools.parent(loc) |
| 22 | + start = charrange(cst, child(loc, i-1))[1][1]+1 |
| 23 | + stop = charrange(cst, child(loc, i))[1][end] |
24 | 24 | return start:stop
|
25 | 25 | end
|
26 | 26 |
|
27 | 27 | function separator(cst, loc, x::EXPR{Call}, i)
|
28 | 28 | length(x.args) == 3 && return ""
|
29 | 29 | length(x.args) == 4 && return ", "
|
30 |
| - separator_range(cst, CSTParser.child(loc, max(i-1,4))) |
| 30 | + separator_range(cst, child(loc, max(i-1,4))) |
31 | 31 | end
|
32 | 32 |
|
33 | 33 | function separator(cst, loc, x::EXPR{CSTParser.Block}, i)
|
34 |
| - out, in = charrange(cst, CSTParser.child(loc, max(i-1,1))) |
| 34 | + out, in = charrange(cst, child(loc, max(i-1,1))) |
35 | 35 | in[end]+1:out[end]
|
36 | 36 | end
|
37 | 37 |
|
38 | 38 | function separator(cst, loc, x::CSTParser.BinaryOpCall, i)
|
39 |
| - separator_range(cst, CSTParser.child(loc, 2)) |
| 39 | + separator_range(cst, child(loc, 2)) |
40 | 40 | end
|
41 | 41 |
|
42 | 42 | function separator(cst::EXPR, loc::Location)
|
43 |
| - parent = CSTParser.parent(loc) |
| 43 | + parent = MacroTools.parent(loc) |
44 | 44 | separator(cst, parent, cst[parent], loc.ii[end])
|
45 | 45 | end
|
46 | 46 |
|
@@ -68,7 +68,7 @@ function replacement(src::SourceFile, p::Insert)
|
68 | 68 | append && (p.idx[end] -= 1)
|
69 | 69 | loc = expr_location(src.cst, p.idx)
|
70 | 70 | # TODO handle cases like this more generally
|
71 |
| - src.cst[CSTParser.parent(loc)] isa EXPR{Call} && (loc.ii[end] = max(loc.ii[end], 2)) |
| 71 | + src.cst[MacroTools.parent(loc)] isa EXPR{Call} && (loc.ii[end] = max(loc.ii[end], 2)) |
72 | 72 | _, span = charrange(src.cst, loc)
|
73 | 73 | point = append ? span[end] : span[1]-1
|
74 | 74 | sep = separator(src.cst, loc)
|
|
0 commit comments