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"
33 type SrcFile = FAST_STRING
40 | RdrAndBindings RdrBinding RdrBinding
42 | RdrTyDecl RdrNameTyDecl
43 | RdrFunctionBinding SrcLine [RdrMatch]
44 | RdrPatternBinding SrcLine [RdrMatch]
45 | RdrClassDecl RdrNameClassDecl
46 | RdrInstDecl RdrNameInstDecl
47 | RdrDefaultDecl RdrNameDefaultDecl
49 -- signatures are mysterious; we can't
50 -- tell if its a Sig or a ClassOpSig,
51 -- so we just save the pieces:
52 | RdrTySig [RdrName] -- vars getting sigs
53 RdrNamePolyType -- the type
56 -- user pragmas come in in a Sig-ish way/form...
57 | RdrSpecValSig [RdrNameSig]
58 | RdrInlineValSig RdrNameSig
59 | RdrDeforestSig RdrNameSig
60 | RdrMagicUnfoldingSig RdrNameSig
61 | RdrSpecInstSig RdrNameSpecInstSig
62 | RdrSpecDataSig RdrNameSpecDataSig
64 type SigConverter = RdrBinding {- a Sig -} -> [RdrNameSig]
78 [(RdrNameHsExpr, RdrNameHsExpr)]
83 Unscramble strings representing oct/dec/hex integer literals:
85 readInteger :: String -> Integer
87 readInteger ('-' : xs) = - (readInteger xs)
88 readInteger ('0' : 'o' : xs) = chk (stoo 0 xs)
89 readInteger ('0' : 'x' : xs) = chk (stox 0 xs)
90 readInteger ['0'] = 0 -- efficiency shortcut?
91 readInteger ['1'] = 1 -- ditto?
92 readInteger xs = chk (stoi 0 xs)
95 chk (i, junk) = panic ("readInteger: junk after reading:"++junk)
97 stoo, stoi, stox :: Integer -> String -> (Integer, String)
99 stoo a (c:cs) | is_oct c = stoo (a*8 + ord_ c - ord_0) cs
102 stoi a (c:cs) | isDigit c = stoi (a*10 + ord_ c - ord_0) cs
105 stox a (c:cs) | isDigit c = stox (a_16_ord_c - ord_0) cs
106 | is_hex c = stox (a_16_ord_c - ord_a + 10) cs
107 | is_Hex c = stox (a_16_ord_c - ord_A + 10) cs
108 where a_16_ord_c = a*16 + ord_ c
111 is_oct c = c >= '0' && c <= '7'
112 is_hex c = c >= 'a' && c <= 'f'
113 is_Hex c = c >= 'A' && c <= 'F'
115 ord_ c = toInteger (ord c)
117 ord_0, ord_a, ord_A :: Integer
118 ord_0 = ord_ '0'; ord_a = ord_ 'a'; ord_A = ord_ 'A'