feat(library/init/lean/parser/term): match-expression
TODO: add whitespace sensitivity
This commit is contained in:
parent
5cfa13d08b
commit
f37cd3cd11
2 changed files with 8 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue