@@ -4,10 +4,8 @@ This is realy just an extended prelude.
4
4
All the code below is understood to be in the public domain.
5
5
-----------------------------------------------------------------------------
6
6
7
- > module Happy.Grammar.GenUtils (
8
- > mkClosure ,
7
+ > module GenUtils (
9
8
> combinePairs ,
10
- > mapDollarDollar ,
11
9
> str , char , nl , brack , brack' ,
12
10
> interleave , interleave' ,
13
11
> strspace , maybestr ,
@@ -16,28 +14,13 @@ All the code below is understood to be in the public domain.
16
14
> getProgramName
17
15
> ) where
18
16
19
- > import Data.Char (isAlphaNum )
20
17
> import Data.Ord (comparing )
21
18
> import Data.List (sortBy , isSuffixOf )
22
19
> import Control.Monad
23
20
> import System.IO (stderr , hPutStr )
24
21
> import System.Environment
25
22
> import System.Exit (exitWith , ExitCode (.. ))
26
23
27
- % ------------------------------------------------------------------------------
28
-
29
- @mkClosure@ makes a closure, when given a comparison and iteration loop.
30
- Be careful, because if the functional always makes the object different,
31
- This will never terminate.
32
-
33
- > mkClosure :: (a -> a -> Bool ) -> (a -> a ) -> a -> a
34
- > mkClosure eq f = match . iterate f
35
- > where
36
- > match (a: b: _) | a `eq` b = a
37
- > match (_: c) = match c
38
- > match [] = error " Can't happen: match []"
39
-
40
-
41
24
Gofer-like stuff:
42
25
43
26
> combinePairs :: (Ord a ) => [(a ,b )] -> [(a ,[b ])]
@@ -49,27 +32,6 @@ Gofer-like stuff:
49
32
> combine (a: r) = a : combine r
50
33
>
51
34
52
-
53
- Replace $$ with an arbitrary string, being careful to avoid ".." and '.'.
54
-
55
- > mapDollarDollar :: String -> Maybe (String -> String)
56
- > mapDollarDollar code0 = go code0 ""
57
- > where go code acc =
58
- > case code of
59
- > [] -> Nothing
60
- >
61
- > '"' :r -> case reads code :: [(String,String)] of
62
- > [] -> go r ('"':acc)
63
- > (s,r'):_ -> go r' (reverse (show s) ++ acc)
64
- > a:'\' ' :r | isAlphaNum a -> go r ('\' ':a:acc)
65
- > '\' ' :r -> case reads code :: [(Char,String)] of
66
- > [] -> go r ('\' ':acc)
67
- > (c,r'):_ -> go r' (reverse (show c) ++ acc)
68
- > '\\ ':'$ ':r -> go r ('$ ':acc)
69
- > '$ ':'$ ':r -> Just (\repl -> reverse acc ++ repl ++ r)
70
- > c:r -> go r (c:acc)
71
-
72
-
73
35
% -------------------------------------------------------------------------------
74
36
Fast string-building functions.
75
37
0 commit comments