From ff5b1b859c76359d9b7b74721fce5d3ac90526d8 Mon Sep 17 00:00:00 2001 From: Emeka Nkurumeh Date: Sat, 30 Dec 2023 00:06:13 -0600 Subject: [PATCH 1/2] close #220 --- data/AlexWrappers.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/AlexWrappers.hs b/data/AlexWrappers.hs index 0aa90bde..30ea7be3 100644 --- a/data/AlexWrappers.hs +++ b/data/AlexWrappers.hs @@ -360,13 +360,13 @@ alexGetStartCode = Alex $ \s@AlexState{alex_scd=sc} -> Right (s, sc) alexSetStartCode :: Int -> Alex () alexSetStartCode sc = Alex $ \s -> Right (s{alex_scd=sc}, ()) -#if !defined(ALEX_MONAD_BYTESTRING) && defined(ALEX_MONAD_USER_STATE) +#if defined(ALEX_MONAD_USER_STATE) alexGetUserState :: Alex AlexUserState alexGetUserState = Alex $ \s@AlexState{alex_ust=ust} -> Right (s,ust) alexSetUserState :: AlexUserState -> Alex () alexSetUserState ss = Alex $ \s -> Right (s{alex_ust=ss}, ()) -#endif /* !defined(ALEX_MONAD_BYTESTRING) && defined(ALEX_MONAD_USER_STATE) */ +#endif /* defined(ALEX_MONAD_USER_STATE) */ #ifdef ALEX_MONAD alexMonadScan = do From a857c89624b448461cef77e57e25a575e5feb283 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Sat, 30 Dec 2023 09:39:01 +0100 Subject: [PATCH 2/2] Tests and CHANGELOG for #220 --- CHANGELOG.md | 2 ++ tests/monadUserState_typeclass_bytestring.x | 5 +++ tests/tokens_monadUserState_bytestring.x | 39 +++++++++++++-------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f471d6e2..d3a93d01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ * Add option `--numeric-version`. * Remove deprecated `-v` as alias for `--version`. * Add `-v` as placeholder for a future `--verbose` option. + * Make `alex{G,S}etUserState` available with the `monadUserState-bytestring` wrapper + [Issue #220](https://github.com/haskell/alex/issues/220). ## Changes in 3.4.0.1 diff --git a/tests/monadUserState_typeclass_bytestring.x b/tests/monadUserState_typeclass_bytestring.x index 992ac93c..d8c53afb 100644 --- a/tests/monadUserState_typeclass_bytestring.x +++ b/tests/monadUserState_typeclass_bytestring.x @@ -70,6 +70,11 @@ lex inp = let lexAll = do + -- Andreas Abel, 2023-12-30, issue #220: + -- Test that alex{G,S}etUserState are in scope. + u <- alexGetUserState + alexSetUserState (u + 1) + res <- alexMonadScan case res of EOF -> return [] diff --git a/tests/tokens_monadUserState_bytestring.x b/tests/tokens_monadUserState_bytestring.x index 915e2eb5..eebbd09d 100644 --- a/tests/tokens_monadUserState_bytestring.x +++ b/tests/tokens_monadUserState_bytestring.x @@ -28,30 +28,39 @@ tokens :- tok f (p,_,input,_) len = return (f p (B.take (fromIntegral len) input)) -- The token type: -data Token = - Let AlexPosn | - In AlexPosn | - Sym AlexPosn Char | - Var AlexPosn String | - Int AlexPosn Int | - Err AlexPosn | - EOF - deriving (Eq,Show) +data Token + = Let AlexPosn + | In AlexPosn + | Sym AlexPosn Char + | Var AlexPosn String + | Int AlexPosn Int + | Err AlexPosn + | EOF + deriving (Eq,Show) alexEOF = return EOF main = if test1 /= result1 then do print test1; exitFailure - else exitWith ExitSuccess + else exitWith ExitSuccess type AlexUserState = () alexInitUserState = () scanner str = runAlex str $ do - let loop = do tk <- alexMonadScan - if tk == EOF - then return [tk] - else do toks <- loop - return (tk:toks) + let + loop = do + + -- Andreas Abel, 2023-12-30, issue #220: + -- Test that alex{G,S}etUserState are in scope. + () <- alexGetUserState + alexSetUserState () + + tk <- alexMonadScan + if tk == EOF + then return [tk] + else do + toks <- loop + return (tk:toks) loop test1 = case scanner " let in 012334\n=+*foo bar__'" of