Skip to content

Instantly share code, notes, and snippets.

@doivosevic
Created January 3, 2015 18:31
Show Gist options
  • Save doivosevic/ac3c068211bf2f424619 to your computer and use it in GitHub Desktop.
Save doivosevic/ac3c068211bf2f424619 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