Commit 59534b80 authored by Simon Marlow's avatar Simon Marlow

Update to work with Alex 3.0: basically disabling Alex's new Unicode

support because we have our own, and defining alexGetByte instead of
alexGetChar (actually we also define alexGetChar, for backwards
compatibility).
parent 8feb2813
......@@ -517,9 +517,12 @@ if test ! -f compiler/cmm/CmmLex.hs || test ! -f compiler/parser/Lexer.hs
then
FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[2.1.0],
[AC_MSG_ERROR([Alex version 2.1.0 or later is required to compile GHC.])])[]
FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-ge],[3.0],
[Alex3=YES],[Alex3=NO])
fi
AlexVersion=$fptools_cv_alex_version;
AC_SUBST(AlexVersion)
AC_SUBST(Alex3)
])
......
......@@ -33,6 +33,9 @@ import FastString
import Ctype
import Util
--import TRACE
import Data.Word
import Data.Char
}
$whitechar = [\ \t\n\r\f\v\xa0] -- \xa0 is Unicode no-break space
......@@ -320,11 +323,19 @@ type AlexInput = (RealSrcLoc,StringBuffer)
alexInputPrevChar :: AlexInput -> Char
alexInputPrevChar (_,s) = prevChar s '\n'
-- backwards compatibility for Alex 2.x
alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
alexGetChar (loc,s)
alexGetChar inp = case alexGetByte inp of
Nothing -> Nothing
Just (b,i) -> c `seq` Just (c,i)
where c = chr $ fromIntegral b
alexGetByte :: AlexInput -> Maybe (Word8,AlexInput)
alexGetByte (loc,s)
| atEnd s = Nothing
| otherwise = c `seq` loc' `seq` s' `seq` Just (c, (loc', s'))
where c = currentChar s
| otherwise = b `seq` loc' `seq` s' `seq` Just (b, (loc', s'))
where c = currentChar s
b = fromIntegral $ ord $ c
loc' = advanceSrcLoc loc c
s' = stepOn s
......
......@@ -80,6 +80,7 @@ import Data.Maybe
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Ratio
import Data.Word
}
$unispace = \x05 -- Trick Alex into handling Unicode. See alexGetChar.
......@@ -1576,14 +1577,22 @@ data AlexInput = AI RealSrcLoc StringBuffer
alexInputPrevChar :: AlexInput -> Char
alexInputPrevChar (AI _ buf) = prevChar buf '\n'
-- backwards compatibility for Alex 2.x
alexGetChar :: AlexInput -> Maybe (Char,AlexInput)
alexGetChar (AI loc s)
alexGetChar inp = case alexGetByte inp of
Nothing -> Nothing
Just (b,i) -> c `seq` Just (c,i)
where c = chr $ fromIntegral b
alexGetByte :: AlexInput -> Maybe (Word8,AlexInput)
alexGetByte (AI loc s)
| atEnd s = Nothing
| otherwise = adj_c `seq` loc' `seq` s' `seq`
| otherwise = byte `seq` loc' `seq` s' `seq`
--trace (show (ord c)) $
Just (adj_c, (AI loc' s'))
Just (byte, (AI loc' s'))
where (c,s') = nextChar s
loc' = advanceSrcLoc loc c
byte = fromIntegral $ ord adj_c
non_graphic = '\x0'
upper = '\x1'
......
......@@ -760,10 +760,17 @@ SRC_HAPPY_OPTS = -agc --strict
#
ALEX = @AlexCmd@
ALEX_VERSION = @AlexVersion@
Alex3 = @Alex3@
#
# Options to pass to Happy when we're going to compile the output with GHC
#
ifeq "$(Alex3)" "YES"
# We aren't using the Unicode support in Alex 3.0 yet, in fact we do our own
# Unicode handling, so diable Alex's.
SRC_ALEX_OPTS = -g --latin1
else
SRC_ALEX_OPTS = -g
endif
# Should we build haddock docs?
HADDOCK_DOCS = YES
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment