Skip to content

Commit 4de7cd8

Browse files
committed
Make the ifdefs a bit neater
1 parent 3850530 commit 4de7cd8

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

templates/wrappers.hs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,13 @@ data AlexState = AlexState {
166166
alex_pos :: !AlexPosn, -- position at current input location
167167
#ifndef ALEX_MONAD_BYTESTRING
168168
alex_inp :: String, -- the current input
169+
alex_chr :: !Char, -- the character before the input
170+
alex_bytes :: [Byte],
169171
#else /* ALEX_MONAD_BYTESTRING */
170172
alex_bpos:: !Int64, -- bytes consumed so far
171173
alex_inp :: ByteString.ByteString, -- the current input
172-
#endif /* ALEX_MONAD_BYTESTRING */
173174
alex_chr :: !Char, -- the character before the input
174-
#ifndef ALEX_MONAD_BYTESTRING
175-
alex_bytes :: [Byte],
176-
#endif /* ! ALEX_MONAD_BYTESTRING */
175+
#endif /* ALEX_MONAD_BYTESTRING */
177176
alex_scd :: !Int -- the current startcode
178177
#ifdef ALEX_MONAD_USER_STATE
179178
, alex_ust :: AlexUserState -- AlexUserState will be defined in the user program
@@ -184,19 +183,16 @@ data AlexState = AlexState {
184183

185184
#ifndef ALEX_MONAD_BYTESTRING
186185
runAlex :: String -> Alex a -> Either String a
186+
runAlex input__ (Alex f)
187+
= case f (AlexState {alex_bytes = [],
187188
#else /* ALEX_MONAD_BYTESTRING */
188189
runAlex :: ByteString.ByteString -> Alex a -> Either String a
189-
#endif /* ALEX_MONAD_BYTESTRING */
190190
runAlex input__ (Alex f)
191-
= case f (AlexState {alex_pos = alexStartPos,
192-
#ifdef ALEX_MONAD_BYTESTRING
193-
alex_bpos = 0,
191+
= case f (AlexState {alex_bpos = 0,
194192
#endif /* ALEX_MONAD_BYTESTRING */
193+
alex_pos = alexStartPos,
195194
alex_inp = input__,
196195
alex_chr = '\n',
197-
#ifndef ALEX_MONAD_BYTESTRING
198-
alex_bytes = [],
199-
#endif /* ! ALEX_MONAD_BYTESTRING */
200196
#ifdef ALEX_MONAD_USER_STATE
201197
alex_ust = alexInitUserState,
202198
#endif
@@ -256,16 +252,14 @@ alexGetStartCode = Alex $ \s@AlexState{alex_scd=sc} -> Right (s, sc)
256252
alexSetStartCode :: Int -> Alex ()
257253
alexSetStartCode sc = Alex $ \s -> Right (s{alex_scd=sc}, ())
258254

259-
#ifndef ALEX_MONAD_BYTESTRING
260-
#ifdef ALEX_MONAD_USER_STATE
255+
#if !defined(ALEX_MONAD_BYTESTRING) && defined(ALEX_MONAD_USER_STATE)
261256
alexGetUserState :: Alex AlexUserState
262257
alexGetUserState = Alex $ \s@AlexState{alex_ust=ust} -> Right (s,ust)
263258

264259
alexSetUserState :: AlexUserState -> Alex ()
265260
alexSetUserState ss = Alex $ \s -> Right (s{alex_ust=ss}, ())
266-
#endif
261+
#endif /* !defined(ALEX_MONAD_BYTESTRING) && defined(ALEX_MONAD_USER_STATE) */
267262

268-
#endif /* ! ALEX_MONAD_BYTESTRING */
269263
alexMonadScan = do
270264
#ifndef ALEX_MONAD_BYTESTRING
271265
inp__ <- alexGetInput

0 commit comments

Comments
 (0)