Last active
November 7, 2017 00:43
-
-
Save msmorgan/b4901d8626d22da6fd47fbb9d503c697 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Text.Parser.Core | |
{- | |
... | |
-} | |
-- what to name this? | |
mapToken : (tokB -> tokA) -> Grammar tokA c a -> Grammar tokB c a | |
mapToken f (Empty val) = Empty val | |
mapToken f (Terminal g) = Terminal (g . f) | |
mapToken f (NextIs g) = SeqEmpty (NextIs (g . f)) (Empty . f) | |
mapToken f EOF = EOF | |
mapToken f (Fail msg) = Fail msg | |
mapToken f Commit = Commit | |
mapToken f (SeqEat act next) = SeqEat (mapToken f act) (\x => mapToken f (next x)) | |
mapToken f (SeqEmpty act next) = SeqEmpty (mapToken f act) (\x => mapToken f (next x)) | |
mapToken f (Alt x y) = Alt (mapToken f x) (mapToken f y) | |
-- used like this | |
dropTokenData : Grammar tok c a -> Grammar (TokenData tok) c a | |
dropTokenData p = mapToken (\(MkToken l c t) => t) p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment