Skip to content

Instantly share code, notes, and snippets.

@banacorn
Created December 16, 2014 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banacorn/9856ed0a164f0f5415f6 to your computer and use it in GitHub Desktop.
Save banacorn/9856ed0a164f0f5415f6 to your computer and use it in GitHub Desktop.
alex posn
scan :: String -> Pipeline [Token]
scan str = go (alexStartPos, '\n', [], str)
where
go inp@(pos, _, _, str) = case alexScan inp 0 of
AlexEOF -> return []
AlexError (pos, _, _, _) -> throwError $ LexError (toPosition pos) "fucked up"
AlexSkip inp_ len -> go inp_
AlexToken inp_ len act -> do
xs <- go inp_
return $ act pos (take len str) : xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment