2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
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.
22 #include "HsVersions.h"
26 import RdrName ( RdrName )
27 import Panic ( panic )
28 import Char ( isDigit, ord )
31 --UNUSED: type RdrId = RdrName
33 type SrcFile = FAST_STRING
39 = -- On input we use the Empty/And form rather than a list
41 | RdrAndBindings RdrBinding RdrBinding
43 -- Value bindings havn't been united with their
45 | RdrValBinding RdrNameMonoBinds
47 -- Signatures are mysterious; we can't
48 -- tell if its a Sig or a ClassOpSig,
49 -- so we just save the pieces:
52 -- The remainder all fit into the main HsDecl form
53 | RdrHsDecl RdrNameHsDecl
55 type SigConverter = RdrNameSig -> RdrNameSig
66 Unscramble strings representing oct/dec/hex integer literals:
68 readInteger :: String -> Integer
70 readInteger ('-' : xs) = - (readInteger xs)
71 readInteger ('0' : 'o' : xs) = chk (stoo 0 xs)
72 readInteger ('0' : 'x' : xs) = chk (stox 0 xs)
73 readInteger ['0'] = 0 -- efficiency shortcut?
74 readInteger ['1'] = 1 -- ditto?
75 readInteger xs = chk (stoi 0 xs)
78 chk (i, junk) = panic ("readInteger: junk after reading:"++junk)
80 stoo, stoi, stox :: Integer -> String -> (Integer, String)
82 stoo a (c:cs) | is_oct c = stoo (a*8 + ord_ c - ord_0) cs
85 stoi a (c:cs) | isDigit c = stoi (a*10 + ord_ c - ord_0) cs
88 stox a (c:cs) | isDigit c = stox (a_16_ord_c - ord_0) cs
89 | is_hex c = stox (a_16_ord_c - ord_a + 10) cs
90 | is_Hex c = stox (a_16_ord_c - ord_A + 10) cs
91 where a_16_ord_c = a*16 + ord_ c
94 is_oct c = c >= '0' && c <= '7'
95 is_hex c = c >= 'a' && c <= 'f'
96 is_Hex c = c >= 'A' && c <= 'F'
98 ord_ c = toInteger (ord c)
100 ord_0, ord_a, ord_A :: Integer
101 ord_0 = ord_ '0'; ord_a = ord_ 'a'; ord_A = ord_ 'A'