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.
23 #include "HsVersions.h"
27 import BasicTypes ( IfaceFlavour )
29 import SrcLoc ( SrcLoc )
30 import Char ( isDigit, ord )
34 type SrcFile = FAST_STRING
41 | RdrAndBindings RdrBinding RdrBinding
43 | RdrTyDecl RdrNameTyDecl
44 | RdrFunctionBinding SrcLine [RdrMatch]
45 | RdrPatternBinding SrcLine [RdrMatch]
46 | RdrClassDecl RdrNameClassDecl
47 | RdrInstDecl RdrNameInstDecl
48 | RdrDefaultDecl RdrNameDefaultDecl
50 -- signatures are mysterious; we can't
51 -- tell if its a Sig or a ClassOpSig,
52 -- so we just save the pieces:
55 type SigConverter = RdrNameSig -> RdrNameSig
69 [([RdrNameStmt], RdrNameHsExpr)]
74 Unscramble strings representing oct/dec/hex integer literals:
76 readInteger :: String -> Integer
78 readInteger ('-' : xs) = - (readInteger xs)
79 readInteger ('0' : 'o' : xs) = chk (stoo 0 xs)
80 readInteger ('0' : 'x' : xs) = chk (stox 0 xs)
81 readInteger ['0'] = 0 -- efficiency shortcut?
82 readInteger ['1'] = 1 -- ditto?
83 readInteger xs = chk (stoi 0 xs)
86 chk (i, junk) = panic ("readInteger: junk after reading:"++junk)
88 stoo, stoi, stox :: Integer -> String -> (Integer, String)
90 stoo a (c:cs) | is_oct c = stoo (a*8 + ord_ c - ord_0) cs
93 stoi a (c:cs) | isDigit c = stoi (a*10 + ord_ c - ord_0) cs
96 stox a (c:cs) | isDigit c = stox (a_16_ord_c - ord_0) cs
97 | is_hex c = stox (a_16_ord_c - ord_a + 10) cs
98 | is_Hex c = stox (a_16_ord_c - ord_A + 10) cs
99 where a_16_ord_c = a*16 + ord_ c
102 is_oct c = c >= '0' && c <= '7'
103 is_hex c = c >= 'a' && c <= 'f'
104 is_Hex c = c >= 'A' && c <= 'F'
106 ord_ c = toInteger (ord c)
108 ord_0, ord_a, ord_A :: Integer
109 ord_0 = ord_ '0'; ord_a = ord_ 'a'; ord_A = ord_ 'A'