add boolean patterns

This commit is contained in:
darkf 2013-11-01 21:43:36 -07:00
parent 6a45e9092c
commit 4ce2bb22d5
3 changed files with 6 additions and 0 deletions

1
ast.hs
View File

@ -33,6 +33,7 @@ data AST = Add AST AST
data Pattern = VarP String
| IntP Integer
| StrP String
| BoolP Bool
| UnitP
| ConsP Pattern Pattern
| TupleP [Pattern]

View File

@ -324,6 +324,10 @@ patternBindings (IntP n) (IntV v)
| otherwise = Nothing
patternBindings (IntP n) _ = Nothing
patternBindings (BoolP b) (BoolV v)
| v == b = Just M.empty
| otherwise = Nothing
patternBindings UnitP UnitV = Just M.empty
patternBindings UnitP _ = Nothing

View File

@ -40,6 +40,7 @@ pattern :: Pattern
= pattern "::" pattern { ConsP $1 $2 }
/ "[" patternlist "]"
/ patterntuple
/ "true" { BoolP True } / "false" { BoolP False }
/ identifier { VarP $1 }
/ stringlit { StrP $1 }
/ integer { IntP $1 }