diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-06-25 16:54:35 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-06-25 16:54:35 +0000 |
| commit | e9e80fc389365e24d4300d7d5390c7d833a96c50 (patch) | |
| tree | f0b58473adaa670bd8fc52ada419d8cad470ee03 /src/PGF/Raw/Print.hs | |
| parent | b96b36f43de3e2f8b58d5f539daa6f6d47f25870 (diff) | |
changed names of resource-1.3; added a note on homepage on release
Diffstat (limited to 'src/PGF/Raw/Print.hs')
| -rw-r--r-- | src/PGF/Raw/Print.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/PGF/Raw/Print.hs b/src/PGF/Raw/Print.hs new file mode 100644 index 000000000..d34adbc2b --- /dev/null +++ b/src/PGF/Raw/Print.hs @@ -0,0 +1,35 @@ +module PGF.Raw.Print (printTree) where + +import PGF.CId +import PGF.Raw.Abstract + +import Data.List (intersperse) +import Numeric (showFFloat) +import qualified Data.ByteString.Char8 as BS + +printTree :: Grammar -> String +printTree g = prGrammar g "" + +prGrammar :: Grammar -> ShowS +prGrammar (Grm xs) = prRExpList xs + +prRExp :: Int -> RExp -> ShowS +prRExp _ (App x []) = showString x +prRExp n (App x xs) = p (showString x . showChar ' ' . prRExpList xs) + where p s = if n == 0 then s else showChar '(' . s . showChar ')' +prRExp _ (AInt x) = shows x +prRExp _ (AStr x) = showChar '"' . concatS (map mkEsc x) . showChar '"' +prRExp _ (AFlt x) = showFFloat Nothing x +prRExp _ AMet = showChar '?' + +mkEsc :: Char -> ShowS +mkEsc s = case s of + '"' -> showString "\\\"" + '\\' -> showString "\\\\" + _ -> showChar s + +prRExpList :: [RExp] -> ShowS +prRExpList = concatS . intersperse (showChar ' ') . map (prRExp 1) + +concatS :: [ShowS] -> ShowS +concatS = foldr (.) id |
