Skip to content

Instantly share code, notes, and snippets.

@doivosevic
Created January 3, 2015 18:32
Show Gist options
  • Save doivosevic/8fdd01ff8917a34ba2bd to your computer and use it in GitHub Desktop.
Save doivosevic/8fdd01ff8917a34ba2bd to your computer and use it in GitHub Desktop.
parseIf :: Parser Statement
parseIf = do
spaces
string "if "
spaces
expr <- expression
spaces
string "then "
st <- statement
return $ If expr st Nothing
parseIfElse :: Parser Statement
parseIfElse = do
spaces
string "if "
spaces
expr <- expression
spaces
string "then "
st <- statement
spaces
string "else "
mst <- statement
return $ If expr st $ Just mst
statement :: Parser Statement
statement = try parseIfElse <|> parseIf <|> assignment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment