feat(library/init/lean/parser/term): match-expression

TODO: add whitespace sensitivity
This commit is contained in:
Leonardo de Moura 2019-07-08 14:14:49 -07:00
parent 5cfa13d08b
commit f37cd3cd11
2 changed files with 8 additions and 1 deletions

View file

@ -77,6 +77,9 @@ def bracktedBinder (requireType := false) := explicitBinder requireType <|> impl
@[builtinTermParser] def depArrow := parser! bracktedBinder true >> unicodeSymbolCheckPrec " → " " -> " 25 >> termParser
def simpleBinder := parser! many1 binderIdent
@[builtinTermParser] def «forall» := parser! unicodeSymbol "∀" "forall" >> many1 (simpleBinder <|> bracktedBinder) >> ", " >> termParser
def equation := parser! " | " >> sepBy1 termParser ", " >> " => " >> termParser
@[builtinTermParser] def «match» := parser! "match " >> sepBy1 termParser ", " >> optType >> " with " >> many1 equation
@[builtinTermParser] def «nomatch» := parser! "nomatch " >> termParser
def namedArgument := tparser! try ("(" >> ident >> " := ") >> termParser >> ")"
@[builtinTermParser] def app := tparser! pushLeading >> (namedArgument <|> termParser appPrec)

View file

@ -74,7 +74,11 @@ test [
"f (x : a) -> b",
"f ((x : a) -> b)",
"(f : (n : Nat) → Vector Nat n) -> Nat",
"∀ x y (z : Nat), x > y -> x > y - z"
"∀ x y (z : Nat), x > y -> x > y - z",
"
match x with
| some x => true
| none => false"
];
testFailures [
"f {x : a} -> b",