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 Panic ( panic )
27 import Char ( isDigit, ord )
30 --UNUSED: type RdrId = RdrName
32 type SrcFile = FAST_STRING
39 | RdrAndBindings RdrBinding RdrBinding
40 | RdrTyClDecl RdrNameTyClDecl
41 | RdrValBinding RdrNameMonoBinds -- Pattern or function binding
42 | RdrInstDecl RdrNameInstDecl
43 | RdrDefaultDecl RdrNameDefaultDecl
44 | RdrForeignDecl RdrNameForeignDecl
46 -- signatures are mysterious; we can't
47 -- tell if its a Sig or a ClassOpSig,
48 -- so we just save the pieces:
51 type SigConverter = RdrNameSig -> RdrNameSig
62 Unscramble strings representing oct/dec/hex integer literals:
64 readInteger :: String -> Integer
66 readInteger ('-' : xs) = - (readInteger xs)
67 readInteger ('0' : 'o' : xs) = chk (stoo 0 xs)
68 readInteger ('0' : 'x' : xs) = chk (stox 0 xs)
69 readInteger ['0'] = 0 -- efficiency shortcut?
70 readInteger ['1'] = 1 -- ditto?
71 readInteger xs = chk (stoi 0 xs)
74 chk (i, junk) = panic ("readInteger: junk after reading:"++junk)
76 stoo, stoi, stox :: Integer -> String -> (Integer, String)
78 stoo a (c:cs) | is_oct c = stoo (a*8 + ord_ c - ord_0) cs
81 stoi a (c:cs) | isDigit c = stoi (a*10 + ord_ c - ord_0) cs
84 stox a (c:cs) | isDigit c = stox (a_16_ord_c - ord_0) cs
85 | is_hex c = stox (a_16_ord_c - ord_a + 10) cs
86 | is_Hex c = stox (a_16_ord_c - ord_A + 10) cs
87 where a_16_ord_c = a*16 + ord_ c
90 is_oct c = c >= '0' && c <= '7'
91 is_hex c = c >= 'a' && c <= 'f'
92 is_Hex c = c >= 'A' && c <= 'F'
94 ord_ c = toInteger (ord c)
96 ord_0, ord_a, ord_A :: Integer
97 ord_0 = ord_ '0'; ord_a = ord_ 'a'; ord_A = ord_ 'A'