Browse Source

fix a few JET opt errors

pull/31/head
Kristoffer 1 year ago
parent
commit
d293606882
  1. 4
      src/chisels.jl
  2. 6
      src/main.jl
  3. 12
      src/runestone.jl

4
src/chisels.jl

@ -368,8 +368,8 @@ end
function infix_op_call_op(node::Node) function infix_op_call_op(node::Node)
@assert is_infix_op_call(node) || kind(node) === K"||" @assert is_infix_op_call(node) || kind(node) === K"||"
kids = verified_kids(node) kids = verified_kids(node)
first_operand_index = findfirst(!JuliaSyntax.is_whitespace, kids) first_operand_index = findfirst(!JuliaSyntax.is_whitespace, kids)::Int
op_index = findnext(JuliaSyntax.is_operator, kids, first_operand_index + 1) op_index = findnext(JuliaSyntax.is_operator, kids, first_operand_index + 1)::Int
return kids[op_index] return kids[op_index]
end end

6
src/main.jl

@ -270,9 +270,9 @@ function main(argv)
# Call the library to format the text # Call the library to format the text
ctx = try ctx = try
ctx = Context(sourcetext; quiet, verbose, debug, diff, check) ctx = Context(sourcetext; quiet, verbose, debug, diff, check)
format_tree!(ctx) format_tree!(ctx)
ctx ctx
catch err catch err
print_progress && errln() print_progress && errln()
# Limit stacktrace to 5 frames because Runic uses recursion a lot and 5 should # Limit stacktrace to 5 frames because Runic uses recursion a lot and 5 should

12
src/runestone.jl

@ -129,7 +129,7 @@ function format_float_literals(ctx::Context, node::Node)
end end
# Split up the pieces # Split up the pieces
r = r"^(?<sgn>[+-])?(?<int>\d*)(?:\.?(?<frac>\d*))?(?:(?<epm>[eEf][+-]?)(?<exp>\d+))?$" r = r"^(?<sgn>[+-])?(?<int>\d*)(?:\.?(?<frac>\d*))?(?:(?<epm>[eEf][+-]?)(?<exp>\d+))?$"
m = match(r, str) m = match(r, str)::RegexMatch
io = IOBuffer() # TODO: Could be reused? io = IOBuffer() # TODO: Could be reused?
# Write the sign part # Write the sign part
if (sgn = m[:sgn]; sgn !== nothing) if (sgn = m[:sgn]; sgn !== nothing)
@ -380,10 +380,6 @@ function spaces_in_listlike(ctx::Context, node::Node)
if last_item_idx !== nothing && last_item_idx <= opening_leaf_idx if last_item_idx !== nothing && last_item_idx <= opening_leaf_idx
last_item_idx = nothing last_item_idx = nothing
end end
last_comma_idx = findprev(x -> kind(x) === K",", kids, closing_leaf_idx - 1)
if last_comma_idx !== nothing && last_comma_idx <= opening_leaf_idx
last_comma_idx = nothing
end
# Multiline lists require leading and trailing newline # Multiline lists require leading and trailing newline
# multiline = contains_outer_newline(kids, opening_leaf_idx, closing_leaf_idx) # multiline = contains_outer_newline(kids, opening_leaf_idx, closing_leaf_idx)
@ -1379,7 +1375,7 @@ function replace_with_in(ctx::Context, node::Node)
@assert kind(node) === K"=" && !is_leaf(node) && meta_nargs(node) == 3 @assert kind(node) === K"=" && !is_leaf(node) && meta_nargs(node) == 3
kids = verified_kids(node) kids = verified_kids(node)
pos = position(ctx.fmt_io) pos = position(ctx.fmt_io)
vars_index = findfirst(!JuliaSyntax.is_whitespace, kids) vars_index = findfirst(!JuliaSyntax.is_whitespace, kids)::Int
# TODO: Need to insert whitespaces around `in` when replacing e.g. `i=I` with `iinI`. # TODO: Need to insert whitespaces around `in` when replacing e.g. `i=I` with `iinI`.
# However, at the moment it looks like the whitespace around operator pass does it's # However, at the moment it looks like the whitespace around operator pass does it's
# thing first? I don't really know how though, because the for loop pass should be # thing first? I don't really know how though, because the for loop pass should be
@ -2778,8 +2774,8 @@ function indent_multiline_strings(ctx::Context, node::Node)
end end
# Opening triple quote # Opening triple quote
open_idx = findfirst(x -> kind(x) === triplekind, kids) open_idx = findfirst(x -> kind(x) === triplekind, kids)::Int
close_idx = findlast(x -> kind(x) === triplekind, kids) close_idx = findlast(x -> kind(x) === triplekind, kids)::Int
@assert close_idx == length(kids) # ? @assert close_idx == length(kids) # ?
open_kid = kids[open_idx] open_kid = kids[open_idx]
@assert kind(open_kid) === triplekind @assert kind(open_kid) === triplekind

Loading…
Cancel
Save