Skip to content

Commit

Permalink
Update syntaxstring
Browse files Browse the repository at this point in the history
  • Loading branch information
giopaglia committed Jan 8, 2025
1 parent 0f7e642 commit 58c2462
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/types/syntactical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/parse.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Test
using SoleLogics
import SoleLogics: arity

using SoleLogics: relation
Expand Down Expand Up @@ -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)"
Expand Down

0 comments on commit 58c2462

Please sign in to comment.