-
-
Save alok/90bd979dc6496dfe0ddb72cdd799c58b 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
import Control.Monad | |
import System.IO | |
import Text.ParserCombinators.Parsec | |
import Text.ParserCombinators.Parsec.Expr | |
import Text.ParserCombinators.Parsec.Language | |
import qualified Text.ParserCombinators.Parsec.Token as Token | |
languageDef = | |
emptyDef | |
{ Token.commentLine = "%" | |
, Token.identStart = letter | |
, Token.identLetter = alphaNum | |
, Token.reservedNames = | |
["\\", "$", "\\(", "\\)", "\\[", "\\]", "$$", "{", "}"] | |
, Token.reservedOpNames = ["\\", "$", "\\(", "\\)", "\\[", "\\]", "$$"] | |
} | |
lexer = Token.makeTokenParser languageDef | |
parseString :: String -> Stmt | |
parseString str = | |
case parse whileParser "" str of | |
Left e -> error $ show e | |
Right r -> r | |
parseFile :: String -> IO Stmt | |
parseFile file = do | |
program <- readFile file | |
case parse whileParser "" program of | |
Left e -> print e >> fail "parse error" | |
Right r -> return r | |
main :: IO () | |
main = do | |
error "undefined: `main' in lex.hs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment