diff --git a/src/Runic.jl b/src/Runic.jl index d6bcb3c..d3fe2a5 100644 --- a/src/Runic.jl +++ b/src/Runic.jl @@ -305,7 +305,6 @@ function format_node!(ctx::Context, node::Node)::Union{Node, Nothing, NullNode} @return_something insert_delete_mark_newlines(ctx, node) @return_something trim_trailing_whitespace(ctx, node) @return_something format_hex_literals(ctx, node) - @return_something format_oct_literals(ctx, node) @return_something format_float_literals(ctx, node) @return_something spaces_around_operators(ctx, node) @return_something spaces_around_assignments(ctx, node) diff --git a/src/runestone.jl b/src/runestone.jl index aaeae49..3350199 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -67,44 +67,6 @@ function format_hex_literals(ctx::Context, node::Node) return node′ end -function format_oct_literals(ctx::Context, node::Node) - kind(node) === K"OctInt" || return nothing - @assert flags(node) == 0 - @assert is_leaf(node) - spn = span(node) - @assert spn > 2 # 0o prefix + something more - # Padding depends on the value of the literal... - str = String(read_bytes(ctx, node)) - n = tryparse(UInt128, str) - if n === nothing || spn > 45 - # Do nothing: BigInt oct literal - return nothing - end - # Compute the target span - target_span_from_value = - n <= typemax(UInt8) ? 5 : n <= typemax(UInt16) ? 8 : - n <= typemax(UInt32) ? 13 : n <= typemax(UInt64) ? 24 : - n <= typemax(UInt128) ? 45 : error("unreachable") - target_spans = (5, 8, 13, 24, 45) - i = findfirst(x -> x >= spn, target_spans)::Int - target_span_from_source = target_spans[i] - target_span = max(target_span_from_value, target_span_from_source) - if spn == target_span - # Do nothing: correctly formatted oct literal - return nothing - end - # Insert leading zeros - bytes = read_bytes(ctx, node) - while length(bytes) < target_span - insert!(bytes, 3, '0') - end - nb = replace_bytes!(ctx, bytes, spn) - @assert nb == length(bytes) == target_span - # Create new node and return it - node′ = Node(head(node), nb) - return node′ -end - function format_float_literals(ctx::Context, node::Node) kind(node) in KSet"Float Float32" || return nothing @assert flags(node) == 0 diff --git a/test/runtests.jl b/test/runtests.jl index c990082..9209deb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -78,28 +78,6 @@ end ("0x" * z(n) * "1" => "0x" * z(31) * "1" for n in 16:31)..., # Hex BigInt ("0x" * z(n) * "1" => "0x" * z(n) * "1" for n in 32:35)..., - # Octal UInt8 - ("0o" * z(n) * "1" => "0o001" for n in 0:2)..., - "0o377" => "0o377", # typemax(UInt8) - # Octal UInt16 - "0o400" => "0o000400", # typemax(UInt8) + 1 - ("0o" * z(n) * "1" => "0o000001" for n in 3:5)..., - "0o177777" => "0o177777", # typemax(UInt16) - # Octal UInt32 - "0o200000" => "0o00000200000", # typemax(UInt16) + 1 - ("0o" * z(n) * "1" => "0o00000000001" for n in 6:10)..., - "0o37777777777" => "0o37777777777", # typemax(UInt32) - # Octal UInt64 - "0o40000000000" => "0o0000000000040000000000", # typemax(UInt32) + 1 - ("0o" * z(n) * "1" => "0o" * z(21) * "1" for n in 11:21)..., - "0o1777777777777777777777" => "0o1777777777777777777777", # typemax(UInt64) - # Octal UInt128 - "0o2" * z(21) => "0o" * z(21) * "2" * z(21), # typemax(UInt64) + 1 - ("0o" * z(n) * "1" => "0o" * z(42) * "1" for n in 22:42)..., - "0o3" * "7"^42 => "0o3" * "7"^42, # typemax(UInt128) - # Octal BigInt - "0o4" * z(42) => "0o4" * z(42), # typemax(UInt128) + 1 - "0o7" * z(42) => "0o7" * z(42), ] mod = Module() for (a, b) in test_cases