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))
32 #ifdef REALLY_HASKELL_1_3
33 ord = fromEnum :: Char -> Int
38 type SrcFile = FAST_STRING
45 | RdrAndBindings RdrBinding RdrBinding
47 | RdrTyDecl RdrNameTyDecl
48 | RdrFunctionBinding SrcLine [RdrMatch]
49 | RdrPatternBinding SrcLine [RdrMatch]
50 | RdrClassDecl RdrNameClassDecl
51 | RdrInstDecl RdrNameInstDecl
52 | RdrDefaultDecl RdrNameDefaultDecl
54 -- signatures are mysterious; we can't
55 -- tell if its a Sig or a ClassOpSig,
56 -- so we just save the pieces:
57 | RdrTySig [RdrName] -- vars getting sigs
58 RdrNamePolyType -- the type
61 -- user pragmas come in in a Sig-ish way/form...
62 | RdrSpecValSig [RdrNameSig]
63 | RdrInlineValSig RdrNameSig
64 | RdrDeforestSig RdrNameSig
65 | RdrMagicUnfoldingSig RdrNameSig
66 | RdrSpecInstSig RdrNameSpecInstSig
67 | RdrSpecDataSig RdrNameSpecDataSig
69 type SigConverter = RdrBinding {- a Sig -} -> [RdrNameSig]
83 [(RdrNameHsExpr, RdrNameHsExpr)]
88 Unscramble strings representing oct/dec/hex integer literals:
90 readInteger :: String -> Integer
92 readInteger ('-' : xs) = - (readInteger xs)
93 readInteger ('0' : 'o' : xs) = chk (stoo 0 xs)
94 readInteger ('0' : 'x' : xs) = chk (stox 0 xs)
95 readInteger ['0'] = 0 -- efficiency shortcut?
96 readInteger ['1'] = 1 -- ditto?
97 readInteger xs = chk (stoi 0 xs)
100 chk (i, junk) = panic ("readInteger: junk after reading:"++junk)
102 stoo, stoi, stox :: Integer -> String -> (Integer, String)
104 stoo a (c:cs) | is_oct c = stoo (a*8 + ord_ c - ord_0) cs
107 stoi a (c:cs) | isDigit c = stoi (a*10 + ord_ c - ord_0) cs
110 stox a (c:cs) | isDigit c = stox (a_16_ord_c - ord_0) cs
111 | is_hex c = stox (a_16_ord_c - ord_a + 10) cs
112 | is_Hex c = stox (a_16_ord_c - ord_A + 10) cs
113 where a_16_ord_c = a*16 + ord_ c
116 is_oct c = c >= '0' && c <= '7'
117 is_hex c = c >= 'a' && c <= 'f'
118 is_Hex c = c >= 'A' && c <= 'F'
120 ord_ c = toInteger (ord c)
122 ord_0, ord_a, ord_A :: Integer
123 ord_0 = ord_ '0'; ord_a = ord_ 'a'; ord_A = ord_ 'A'