2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[PrefixSyn]{``Prefix-form'' syntax}
6 This module contains an algebraic data type into which a prefix form
7 string from the current Haskell parser is converted. Given in an
8 order that follows the \tr{Prefix_Form} document.
11 #include "HsVersions.h"
32 type RdrId = ProtoName
34 type SrcFile = FAST_STRING
35 type SrcFun = ProtoName
41 | RdrAndBindings RdrBinding RdrBinding
43 | RdrTyDecl ProtoNameTyDecl
44 | RdrFunctionBinding SrcLine [RdrMatch]
45 | RdrPatternBinding SrcLine [RdrMatch]
46 | RdrClassDecl ProtoNameClassDecl
47 | RdrInstDecl ProtoNameInstDecl
48 | RdrDefaultDecl ProtoNameDefaultDecl
49 | RdrIfaceImportDecl (IfaceImportDecl ProtoName)
50 | RdrIfaceFixities [ProtoNameFixityDecl]
52 -- signatures are mysterious; we can't
53 -- tell if its a Sig or a ClassOpSig,
54 -- so we just save the pieces:
55 | RdrTySig [ProtoName] -- vars getting sigs
56 ProtoNamePolyType -- the type
57 RdrTySigPragmas -- val/class-op pragmas
60 -- user pragmas come in in a Sig-ish way/form...
61 | RdrSpecValSig [ProtoNameSig]
62 | RdrInlineValSig ProtoNameSig
63 | RdrDeforestSig ProtoNameSig
64 | RdrMagicUnfoldingSig ProtoNameSig
65 | RdrSpecInstSig ProtoNameSpecInstSig
66 | RdrSpecDataSig ProtoNameSpecDataSig
70 | RdrGenPragmas ProtoNameGenPragmas
71 | RdrClassOpPragmas ProtoNameClassOpPragmas
73 type SigConverter = RdrBinding {- a RdrTySig... -} -> [ProtoNameSig]
87 [(ProtoNameHsExpr, ProtoNameHsExpr)]
92 Unscramble strings representing oct/dec/hex integer literals:
94 readInteger :: String -> Integer
96 readInteger ('-' : xs) = - (readInteger xs)
97 readInteger ('0' : 'o' : xs) = chk (stoo 0 xs)
98 readInteger ('0' : 'x' : xs) = chk (stox 0 xs)
99 readInteger ['0'] = 0 -- efficiency shortcut?
100 readInteger ['1'] = 1 -- ditto?
101 readInteger xs = chk (stoi 0 xs)
104 chk (i, junk) = panic ("readInteger: junk after reading:"++junk)
106 stoo, stoi, stox :: Integer -> String -> (Integer, String)
108 stoo a (c:cs) | is_oct c = stoo (a*8 + ord_ c - ord_0) cs
111 stoi a (c:cs) | isDigit c = stoi (a*10 + ord_ c - ord_0) cs
114 stox a (c:cs) | isDigit c = stox (a_16_ord_c - ord_0) cs
115 | is_hex c = stox (a_16_ord_c - ord_a + 10) cs
116 | is_Hex c = stox (a_16_ord_c - ord_A + 10) cs
117 where a_16_ord_c = a*16 + ord_ c
120 is_oct c = c >= '0' && c <= '7'
121 is_hex c = c >= 'a' && c <= 'f'
122 is_Hex c = c >= 'A' && c <= 'F'
124 ord_ c = toInteger (ord c)
126 ord_0, ord_a, ord_A :: Integer
127 ord_0 = ord_ '0'; ord_a = ord_ 'a'; ord_A = ord_ 'A'