Skip to content

Instantly share code, notes, and snippets.

@msmorgan
Last active November 7, 2017 00:43
Show Gist options
  • Save msmorgan/b4901d8626d22da6fd47fbb9d503c697 to your computer and use it in GitHub Desktop.
Save msmorgan/b4901d8626d22da6fd47fbb9d503c697 to your computer and use it in GitHub Desktop.
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