-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Terminal to take an
a -> Maybe b
And rename and deprecate some operators
- Loading branch information
Showing
18 changed files
with
95 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,46 @@ | ||
-- | Derived operators. | ||
module Text.Earley.Derived where | ||
import Control.Applicative hiding (many) | ||
import Data.ListLike(ListLike) | ||
import qualified Data.ListLike as ListLike | ||
|
||
import Text.Earley.Grammar | ||
|
||
-- | Match a token that satisfies the given predicate. Returns the matched | ||
-- token. | ||
{-# INLINE satisfy #-} | ||
satisfy :: (t -> Bool) -> Prod r e t t | ||
satisfy p = Terminal f $ Pure id | ||
where | ||
f t | p t = Just t | ||
f _ = Nothing | ||
|
||
-- | Match a single token. | ||
symbol :: Eq t => t -> Prod r e t t | ||
symbol x = satisfy (== x) | ||
token :: Eq t => t -> Prod r e t t | ||
token x = satisfy (== x) | ||
|
||
-- | Match a single token and give it the name of the token. | ||
namedSymbol :: Eq t => t -> Prod r t t t | ||
namedSymbol x = symbol x <?> x | ||
namedToken :: Eq t => t -> Prod r t t t | ||
namedToken x = token x <?> x | ||
|
||
-- | Match a list of tokens in sequence. | ||
{-# INLINE word #-} | ||
{-# INLINE list #-} | ||
list :: Eq t => [t] -> Prod r e t [t] | ||
list = foldr (liftA2 (:) . satisfy . (==)) (pure []) | ||
|
||
-- | Match a 'ListLike' of tokens in sequence. | ||
{-# INLINE listLike #-} | ||
listLike :: (Eq t, ListLike i t) => i -> Prod r e t i | ||
listLike = ListLike.foldr (liftA2 ListLike.cons . satisfy . (==)) (pure ListLike.empty) | ||
|
||
{-# DEPRECATED symbol "Use `token` instead" #-} | ||
symbol :: Eq t => t -> Prod r e t t | ||
symbol = token | ||
|
||
{-# DEPRECATED namedSymbol "Use `namedToken` instead" #-} | ||
namedSymbol :: Eq t => t -> Prod r e t t | ||
namedSymbol = token | ||
|
||
{-# DEPRECATED word "Use `list` or `listLike` instead" #-} | ||
word :: Eq t => [t] -> Prod r e t [t] | ||
word = foldr (liftA2 (:) . satisfy . (==)) (pure []) | ||
word = list |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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