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
40 | RdrAndBindings RdrBinding RdrBinding
41 | RdrTyClDecl RdrNameTyClDecl
42 | RdrValBinding RdrNameMonoBinds -- Pattern or function binding
43 | RdrInstDecl RdrNameInstDecl
44 | RdrDefaultDecl RdrNameDefaultDecl
45 | RdrForeignDecl RdrNameForeignDecl
47 -- signatures are mysterious; we can't
48 -- tell if its a Sig or a ClassOpSig,
49 -- so we just save the pieces:
52 type SigConverter = RdrNameSig -> RdrNameSig
63 Unscramble strings representing oct/dec/hex integer literals:
65 readInteger :: String -> Integer
67 readInteger ('-' : xs) = - (readInteger xs)
68 readInteger ('0' : 'o' : xs) = chk (stoo 0 xs)
69 readInteger ('0' : 'x' : xs) = chk (stox 0 xs)
70 readInteger ['0'] = 0 -- efficiency shortcut?
71 readInteger ['1'] = 1 -- ditto?
72 readInteger xs = chk (stoi 0 xs)
75 chk (i, junk) = panic ("readInteger: junk after reading:"++junk)
77 stoo, stoi, stox :: Integer -> String -> (Integer, String)
79 stoo a (c:cs) | is_oct c = stoo (a*8 + ord_ c - ord_0) cs
82 stoi a (c:cs) | isDigit c = stoi (a*10 + ord_ c - ord_0) cs
85 stox a (c:cs) | isDigit c = stox (a_16_ord_c - ord_0) cs
86 | is_hex c = stox (a_16_ord_c - ord_a + 10) cs
87 | is_Hex c = stox (a_16_ord_c - ord_A + 10) cs
88 where a_16_ord_c = a*16 + ord_ c
91 is_oct c = c >= '0' && c <= '7'
92 is_hex c = c >= 'a' && c <= 'f'
93 is_Hex c = c >= 'A' && c <= 'F'
95 ord_ c = toInteger (ord c)
97 ord_0, ord_a, ord_A :: Integer
98 ord_0 = ord_ '0'; ord_a = ord_ 'a'; ord_A = ord_ 'A'