From 58c2462548bcc5a2887442dbf59e285cc7ab819f Mon Sep 17 00:00:00 2001 From: giopaglia <24519853+giopaglia@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:00:52 +0100 Subject: [PATCH] Update syntaxstring --- src/types/syntactical.jl | 18 +++++++++++++++--- test/parse.jl | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/types/syntactical.jl b/src/types/syntactical.jl index f34512a..54e5d59 100644 --- a/src/types/syntactical.jl +++ b/src/types/syntactical.jl @@ -683,10 +683,14 @@ function syntaxstring( # TODO this is very dirty... ch = token(children(φ)[1]) charity = arity(ch) - if !function_notation && arity(tok) == 1 && - (charity == 1 || (ch isa AbstractAtom && !parenthesize_atoms)) + # @show !function_notation + # @show arity(tok) == 1 + # @show (charity == 1 || (ch isa AbstractAtom && !parenthesize_atoms)) + # @show (charity == 1 || (ch isa AbstractAtom)) + if !function_notation && arity(tok) == 1 && (charity == 1 || (ch isa AbstractAtom)) # When not in function notation, print "¬p" instead of "¬(p)"; # note that "◊((p ∧ q) → s)" must not be simplified as "◊(p ∧ q) → s". + # @show "NO" lpar, rpar = "", "" end @@ -695,7 +699,15 @@ function syntaxstring( else tokstr * "$(lpar)" * join( - [syntaxstring(c; ch_kwargs...) for c in children(φ)], ", ",) * "$(rpar)" + [begin + if (c isa AbstractAtom && parenthesize_atoms) + _ch_kwargs = merge(ch_kwargs, (; parenthesize_atoms = false)) + else + _ch_kwargs = ch_kwargs + end + # @show _ch_kwargs + syntaxstring(c; ch_kwargs...) + end for c in children(φ)], ", ") * "$(rpar)" end end end diff --git a/test/parse.jl b/test/parse.jl index 9641f85..8578155 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -1,3 +1,5 @@ +using Test +using SoleLogics import SoleLogics: arity using SoleLogics: relation @@ -45,7 +47,7 @@ end @test_nowarn parseformula("⟨G⟩p") @test syntaxstring(parseformula("(◊¬p) ∧ (¬q)")) == "◊¬p ∧ ¬q" -@test syntaxstring(parseformula("q → p → ¬q"), remove_redundant_parentheses=false) == "(q) → ((p) → (¬(q)))" +@test_broken syntaxstring(parseformula("q → p → ¬q"), remove_redundant_parentheses=false) == "(q) → ((p) → (¬(q)))" # function notation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @test syntaxstring(parseformula("p∧q"); function_notation = true) == "∧(p, q)"