37 | 37 |
\$ $idchar + { lex (TkJoin . T.strip) }
|
38 | 38 |
|
39 | 39 |
{
|
40 | |
data Token = Token AlexPosn TkType deriving (Eq, Show)
|
| 40 |
data Token = Token
|
| 41 |
{ tkPosn :: AlexPosn
|
| 42 |
, tkType :: TkType
|
| 43 |
} deriving (Eq, Show)
|
41 | 44 |
|
42 | 45 |
data TkType
|
43 | 46 |
= TkLCurl
|
|
55 | 58 |
deriving (Eq, Show)
|
56 | 59 |
|
57 | 60 |
data AlexUserState = AlexUserState
|
58 | |
{ filePath :: FilePath
|
| 61 |
{ filePath :: FilePath
|
| 62 |
, lastToken :: Maybe Token
|
| 63 |
, thisToken :: Maybe Token
|
59 | 64 |
} deriving (Eq, Show)
|
60 | 65 |
|
61 | 66 |
alexInitUserState :: AlexUserState
|
62 | |
alexInitUserState = AlexUserState "<unknown>"
|
| 67 |
alexInitUserState = AlexUserState "<unknown>" Nothing Nothing
|
63 | 68 |
|
64 | 69 |
getFilePath :: Alex FilePath
|
65 | 70 |
getFilePath = liftM filePath alexGetUserState
|
66 | 71 |
|
67 | 72 |
setFilePath :: FilePath -> Alex ()
|
68 | |
setFilePath = alexSetUserState . AlexUserState
|
| 73 |
setFilePath f = do
|
| 74 |
userState <- alexGetUserState
|
| 75 |
alexSetUserState userState { filePath = f }
|
| 76 |
|
| 77 |
getLastToken :: Alex (Maybe Token)
|
| 78 |
getLastToken = liftM lastToken alexGetUserState
|
| 79 |
|
| 80 |
setLastToken :: Token -> Alex ()
|
| 81 |
setLastToken t = do
|
| 82 |
userState <- alexGetUserState
|
| 83 |
alexSetUserState userState
|
| 84 |
{ lastToken = thisToken userState
|
| 85 |
, thisToken = Just t
|
| 86 |
}
|
69 | 87 |
|
70 | 88 |
alexMonadScan' :: Alex Token
|
71 | 89 |
alexMonadScan' = do
|
|
80 | 98 |
alexMonadScan'
|
81 | 99 |
AlexToken inp' len action -> do
|
82 | 100 |
alexSetInput inp'
|
83 | |
action (ignorePendingBytes inp) len
|
| 101 |
tok <- action (ignorePendingBytes inp) len
|
| 102 |
setLastToken tok
|
| 103 |
return tok
|
84 | 104 |
|
85 | 105 |
alexError' :: AlexPosn -> String -> Alex a
|
86 | 106 |
alexError' (AlexPn _ l c) msg = do
|