ollef / Earley

Parsing all context-free grammars using Earley's algorithm in Haskell.
BSD 3-Clause "New" or "Revised" License
361 stars 24 forks source link

Change type of `satisfy` #26

Closed massysett closed 8 years ago

massysett commented 8 years ago

Would it be possible to change the type of satisfy to something like

satisfy :: (t -> Maybe a) -> Prod r e t a

This would make it easier to have a type like

module Token (Token, mkToken, unToken) where

newtype Token = Token { unToken :: Char }

mkToken :: Char -> Maybe Token
mkToken x
  | x >= 'a' || x <= 'z' = Just (Token x)
  | otherwise = Nothing

and have satisfy work as expected. (You can do this now, but with partial function nastiness.) Currently this is what Parsec's tokenPrim looks like.

ollef commented 8 years ago

Hey! Thanks for your input. There's now a new terminal operator that does this on master. Coming soon to a release near you.