feat: improve letIdLhs parser
The extra space is only really needed to distinguish an array update (NIY) ``` let x[i] := ... ``` from a declaration taking an instance argument ``` let f [Monad m] := ... ``` closes #696
This commit is contained in:
parent
f4759c9a22
commit
200a38e20c
2 changed files with 21 additions and 1 deletions
|
|
@ -166,7 +166,7 @@ def simpleBinderWithoutType := nodeWithAntiquot "simpleBinder" `Lean.Parser.Term
|
|||
(many1 binderIdent >> pushNone)
|
||||
|
||||
/- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/
|
||||
def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many (ppSpace >> (simpleBinderWithoutType <|> bracketedBinder)) >> optType
|
||||
def letIdLhs : Parser := ident >> notFollowedBy (checkNoWsBefore "" >> "[") "space is required before instance '[...]' binders to distinguish them from array updates `let x[i] := e; ...`" >> many (ppSpace >> (simpleBinderWithoutType <|> bracketedBinder)) >> optType
|
||||
def letIdDecl := nodeWithAntiquot "letIdDecl" `Lean.Parser.Term.letIdDecl $ atomic (letIdLhs >> " := ") >> termParser
|
||||
def letPatDecl := nodeWithAntiquot "letPatDecl" `Lean.Parser.Term.letPatDecl $ atomic (termParser >> pushNone >> optType >> " := ") >> termParser
|
||||
def letEqnsDecl := nodeWithAntiquot "letEqnsDecl" `Lean.Parser.Term.letEqnsDecl $ letIdLhs >> matchAlts
|
||||
|
|
|
|||
20
tests/lean/run/696.lean
Normal file
20
tests/lean/run/696.lean
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def four1 := double 2
|
||||
where double (n : Nat) : Nat := 2 * n
|
||||
|
||||
def four2 := double 2
|
||||
where double : Nat → Nat := fun n => 2 * n
|
||||
|
||||
def four3 := double 2
|
||||
where double(n : Nat) : Nat := 2 * n
|
||||
|
||||
def four4 := double 2
|
||||
where double: Nat → Nat := fun n => 2 * n
|
||||
|
||||
def four5 := let double(n : Nat) : Nat := 2 * n
|
||||
double 2
|
||||
|
||||
def four6 := let double: Nat → Nat := fun n => 2 * n
|
||||
double 2
|
||||
|
||||
def four7 := let rec double: Nat → Nat := fun n => 2 * n
|
||||
double 2
|
||||
Loading…
Add table
Reference in a new issue