Created
March 1, 2019 02:08
-
-
Save DylanLukes/db4a92b78f4185895f6936037a233bef 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
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE RecursiveDo #-} | |
module WAM.L0.Token where | |
import Control.Applicative | |
import Control.Applicative.Combinators | |
import Control.Monad | |
import Data.Char | |
import Text.Earley | |
data Token where | |
Atom :: String -> Token | |
Var :: String -> Token | |
LPar :: Token -- ( | |
RPar :: Token -- ) | |
Query :: Token -- ?- | |
Comma :: Token -- , | |
Period :: Token -- . | |
deriving (Show, Eq) | |
tokens :: Grammar r (Prod r String Char [Token]) | |
tokens = mdo | |
atom | |
<- rule $ Atom | |
<$> liftA2 (:) (satisfy isLower) (many $ satisfy isAlphaNum) | |
<* ws | |
<?> "atom" | |
var | |
<- rule $ Var | |
<$> liftA2 (:) (satisfy isUpper) (many $ satisfy isAlphaNum) | |
<* ws | |
<?> "variable" | |
ws | |
<- rule $ void | |
<$> many (some (satisfy isSpace)) | |
<?> "" | |
return (many (atom <|> var)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment