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"
26 IMPORT_1_3(Char(isDigit))
31 import SrcLoc ( SrcLoc )
33 #ifdef REALLY_HASKELL_1_3
34 ord = fromEnum :: Char -> Int
39 type SrcFile = FAST_STRING
46 | RdrAndBindings RdrBinding RdrBinding
48 | RdrTyDecl RdrNameTyDecl
49 | RdrFunctionBinding SrcLine [RdrMatch]
50 | RdrPatternBinding SrcLine [RdrMatch]
51 | RdrClassDecl RdrNameClassDecl
52 | RdrInstDecl RdrNameInstDecl
53 | RdrDefaultDecl RdrNameDefaultDecl
55 -- signatures are mysterious; we can't
56 -- tell if its a Sig or a ClassOpSig,
57 -- so we just save the pieces:
58 | RdrTySig [RdrName] -- vars getting sigs
59 RdrNameHsType -- the type
62 -- user pragmas come in in a Sig-ish way/form...
63 | RdrSpecValSig [RdrNameSig]
64 | RdrInlineValSig RdrNameSig
65 | RdrDeforestSig RdrNameSig
66 | RdrMagicUnfoldingSig RdrNameSig
67 | RdrSpecInstSig RdrNameSpecInstSig
68 | RdrSpecDataSig RdrNameSpecDataSig
70 type SigConverter = RdrBinding {- a Sig -} -> [RdrNameSig]
84 [([RdrNameStmt], RdrNameHsExpr)]
89 Unscramble strings representing oct/dec/hex integer literals:
91 readInteger :: String -> Integer
93 readInteger ('-' : xs) = - (readInteger xs)
94 readInteger ('0' : 'o' : xs) = chk (stoo 0 xs)
95 readInteger ('0' : 'x' : xs) = chk (stox 0 xs)
96 readInteger ['0'] = 0 -- efficiency shortcut?
97 readInteger ['1'] = 1 -- ditto?
98 readInteger xs = chk (stoi 0 xs)
101 chk (i, junk) = panic ("readInteger: junk after reading:"++junk)
103 stoo, stoi, stox :: Integer -> String -> (Integer, String)
105 stoo a (c:cs) | is_oct c = stoo (a*8 + ord_ c - ord_0) cs
108 stoi a (c:cs) | isDigit c = stoi (a*10 + ord_ c - ord_0) cs
111 stox a (c:cs) | isDigit c = stox (a_16_ord_c - ord_0) cs
112 | is_hex c = stox (a_16_ord_c - ord_a + 10) cs
113 | is_Hex c = stox (a_16_ord_c - ord_A + 10) cs
114 where a_16_ord_c = a*16 + ord_ c
117 is_oct c = c >= '0' && c <= '7'
118 is_hex c = c >= 'a' && c <= 'f'
119 is_Hex c = c >= 'A' && c <= 'F'
121 ord_ c = toInteger (ord c)
123 ord_0, ord_a, ord_A :: Integer
124 ord_0 = ord_ '0'; ord_a = ord_ 'a'; ord_A = ord_ 'A'