add boolean patterns
This commit is contained in:
parent
6a45e9092c
commit
4ce2bb22d5
1
ast.hs
1
ast.hs
|
@ -33,6 +33,7 @@ data AST = Add AST AST
|
||||||
data Pattern = VarP String
|
data Pattern = VarP String
|
||||||
| IntP Integer
|
| IntP Integer
|
||||||
| StrP String
|
| StrP String
|
||||||
|
| BoolP Bool
|
||||||
| UnitP
|
| UnitP
|
||||||
| ConsP Pattern Pattern
|
| ConsP Pattern Pattern
|
||||||
| TupleP [Pattern]
|
| TupleP [Pattern]
|
||||||
|
|
|
@ -324,6 +324,10 @@ patternBindings (IntP n) (IntV v)
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
patternBindings (IntP n) _ = 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 UnitV = Just M.empty
|
||||||
patternBindings UnitP _ = Nothing
|
patternBindings UnitP _ = Nothing
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ pattern :: Pattern
|
||||||
= pattern "::" pattern { ConsP $1 $2 }
|
= pattern "::" pattern { ConsP $1 $2 }
|
||||||
/ "[" patternlist "]"
|
/ "[" patternlist "]"
|
||||||
/ patterntuple
|
/ patterntuple
|
||||||
|
/ "true" { BoolP True } / "false" { BoolP False }
|
||||||
/ identifier { VarP $1 }
|
/ identifier { VarP $1 }
|
||||||
/ stringlit { StrP $1 }
|
/ stringlit { StrP $1 }
|
||||||
/ integer { IntP $1 }
|
/ integer { IntP $1 }
|
||||||
|
|
Loading…
Reference in New Issue