[Alex] Feature request: Create a customizable state monad AlexState

Alain Cremieux alcremi at pobox.com
Sat Feb 16 18:13:18 EST 2008


In Alex, very often I need to include elements in the basic monad of the 
wrapper ALEX_MONAD.
For instance if I want to record the level of a comment, or a list of 
the comments.

Several years ago I hacked the file wrapper.hs to include my own 
elements, by defining another entry point:

data AlexState = AlexState {
        alex_pos :: !AlexPosn,  -- position at current input location
        alex_inp :: String,     -- the current input
        alex_chr :: !Char,      -- the character before the input
        alex_scd :: !Int        -- the current startcode
  , alex_ust :: AlexUserState -- defined in the user program
/*    }


runAlex :: String -> Alex a -> Either String a
runAlex input (Alex f)
   = case f (AlexState {alex_pos = alexStartPos,
                        alex_inp = input,
                        alex_chr = '\n',
            alex_ust = alexInitUserState,
/*                        alex_scd = 0}) of Left msg -> Left msg
                                          Right ( _, a ) -> Right a

This way I can define my own elements, and initialize them.

Now I'd like to have this change integrated in the development tree.
Has anyone another idea as how to obtain the same result (knowing that 
now there are 2 variants, whith normal chars and with bytestrings) ? How 
would other Alex users do that ?


More information about the Libraries mailing list