Commit 2d655d48 authored by Michael Hanus 's avatar Michael Hanus

Improves term printing for infix operators

parent 859a13a7
Pipeline #257 failed with stages
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
--- also defines other structures, like term equations. --- also defines other structures, like term equations.
--- ---
--- @author Jan-Hendrik Matthes --- @author Jan-Hendrik Matthes
--- @version August 2016 --- @version November 2018
--- @category algorithm --- @category algorithm
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
...@@ -18,9 +18,10 @@ module Rewriting.Term ...@@ -18,9 +18,10 @@ module Rewriting.Term
, mapTerm, eqConsPattern , mapTerm, eqConsPattern
) where ) where
import FiniteMap (listToFM, lookupFM) import Char ( isAlphaNum )
import List (nub, intercalate, maximum, minimum) import FiniteMap ( listToFM, lookupFM )
import Maybe (fromMaybe) import List ( nub, intercalate, maximum, minimum )
import Maybe ( fromMaybe )
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
-- Representation of first-order terms and term equations -- Representation of first-order terms and term equations
...@@ -62,13 +63,17 @@ showTerm :: (f -> String) -> Term f -> String ...@@ -62,13 +63,17 @@ showTerm :: (f -> String) -> Term f -> String
showTerm s = showTerm' False showTerm s = showTerm' False
where where
showTerm' _ (TermVar v) = showVarIdx v showTerm' _ (TermVar v) = showVarIdx v
showTerm' b (TermCons c ts) showTerm' b (TermCons c ts) = case ts of
= case ts of [] -> cstr
[] -> s c [l, r] -> if any isAlphaNum cstr
[l, r] -> parensIf b ((showTerm' True l) ++ " " ++ (s c) ++ " " then prefixString -- no infix notation
++ (showTerm' True r)) else parensIf b (showTerm' True l ++ " " ++ cstr ++ " " ++
_ -> (s c) ++ "(" showTerm' True r)
++ (intercalate "," (map (showTerm' False) ts)) ++ ")" _ -> prefixString
where
cstr = s c
prefixString = cstr ++ "("
++ intercalate "," (map (showTerm' False) ts) ++ ")"
--- Transforms a term equation into a string representation. --- Transforms a term equation into a string representation.
showTermEq :: (f -> String) -> TermEq f -> String showTermEq :: (f -> String) -> TermEq f -> String
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment