diff --git a/alex/AlexTemplate-ghc-nopred b/alex/AlexTemplate-ghc-nopred index a6a1711..bdf663b 100644 --- a/alex/AlexTemplate-ghc-nopred +++ b/alex/AlexTemplate-ghc-nopred @@ -1,23 +1,12 @@ {-# LINE 1 "templates/GenericTemplate.hs" #-} -{-# LINE 1 "templates/GenericTemplate.hs" #-} -{-# LINE 1 "" #-} -{-# LINE 10 "" #-} -# 1 "/usr/include/stdc-predef.h" 1 3 4 - -# 17 "/usr/include/stdc-predef.h" 3 4 - - - - - - - - - - - - +-- ----------------------------------------------------------------------------- +-- ALEX TEMPLATE +-- +-- This code is in the PUBLIC DOMAIN; you may copy it freely and use +-- it for any purpose whatsoever. +-- ----------------------------------------------------------------------------- +-- INTERNALS and main scanner engine @@ -35,6 +24,14 @@ +-- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex. +#if __GLASGOW_HASKELL__ > 706 +#define GTE(n,m) (tagToEnum# (n >=# m)) +#define EQ(n,m) (tagToEnum# (n ==# m)) +#else +#define GTE(n,m) (n >=# m) +#define EQ(n,m) (n ==# m) +#endif @@ -47,34 +44,13 @@ -{-# LINE 10 "" #-} -{-# LINE 1 "templates/GenericTemplate.hs" #-} --- ----------------------------------------------------------------------------- --- ALEX TEMPLATE --- --- This code is in the PUBLIC DOMAIN; you may copy it freely and use --- it for any purpose whatsoever. --- ----------------------------------------------------------------------------- --- INTERNALS and main scanner engine -{-# LINE 21 "templates/GenericTemplate.hs" #-} --- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex. -#if __GLASGOW_HASKELL__ > 706 -#define GTE(n,m) (tagToEnum# (n >=# m)) -#define EQ(n,m) (tagToEnum# (n ==# m)) -#else -#define GTE(n,m) (n >=# m) -#define EQ(n,m) (n ==# m) -#endif -{-# LINE 51 "templates/GenericTemplate.hs" #-} - - data AlexAddr = AlexA# Addr# -- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex. #if __GLASGOW_HASKELL__ < 503 @@ -99,13 +75,13 @@ alexIndexInt16OffAddr (AlexA# arr) off = {-# INLINE alexIndexInt32OffAddr #-} -alexIndexInt32OffAddr (AlexA# arr) off = +alexIndexInt32OffAddr (AlexA# arr) off = #ifdef WORDS_BIGENDIAN narrow32Int# i where i = word2Int# ((b3 `uncheckedShiftL#` 24#) `or#` - (b2 `uncheckedShiftL#` 16#) `or#` - (b1 `uncheckedShiftL#` 8#) `or#` b0) + (b2 `uncheckedShiftL#` 16#) `or#` + (b1 `uncheckedShiftL#` 8#) `or#` b0) b3 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 3#))) b2 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 2#))) b1 = int2Word# (ord# (indexCharOffAddr# arr (off' +# 1#))) @@ -140,49 +116,49 @@ data AlexReturn a | AlexToken !AlexInput !Int a -- alexScan :: AlexInput -> StartCode -> AlexReturn a -alexScan input (I# (sc)) - = alexScanUser undefined input (I# (sc)) +alexScan input__ (I# (sc)) + = alexScanUser undefined input__ (I# (sc)) -alexScanUser user input (I# (sc)) - = case alex_scan_tkn user input 0# input sc AlexNone of - (AlexNone, input') -> - case alexGetByte input of - Nothing -> +alexScanUser user__ input__ (I# (sc)) + = case alex_scan_tkn user__ input__ 0# input__ sc AlexNone of + (AlexNone, input__') -> + case alexGetByte input__ of + Nothing -> - AlexEOF - Just _ -> + AlexEOF + Just _ -> - AlexError input' + AlexError input__' - (AlexLastSkip input'' len, _) -> + (AlexLastSkip input__'' len, _) -> - AlexSkip input'' len + AlexSkip input__'' len - (AlexLastAcc k input''' len, _) -> + (AlexLastAcc k input__''' len, _) -> - AlexToken input''' len k + AlexToken input__''' len (alex_actions ! k) -- Push the input through the DFA, remembering the most recent accepting -- state it encountered. -alex_scan_tkn user orig_input len input s last_acc = - input `seq` -- strict in the input - let - new_acc = (check_accs (alex_accept `quickIndex` (I# (s)))) +alex_scan_tkn user__ orig_input len input__ s last_acc = + input__ `seq` -- strict in the input + let + new_acc = (check_accs (alex_accept `quickIndex` (I# (s)))) in new_acc `seq` - case alexGetByte input of - Nothing -> (new_acc, input) - Just (c, new_input) -> + case alexGetByte input__ of + Nothing -> (new_acc, input__) + Just (c, new_input) -> @@ -191,40 +167,71 @@ alex_scan_tkn user orig_input len input s last_acc = base = alexIndexInt32OffAddr alex_base s offset = (base +# ord_c) check = alexIndexInt16OffAddr alex_check offset - + new_s = if GTE(offset,0#) && EQ(check,ord_c) - then alexIndexInt16OffAddr alex_table offset - else alexIndexInt16OffAddr alex_deflt s - in + then alexIndexInt16OffAddr alex_table offset + else alexIndexInt16OffAddr alex_deflt s + in case new_s of - -1# -> (new_acc, input) - -- on an error, we want to keep the input *before* the - -- character that failed, not after. - _ -> alex_scan_tkn user orig_input (if c < 0x80 || c >= 0xC0 then (len +# 1#) else len) + -1# -> (new_acc, input__) + -- on an error, we want to keep the input *before* the + -- character that failed, not after. + _ -> alex_scan_tkn user__ orig_input (if c < 0x80 || c >= 0xC0 then (len +# 1#) else len) -- note that the length is increased ONLY if this is the 1st byte in a char encoding) - new_input new_s new_acc + new_input new_s new_acc } where - check_accs (AlexAccNone) = last_acc - check_accs (AlexAcc a ) = AlexLastAcc a input (I# (len)) - check_accs (AlexAccSkip) = AlexLastSkip input (I# (len)) -{-# LINE 198 "templates/GenericTemplate.hs" #-} + check_accs (AlexAccNone) = last_acc + check_accs (AlexAcc a ) = AlexLastAcc a input__ (I# (len)) + check_accs (AlexAccSkip) = AlexLastSkip input__ (I# (len)) + + + + + + + -data AlexLastAcc a - = AlexNone - | AlexLastAcc a !AlexInput !Int - | AlexLastSkip !AlexInput !Int -instance Functor AlexLastAcc where - fmap f AlexNone = AlexNone - fmap f (AlexLastAcc x y z) = AlexLastAcc (f x) y z - fmap f (AlexLastSkip x y) = AlexLastSkip x y -data AlexAcc a user + + + +data AlexLastAcc + = AlexNone + | AlexLastAcc !Int !AlexInput !Int + | AlexLastSkip !AlexInput !Int + +data AlexAcc user = AlexAccNone - | AlexAcc a + | AlexAcc Int | AlexAccSkip -{-# LINE 242 "templates/GenericTemplate.hs" #-} --- used by wrappers -iUnbox (I# (i)) = i + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/alex/AlexWrapper-6.035 b/alex/AlexWrapper-basic similarity index 100% rename from alex/AlexWrapper-6.035 rename to alex/AlexWrapper-basic diff --git a/build.sh b/build.sh index 995c41a..a15bda6 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,6 @@ #!/bin/bash -eu # build.sh -- Athena build script +# Copyright (C) 2019 Qiantan Hong # Copyright (C) 2013, 2014 Benjamin Barenblat # # This program is free software: you can redistribute it and/or modify it under @@ -42,10 +43,13 @@ for package in alex happy; do fi done +mkdir -p "$TOP/.cabal-sandbox/bin" + cabal install \ --enable-library-profiling \ --enable-executable-profiling \ - --alex-options="--ghc --template=\"$TOP/alex\"" + --alex-options="--ghc --template=\"$TOP/alex\""\ + --installdir="$TOP/.cabal-sandbox/bin" # --happy-options="-i -a -d" # uncomment the trailing '\' on line 42 and the entirety of line 43 to add # debug info to happy. the '-i' flag outputs a state diagram of the compiled diff --git a/decafc.cabal b/decafc.cabal index 67d7fba..d06e3e1 100644 --- a/decafc.cabal +++ b/decafc.cabal @@ -1,3 +1,4 @@ +-- Copyright (C) 2019 Qiantan Hong -- Copyright (C) 2013, 2014 Benjamin Barenblat -- -- This file is a part of decafc. @@ -19,7 +20,7 @@ author: Benjamin Barenblat maintainer: bbaren@mit.edu license: MIT license-file: LICENSE -extra-source-files: alex/AlexWrapper-6.035 +extra-source-files: alex/AlexWrapper-basic build-type: Simple tested-with: GHC==7.10.3 @@ -37,7 +38,7 @@ executable decafc , split , transformers , pretty-show - build-tools: alex >=3.0.2 + build-tools: alex == 3.2.4 , happy diff --git a/setup.sh b/setup.sh index 2ad3246..84a9b7f 100755 --- a/setup.sh +++ b/setup.sh @@ -11,6 +11,11 @@ fi mkdir .cabal-exec/ cd .cabal-exec/ -wget -O - "https://downloads.haskell.org/~cabal/cabal-install-latest/cabal-install-3.0.0.0-i386-unknown-linux.tar.xz" | +if [[ $(uname) -eq "Darwin" ]]; then + arch=x86_64-apple-darwin17.7.0 +else + arch=i386-unknown-linux +fi +wget -O - "https://downloads.haskell.org/~cabal/cabal-install-latest/cabal-install-3.0.0.0-${arch}.tar.xz" | xzcat | tar -xf - diff --git a/src/Scanner.x b/src/Scanner.x index a46b7f5..2ebc4e7 100644 --- a/src/Scanner.x +++ b/src/Scanner.x @@ -18,7 +18,7 @@ module Scanner ( ScannedToken(..) ) where } -%wrapper "6.035" +%wrapper "basic" ----------------------------------- Tokens ------------------------------------