From ac00f77dadd4d447803dd7cab5a36f47365325d0 Mon Sep 17 00:00:00 2001 From: peb Date: Mon, 11 Apr 2005 12:57:45 +0000 Subject: "Committed_by_peb" --- src/GF/Formalism/Symbol.hs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/GF/Formalism/Symbol.hs (limited to 'src/GF/Formalism/Symbol.hs') diff --git a/src/GF/Formalism/Symbol.hs b/src/GF/Formalism/Symbol.hs new file mode 100644 index 000000000..184dd1023 --- /dev/null +++ b/src/GF/Formalism/Symbol.hs @@ -0,0 +1,46 @@ +---------------------------------------------------------------------- +-- | +-- Maintainer : PL +-- Stability : (stable) +-- Portability : (portable) +-- +-- > CVS $Date: 2005/04/11 13:52:50 $ +-- > CVS $Author: peb $ +-- > CVS $Revision: 1.1 $ +-- +-- Basic type declarations and functions to be used in grammar formalisms +----------------------------------------------------------------------------- + + +module GF.Formalism.Symbol where + +import GF.Infra.Print + +------------------------------------------------------------ +-- symbols + +data Symbol c t = Cat c | Tok t + deriving (Eq, Ord, Show) + +symbol :: (c -> a) -> (t -> a) -> Symbol c t -> a +symbol fc ft (Cat cat) = fc cat +symbol fc ft (Tok tok) = ft tok + +mapSymbol :: (c -> d) -> (t -> u) -> Symbol c t -> Symbol d u +mapSymbol fc ft = symbol (Cat . fc) (Tok . ft) + +------------------------------------------------------------ +-- pretty-printing + +instance (Print c, Print t) => Print (Symbol c t) where + prt = symbol prt (simpleShow . prt) + where simpleShow str = "\"" ++ concatMap mkEsc str ++ "\"" + mkEsc '\\' = "\\\\" + mkEsc '\"' = "\\\"" + mkEsc '\n' = "\\n" + mkEsc '\t' = "\\t" + mkEsc chr = [chr] + prtList = prtSep " " + + + -- cgit v1.2.3