Created
September 26, 2011 02:34
-
-
Save t0yv0/1241504 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| {-# OPTIONS -XDoRec -XDeriveDataTypeable #-} | |
| module Example where | |
| import Text.Earley | |
| import Data.Dynamic | |
| import Control.Applicative | |
| data E = Nat Int | |
| | Add E E deriving (Show, Typeable) | |
| grammar :: Grammar (Rule Char E) | |
| grammar = do | |
| nat <- rule "NAT" | |
| [ fmap (\_ -> 0) (term '0') | |
| , fmap (\_ -> 1) (term '1') | |
| ] | |
| rec expr <- rule "EXPR" | |
| [ fmap Nat $ var nat | |
| , pure (\x _ y -> Add x y) | |
| <*> var expr | |
| <*> term '+' | |
| <*> var expr | |
| ] | |
| return expr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment