Created
June 7, 2012 16:36
-
-
Save rblaze/2889923 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
module LangParser(parseGrammar, Token(..)) where | |
import Control.Applicative | |
import Control.Monad | |
data Token = | |
Return | | |
Simple Char | | |
OctalConst String | | |
DecimalConst String | | |
HexConst String | | |
NamedParam String | | |
Identifier String | | |
LexError String | |
deriving (Eq, Show) | |
tReturn :: [Token] -> Maybe [Token] | |
tReturn [] = Nothing | |
tReturn (x:xs) = f x xs | |
where f Return xs = Just xs | |
f _ _ = Nothing | |
tSimple :: Char -> [Token] -> Maybe [Token] | |
tSimple _ [] = Nothing | |
tSimple c (x:xs) = f x xs | |
where f (Simple c) xs = Just xs | |
f _ _ = Nothing | |
parseGrammar :: [Token] -> Maybe [Token] | |
parseGrammar = retexpr | |
expr :: [Token] -> Maybe [Token] | |
expr = tSimple ':' | |
retexprs :: [Token] -> Maybe [Token] | |
retexprs = multiexpr <|> expr | |
where multiexpr = expr >=> tSimple ',' >=> retexprs | |
retexpr :: [Token] -> Maybe [Token] | |
retexpr = tReturn >=> retexprs | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment