2 ------------------------------------------------------------------
3 -- A primop-table mangling program --
4 ------------------------------------------------------------------
8 #if __GLASGOW_HASKELL__ >= 504
9 import Text.ParserCombinators.Parsec
17 import System ( getArgs )
18 import Maybe ( catMaybes )
20 main = getArgs >>= \args ->
21 if length args /= 1 || head args `notElem` known_args
22 then error ("usage: genprimopcode command < primops.txt > ...\n"
23 ++ " where command is one of\n"
24 ++ unlines (map (" "++) known_args)
28 let pres = parse pTop "" s
30 Left err -> error ("parse error at " ++ (show err))
32 -> myseq (sanityTop p_o_specs) (
36 -> putStr (gen_data_decl p_o_specs)
39 -> putStr (gen_switch_from_attribs
41 "primOpHasSideEffects" p_o_specs)
44 -> putStr (gen_switch_from_attribs
46 "primOpOutOfLine" p_o_specs)
49 -> putStr (gen_switch_from_attribs
51 "commutableOp" p_o_specs)
54 -> putStr (gen_switch_from_attribs
56 "primOpNeedsWrapper" p_o_specs)
59 -> putStr (gen_switch_from_attribs
61 "primOpCanFail" p_o_specs)
64 -> putStr (gen_switch_from_attribs
66 "primOpStrictness" p_o_specs)
69 -> putStr (gen_switch_from_attribs
71 "primOpUsg" p_o_specs)
73 "--primop-primop-info"
74 -> putStr (gen_primop_info p_o_specs)
77 -> putStr (gen_primop_tag p_o_specs)
80 -> putStr (gen_primop_list p_o_specs)
82 "--make-haskell-wrappers"
83 -> putStr (gen_wrappers p_o_specs)
85 "--make-haskell-source"
86 -> putStr (gen_hs_source p_o_specs)
89 -> putStr (gen_latex_doc p_o_specs)
102 "--primop-primop-info",
105 "--make-haskell-wrappers",
106 "--make-haskell-source",
110 ------------------------------------------------------------------
111 -- Code generators -----------------------------------------------
112 ------------------------------------------------------------------
114 gen_hs_source (Info defaults entries)
115 = "module GHC.Prim (\n"
116 ++ unlines (map (("\t" ++) . hdr) entries)
118 ++ unlines (map opt defaults) ++ "-}\n"
119 ++ unlines (map ent entries) ++ "\n\n\n"
120 where opt (OptionFalse n) = n ++ " = False"
121 opt (OptionTrue n) = n ++ " = True"
122 opt (OptionString n v) = n ++ " = { " ++ v ++ "}"
124 hdr s@(Section {}) = sec s
125 hdr o@(PrimOpSpec {}) = wrap (name o) ++ ","
127 ent s@(Section {}) = ""
128 ent o@(PrimOpSpec {}) = spec o
130 sec s = "\n-- * " ++ escape (title s) ++ "\n"
131 ++ (unlines $ map ("-- " ++ ) $ lines $ unlatex $ escape $ "|" ++ desc s) ++ "\n"
133 spec o = comm ++ decl
134 where decl = wrap (name o) ++ " :: " ++ pty (ty o)
135 comm = case (desc o) of
137 d -> "\n" ++ (unlines $ map ("-- " ++ ) $ lines $ unlatex $ escape $ "|" ++ d)
139 pty (TyF t1 t2) = pbty t1 ++ " -> " ++ pty t2
142 pbty (TyApp tc ts) = tc ++ (concat (map (' ':) (map paty ts)))
143 pbty (TyUTup ts) = "(# " ++ (concat (intersperse "," (map pty ts))) ++ " #)"
147 paty t = "(" ++ pty t ++ ")"
149 wrap nm | isLower (head nm) = nm
150 | otherwise = "(" ++ nm ++ ")"
151 unlatex s = case s of
152 '\\':'t':'e':'x':'t':'t':'t':'{':cs -> markup "@" "@" cs
153 '{':'\\':'t':'t':cs -> markup "@" "@" cs
154 c : cs -> c : unlatex cs
156 markup s t cs = s ++ mk (dropWhile isSpace cs)
158 mk ('\n':cs) = ' ' : mk cs
159 mk ('}':cs) = t ++ unlatex cs
160 mk (c:cs) = c : mk cs
161 escape = concatMap (\c -> if c `elem` special then '\\':c:[] else c:[])
162 where special = "/'`\"@<"
164 gen_latex_doc (Info defaults entries)
165 = "\\primopdefaults{"
166 ++ mk_options defaults
168 ++ (concat (map mk_entry entries))
169 where mk_entry (PrimOpSpec {cons=cons,name=name,ty=ty,cat=cat,desc=desc,opts=opts}) =
171 ++ latex_encode cons ++ "}{"
172 ++ latex_encode name ++ "}{"
173 ++ latex_encode (zencode name) ++ "}{"
174 ++ latex_encode (show cat) ++ "}{"
175 ++ latex_encode (mk_source_ty ty) ++ "}{"
176 ++ latex_encode (mk_core_ty ty) ++ "}{"
180 mk_entry (Section {title=title,desc=desc}) =
182 ++ latex_encode title ++ "}{"
184 mk_source_ty t = pty t
185 where pty (TyF t1 t2) = pbty t1 ++ " -> " ++ pty t2
187 pbty (TyApp tc ts) = tc ++ (concat (map (' ':) (map paty ts)))
188 pbty (TyUTup ts) = "(# " ++ (concat (intersperse "," (map pty ts))) ++ " #)"
191 paty t = "(" ++ pty t ++ ")"
193 mk_core_ty t = foralls ++ (pty t)
194 where pty (TyF t1 t2) = pbty t1 ++ " -> " ++ pty t2
196 pbty (TyApp tc ts) = (zencode tc) ++ (concat (map (' ':) (map paty ts)))
197 pbty (TyUTup ts) = (zencode (utuplenm (length ts))) ++ (concat ((map (' ':) (map paty ts))))
199 paty (TyVar tv) = zencode tv
200 paty (TyApp tc []) = zencode tc
201 paty t = "(" ++ pty t ++ ")"
203 utuplenm n = "(#" ++ (replicate (n-1) ',') ++ "#)"
204 foralls = if tvars == [] then "" else "%forall " ++ (tbinds tvars)
207 tbinds ("o":tbs) = "(o::?) " ++ (tbinds tbs)
208 tbinds (tv:tbs) = tv ++ " " ++ (tbinds tbs)
209 tvars_of (TyF t1 t2) = tvars_of t1 `union` tvars_of t2
210 tvars_of (TyApp tc ts) = foldl union [] (map tvars_of ts)
211 tvars_of (TyUTup ts) = foldr union [] (map tvars_of ts)
212 tvars_of (TyVar tv) = [tv]
216 ++ mk_has_side_effects opts ++ "}{"
217 ++ mk_out_of_line opts ++ "}{"
218 ++ mk_commutable opts ++ "}{"
219 ++ mk_needs_wrapper opts ++ "}{"
220 ++ mk_can_fail opts ++ "}{"
221 ++ latex_encode (mk_strictness opts) ++ "}{"
222 ++ latex_encode (mk_usage opts)
225 mk_has_side_effects opts = mk_bool_opt opts "has_side_effects" "Has side effects." "Has no side effects."
226 mk_out_of_line opts = mk_bool_opt opts "out_of_line" "Implemented out of line." "Implemented in line."
227 mk_commutable opts = mk_bool_opt opts "commutable" "Commutable." "Not commutable."
228 mk_needs_wrapper opts = mk_bool_opt opts "needs_wrapper" "Needs wrapper." "Needs no wrapper."
229 mk_can_fail opts = mk_bool_opt opts "can_fail" "Can fail." "Cannot fail."
231 mk_bool_opt opts opt_name if_true if_false =
232 case lookup_attrib opt_name opts of
233 Just (OptionTrue _) -> if_true
234 Just (OptionFalse _) -> if_false
238 case lookup_attrib "strictness" opts of
239 Just (OptionString _ s) -> s -- for now
243 case lookup_attrib "usage" opts of
244 Just (OptionString _ s) -> s -- for now
248 case maybe_tuple cs of
249 Just n -> n -- Tuples go to Z2T etc
250 Nothing -> concat (map encode_ch cs)
252 maybe_tuple "(# #)" = Just("Z1H")
253 maybe_tuple ('(' : '#' : cs) = case count_commas (0::Int) cs of
254 (n, '#' : ')' : cs) -> Just ('Z' : shows (n+1) "H")
256 maybe_tuple "()" = Just("Z0T")
257 maybe_tuple ('(' : cs) = case count_commas (0::Int) cs of
258 (n, ')' : cs) -> Just ('Z' : shows (n+1) "T")
260 maybe_tuple other = Nothing
262 count_commas :: Int -> String -> (Int, String)
263 count_commas n (',' : cs) = count_commas (n+1) cs
264 count_commas n cs = (n,cs)
266 unencodedChar :: Char -> Bool -- True for chars that don't need encoding
267 unencodedChar 'Z' = False
268 unencodedChar 'z' = False
269 unencodedChar c = isAlphaNum c
271 encode_ch :: Char -> String
272 encode_ch c | unencodedChar c = [c] -- Common case first
275 encode_ch '(' = "ZL" -- Needed for things like (,), and (->)
276 encode_ch ')' = "ZR" -- For symmetry with (
296 encode_ch '\'' = "zq"
297 encode_ch '\\' = "zr"
302 encode_ch c = 'z' : shows (ord c) "U"
305 latex_encode (c:cs) | c `elem` "#$%&_^{}" = "\\" ++ c:(latex_encode cs)
306 latex_encode ('~':cs) = "\\verb!~!" ++ (latex_encode cs)
307 latex_encode ('\\':cs) = "$\\backslash$" ++ (latex_encode cs)
308 latex_encode (c:cs) = c:(latex_encode cs)
310 gen_wrappers (Info defaults entries)
311 = "{-# OPTIONS -fno-implicit-prelude #-}\n"
312 -- Dependencies on Prelude must be explicit in libraries/base, but we
313 -- don't need the Prelude here so we add -fno-implicit-prelude.
314 ++ "module GHC.PrimopWrappers where\n"
315 ++ "import qualified GHC.Prim\n"
316 ++ unlines (map f (filter (not.dodgy) (filter is_primop entries)))
318 f spec = let args = map (\n -> "a" ++ show n) [1 .. arity (ty spec)]
319 src_name = wrap (name spec)
320 in "{-# NOINLINE " ++ src_name ++ " #-}\n" ++
321 src_name ++ " " ++ unwords args
322 ++ " = (GHC.Prim." ++ name spec ++ ") " ++ unwords args
323 wrap nm | isLower (head nm) = nm
324 | otherwise = "(" ++ nm ++ ")"
328 [-- C code generator can't handle these
331 -- not interested in parallel support
332 "par#", "parGlobal#", "parLocal#", "parAt#",
333 "parAtAbs#", "parAtRel#", "parAtForNow#"
337 gen_primop_list (Info defaults entries)
339 [ " [" ++ cons first ]
341 map (\pi -> " , " ++ cons pi) rest
344 ) where (first:rest) = filter is_primop entries
346 gen_primop_tag (Info defaults entries)
347 = unlines (max_def : zipWith f primop_entries [1..])
349 primop_entries = filter is_primop entries
350 f i n = "tagOf_PrimOp " ++ cons i
351 ++ " = _ILIT(" ++ show n ++ ") :: FastInt"
352 max_def = "maxPrimOpTag = " ++ show (length primop_entries) ++ " :: Int"
354 gen_data_decl (Info defaults entries)
355 = let conss = map cons (filter is_primop entries)
356 in "data PrimOp\n = " ++ head conss ++ "\n"
357 ++ unlines (map (" | "++) (tail conss))
359 gen_switch_from_attribs :: String -> String -> Info -> String
360 gen_switch_from_attribs attrib_name fn_name (Info defaults entries)
361 = let defv = lookup_attrib attrib_name defaults
362 alts = catMaybes (map mkAlt (filter is_primop entries))
364 getAltRhs (OptionFalse _) = "False"
365 getAltRhs (OptionTrue _) = "True"
366 getAltRhs (OptionString _ s) = s
369 = case lookup_attrib attrib_name (opts po) of
371 Just xx -> Just (fn_name ++ " " ++ cons po ++ " = " ++ getAltRhs xx)
375 Nothing -> error ("gen_switch_from: " ++ attrib_name)
378 ++ fn_name ++ " other = " ++ getAltRhs xx ++ "\n"
380 ------------------------------------------------------------------
381 -- Create PrimOpInfo text from PrimOpSpecs -----------------------
382 ------------------------------------------------------------------
385 gen_primop_info (Info defaults entries)
386 = unlines (map mkPOItext (filter is_primop entries))
388 mkPOItext i = mkPOI_LHS_text i ++ mkPOI_RHS_text i
391 = "primOpInfo " ++ cons i ++ " = "
398 -> "mkCompare " ++ sl_name i ++ ppType t1
402 -> "mkMonadic " ++ sl_name i ++ ppType t1
406 -> "mkDyadic " ++ sl_name i ++ ppType t1
408 -> let (argTys, resTy) = flatTys (ty i)
409 tvs = nub (tvsIn (ty i))
411 "mkGenPrimOp " ++ sl_name i ++ " "
412 ++ listify (map ppTyVar tvs) ++ " "
413 ++ listify (map ppType argTys) ++ " "
414 ++ "(" ++ ppType resTy ++ ")"
416 sl_name i = "FSLIT(\"" ++ name i ++ "\") "
418 ppTyVar "a" = "alphaTyVar"
419 ppTyVar "b" = "betaTyVar"
420 ppTyVar "c" = "gammaTyVar"
421 ppTyVar "s" = "deltaTyVar"
422 ppTyVar "o" = "openAlphaTyVar"
425 ppType (TyApp "Bool" []) = "boolTy"
427 ppType (TyApp "Int#" []) = "intPrimTy"
428 ppType (TyApp "Int32#" []) = "int32PrimTy"
429 ppType (TyApp "Int64#" []) = "int64PrimTy"
430 ppType (TyApp "Char#" []) = "charPrimTy"
431 ppType (TyApp "Word#" []) = "wordPrimTy"
432 ppType (TyApp "Word32#" []) = "word32PrimTy"
433 ppType (TyApp "Word64#" []) = "word64PrimTy"
434 ppType (TyApp "Addr#" []) = "addrPrimTy"
435 ppType (TyApp "Float#" []) = "floatPrimTy"
436 ppType (TyApp "Double#" []) = "doublePrimTy"
437 ppType (TyApp "ByteArr#" []) = "byteArrayPrimTy"
438 ppType (TyApp "RealWorld" []) = "realWorldTy"
439 ppType (TyApp "ThreadId#" []) = "threadIdPrimTy"
440 ppType (TyApp "ForeignObj#" []) = "foreignObjPrimTy"
441 ppType (TyApp "BCO#" []) = "bcoPrimTy"
442 ppType (TyApp "()" []) = "unitTy" -- unitTy is TysWiredIn's name for ()
445 ppType (TyVar "a") = "alphaTy"
446 ppType (TyVar "b") = "betaTy"
447 ppType (TyVar "c") = "gammaTy"
448 ppType (TyVar "s") = "deltaTy"
449 ppType (TyVar "o") = "openAlphaTy"
450 ppType (TyApp "State#" [x]) = "mkStatePrimTy " ++ ppType x
451 ppType (TyApp "MutVar#" [x,y]) = "mkMutVarPrimTy " ++ ppType x
453 ppType (TyApp "MutArr#" [x,y]) = "mkMutableArrayPrimTy " ++ ppType x
456 ppType (TyApp "MutByteArr#" [x]) = "mkMutableByteArrayPrimTy "
459 ppType (TyApp "Array#" [x]) = "mkArrayPrimTy " ++ ppType x
462 ppType (TyApp "Weak#" [x]) = "mkWeakPrimTy " ++ ppType x
463 ppType (TyApp "StablePtr#" [x]) = "mkStablePtrPrimTy " ++ ppType x
464 ppType (TyApp "StableName#" [x]) = "mkStableNamePrimTy " ++ ppType x
466 ppType (TyApp "MVar#" [x,y]) = "mkMVarPrimTy " ++ ppType x
468 ppType (TyApp "TVar#" [x,y]) = "mkTVarPrimTy " ++ ppType x
470 ppType (TyUTup ts) = "(mkTupleTy Unboxed " ++ show (length ts)
472 ++ listify (map ppType ts) ++ ")"
474 ppType (TyF s d) = "(mkFunTy (" ++ ppType s ++ ") (" ++ ppType d ++ "))"
477 = error ("ppType: can't handle: " ++ show other ++ "\n")
479 listify :: [String] -> String
480 listify ss = "[" ++ concat (intersperse ", " ss) ++ "]"
482 flatTys (TyF t1 t2) = case flatTys t2 of (ts,t) -> (t1:ts,t)
483 flatTys other = ([],other)
485 tvsIn (TyF t1 t2) = tvsIn t1 ++ tvsIn t2
486 tvsIn (TyApp tc tys) = concatMap tvsIn tys
487 tvsIn (TyVar tv) = [tv]
488 tvsIn (TyUTup tys) = concatMap tvsIn tys
490 arity = length . fst . flatTys
493 ------------------------------------------------------------------
494 -- Abstract syntax -----------------------------------------------
495 ------------------------------------------------------------------
497 -- info for all primops; the totality of the info in primops.txt(.pp)
499 = Info [Option] [Entry] -- defaults, primops
502 -- info for one primop
504 = PrimOpSpec { cons :: String, -- PrimOp name
505 name :: String, -- name in prog text
507 cat :: Category, -- category
508 desc :: String, -- description
509 opts :: [Option] } -- default overrides
510 | Section { title :: String, -- section title
511 desc :: String } -- description
514 is_primop (PrimOpSpec _ _ _ _ _ _) = True
517 -- a binding of property to value
519 = OptionFalse String -- name = False
520 | OptionTrue String -- name = True
521 | OptionString String String -- name = { ... unparsed stuff ... }
524 -- categorises primops
526 = Dyadic | Monadic | Compare | GenPrimOp
534 | TyUTup [Ty] -- unboxed tuples; just a TyCon really,
535 -- but convenient like this
542 ------------------------------------------------------------------
543 -- Sanity checking -----------------------------------------------
544 ------------------------------------------------------------------
546 {- Do some simple sanity checks:
547 * all the default field names are unique
548 * for each PrimOpSpec, all override field names are unique
549 * for each PrimOpSpec, all overriden field names
550 have a corresponding default value
551 * that primop types correspond in certain ways to the
552 Category: eg if Comparison, the type must be of the form
554 Dies with "error" if there's a problem, else returns ().
557 myseqAll (():ys) x = myseqAll ys x
560 sanityTop :: Info -> ()
561 sanityTop (Info defs entries)
562 = let opt_names = map get_attrib_name defs
563 primops = filter is_primop entries
565 if length opt_names /= length (nub opt_names)
566 then error ("non-unique default attribute names: " ++ show opt_names ++ "\n")
567 else myseqAll (map (sanityPrimOp opt_names) primops) ()
569 sanityPrimOp def_names p
570 = let p_names = map get_attrib_name (opts p)
572 = length p_names == length (nub p_names)
573 && all (`elem` def_names) p_names
574 ty_ok = sane_ty (cat p) (ty p)
577 then error ("attribute names are non-unique or have no default in\n" ++
578 "info for primop " ++ cons p ++ "\n")
581 then error ("type of primop " ++ cons p ++ " doesn't make sense w.r.t" ++
582 " category " ++ show (cat p) ++ "\n")
585 sane_ty Compare (TyF t1 (TyF t2 td))
586 | t1 == t2 && td == TyApp "Bool" [] = True
587 sane_ty Monadic (TyF t1 td)
589 sane_ty Dyadic (TyF t1 (TyF t2 td))
590 | t1 == t2 && t2 == t2 = True
591 sane_ty GenPrimOp any_old_thing
596 get_attrib_name (OptionFalse nm) = nm
597 get_attrib_name (OptionTrue nm) = nm
598 get_attrib_name (OptionString nm _) = nm
600 lookup_attrib nm [] = Nothing
601 lookup_attrib nm (a:as)
602 = if get_attrib_name a == nm then Just a else lookup_attrib nm as
604 ------------------------------------------------------------------
605 -- The parser ----------------------------------------------------
606 ------------------------------------------------------------------
608 -- Due to lack of proper lexing facilities, a hack to zap any
611 pTop = then4 (\_ ds es _ -> Info ds es)
612 pCommentAndWhitespace pDefaults (many pEntry)
613 (lit "thats_all_folks")
615 pEntry :: Parser Entry
617 = alts [pPrimOpSpec, pSection]
619 pSection :: Parser Entry
620 pSection = then3 (\_ n d -> Section {title = n, desc = d})
621 (lit "section") stringLiteral pDesc
623 pDefaults :: Parser [Option]
624 pDefaults = then2 sel22 (lit "defaults") (many pOption)
626 pOption :: Parser Option
629 then3 (\nm eq ff -> OptionFalse nm) pName (lit "=") (lit "False"),
630 then3 (\nm eq tt -> OptionTrue nm) pName (lit "=") (lit "True"),
631 then3 (\nm eq zz -> OptionString nm zz)
632 pName (lit "=") pStuffBetweenBraces
635 pPrimOpSpec :: Parser Entry
637 = then7 (\_ c n k t d o -> PrimOpSpec { cons = c, name = n, ty = t,
638 cat = k, desc = d, opts = o } )
639 (lit "primop") pConstructor stringLiteral
640 pCategory pType pDesc pOptions
642 pOptions :: Parser [Option]
643 pOptions = optdef [] (then2 sel22 (lit "with") (many pOption))
645 pCategory :: Parser Category
648 apply (const Dyadic) (lit "Dyadic"),
649 apply (const Monadic) (lit "Monadic"),
650 apply (const Compare) (lit "Compare"),
651 apply (const GenPrimOp) (lit "GenPrimOp")
654 pDesc :: Parser String
655 pDesc = optdef "" pStuffBetweenBraces
657 pStuffBetweenBraces :: Parser String
663 return (concat ass) )
665 pInsides :: Parser String
668 stuff <- many pInsides
670 return ("{" ++ (concat stuff) ++ "}"))
672 (do c <- satisfy (/= '}')
682 pType = then2 (\t maybe_tt -> case maybe_tt of
686 (opt (then2 sel22 (lit "->") pType))
689 paT = alts [ then2 TyApp pTycon (many ppT),
691 then3 sel23 (lit "(") pType (lit ")"),
695 -- the magic bit in the middle is: T (,T)* so to speak
697 = then3 (\ _ ts _ -> TyUTup ts)
699 (then2 (:) pType (many (then2 sel22 (lit ",") pType)))
703 ppT = alts [apply TyVar pTyvar,
704 apply (\tc -> TyApp tc []) pTycon
707 pTyvar = sat (`notElem` ["section","primop","with"]) pName
708 pTycon = alts [pConstructor, lexeme (string "()")]
709 pName = lexeme (then2 (:) lower (many isIdChar))
710 pConstructor = lexeme (then2 (:) upper (many isIdChar))
712 isIdChar = satisfy (`elem` idChars)
713 idChars = ['a' .. 'z'] ++ ['A' .. 'Z'] ++ ['0' .. '9'] ++ "#_"
721 ------------------------------------------------------------------
722 -- Helpful additions to Daan's parser stuff ----------------------
723 ------------------------------------------------------------------
726 alts (p1:p2:ps) = (try p1) <|> alts (p2:ps)
729 = do x1 <- p1 ; x2 <- p2 ; return (f x1 x2)
731 = do x1 <- p1 ; x2 <- p2 ; x3 <- p3 ; return (f x1 x2 x3)
733 = do x1 <- p1 ; x2 <- p2 ; x3 <- p3 ; x4 <- p4 ; return (f x1 x2 x3 x4)
734 then5 f p1 p2 p3 p4 p5
735 = do x1 <- p1 ; x2 <- p2 ; x3 <- p3 ; x4 <- p4 ; x5 <- p5
736 return (f x1 x2 x3 x4 x5)
737 then6 f p1 p2 p3 p4 p5 p6
738 = do x1 <- p1 ; x2 <- p2 ; x3 <- p3 ; x4 <- p4 ; x5 <- p5 ; x6 <- p6
739 return (f x1 x2 x3 x4 x5 x6)
740 then7 f p1 p2 p3 p4 p5 p6 p7
741 = do x1 <- p1 ; x2 <- p2 ; x3 <- p3 ; x4 <- p4 ; x5 <- p5 ; x6 <- p6 ; x7 <- p7
742 return (f x1 x2 x3 x4 x5 x6 x7)
744 = (do x <- p; return (Just x)) <|> return Nothing
746 = (do x <- p; return x) <|> return d
751 apply f p = liftM f p
753 -- Hacks for zapping whitespace and comments, unfortunately needed
754 -- because Daan won't let us have a lexer before the parser :-(
755 lexeme :: Parser p -> Parser p
756 lexeme p = then2 sel12 p pCommentAndWhitespace
758 lit :: String -> Parser ()
759 lit s = apply (const ()) (lexeme (string s))
761 pCommentAndWhitespace :: Parser ()
762 pCommentAndWhitespace
763 = apply (const ()) (many (alts [pLineComment,
764 apply (const ()) (satisfy isSpace)]))
768 pLineComment :: Parser ()
770 = try (then3 (\_ _ _ -> ()) (string "--") (many (satisfy (/= '\n'))) (char '\n'))
772 stringLiteral :: Parser String
773 stringLiteral = lexeme (
774 do { between (char '"')
775 (char '"' <?> "end of string")
778 <?> "literal string")
782 ------------------------------------------------------------------
784 ------------------------------------------------------------------