From 009cac0a2bf64711f57a4c541f93f98bd173a8b3 Mon Sep 17 00:00:00 2001 From: Dominique Luna Date: Fri, 27 Oct 2023 17:53:28 -0400 Subject: [PATCH] fix #769 --- src/fst.jl | 4 ++++ src/styles/blue/pretty.jl | 2 +- src/styles/default/pretty.jl | 2 +- src/styles/sciml/pretty.jl | 2 +- test/issues.jl | 7 +++++++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/fst.jl b/src/fst.jl index 7f68128d1..e8f8502bc 100644 --- a/src/fst.jl +++ b/src/fst.jl @@ -1179,3 +1179,7 @@ Checks if the binary operation is a dot operation (e.g. `x.y`, `x..z`, `x...z`). function is_dot_op(x::CSTParser.EXPR) op_kind(x) in (Tokens.DDDOT, Tokens.DDOT, Tokens.DDOTS) end + +function is_isa(x::CSTParser.EXPR) + CSTParser.isoperator(x) && x.val == "isa" +end diff --git a/src/styles/blue/pretty.jl b/src/styles/blue/pretty.jl index a225236de..5c01725d0 100644 --- a/src/styles/blue/pretty.jl +++ b/src/styles/blue/pretty.jl @@ -145,7 +145,7 @@ function p_binaryopcall( add_node!(t, Whitespace(1), s) add_node!(t, pretty(style, op, s), s, join_lines = true) nest ? add_node!(t, Placeholder(1), s) : add_node!(t, Whitespace(1), s) - elseif !(CSTParser.is_in(op) || CSTParser.is_elof(op)) && ( + elseif !(CSTParser.is_in(op) || CSTParser.is_elof(op) || is_isa(op)) && ( nospace || ( !CSTParser.is_anon_func(op) && precedence(op) in ( CSTParser.RationalOp, diff --git a/src/styles/default/pretty.jl b/src/styles/default/pretty.jl index 4efde5b95..585ac53ee 100644 --- a/src/styles/default/pretty.jl +++ b/src/styles/default/pretty.jl @@ -1602,7 +1602,7 @@ function p_binaryopcall( add_node!(t, Whitespace(1), s) add_node!(t, pretty(style, op, s), s, join_lines = true) nest ? add_node!(t, Placeholder(1), s) : add_node!(t, Whitespace(1), s) - elseif !(CSTParser.is_in(op) || CSTParser.is_elof(op)) && ( + elseif !(CSTParser.is_in(op) || CSTParser.is_elof(op) || is_isa(op)) && ( nospace || ( !CSTParser.is_anon_func(op) && precedence(op) in (CSTParser.PowerOp, CSTParser.DeclarationOp, CSTParser.DotOp) diff --git a/src/styles/sciml/pretty.jl b/src/styles/sciml/pretty.jl index cdd37a5b9..cfa922e5c 100644 --- a/src/styles/sciml/pretty.jl +++ b/src/styles/sciml/pretty.jl @@ -134,7 +134,7 @@ function p_macrocall(ys::SciMLStyle, cst::CSTParser.EXPR, s::State) # # No: # `@parameters a = a b = b` - n = pretty(style, a, s, nospace = nospace) + n = pretty(style, a, s; nospace = nospace) if CSTParser.ismacroname(a) add_node!(t, n, s, join_lines = true) if length(args) > 0 diff --git a/test/issues.jl b/test/issues.jl index baf4292cf..d97d5eae4 100644 --- a/test/issues.jl +++ b/test/issues.jl @@ -1763,4 +1763,11 @@ s1 = format_text(s, MinimalStyle()) @test format_text(s1, MinimalStyle()) == s end + + @testset "769" begin + s = raw""" + @assert x isa Tuple \"msg\" + """ + @test format_text(s, SciMLStyle()) == s + end end