Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit a4764ed

Browse files
Khatydeu
authored andcommitted
chore: adapt to simpleBinder removal
1 parent 78d1075 commit a4764ed

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

Diff for: Lake/DSL/Script.lean

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ namespace Lake.DSL
1111
open Lean Parser Command
1212

1313
syntax scriptDeclSpec :=
14-
ident (ppSpace "(" Term.simpleBinder ")")? (declValSimple <|> declValDo)
14+
ident (ppSpace "(" ident+ ")")? (declValSimple <|> declValDo)
1515

1616
scoped syntax (name := scriptDecl)
1717
(docComment)? "script " scriptDeclSpec : command
1818

1919
@[macro scriptDecl]
2020
def expandScriptDecl : Macro
21-
| `($[$doc?]? script $id:ident $[($args?)]? do $seq $[$wds?]?) => do
22-
let args := args?.getD (← `(Term.hole|_))
23-
`($[$doc?]? @[«script»] def $id : ScriptFn := fun $args => do $seq $[$wds?]?)
24-
| `($[$doc?]? script $id:ident $[($args?)]? := $defn $[$wds?]?) => do
25-
let args := args?.getD (← `(Term.hole|_))
26-
`($[$doc?]? @[«script»] def $id : ScriptFn := fun $args => $defn $[$wds?]?)
21+
| `($[$doc?]? script $id:ident $[($args?*)]? do $seq $[$wds?]?) => do
22+
let args := args?.getD (α := Array FunBinder) #[← `(Term.hole|_)]
23+
`($[$doc?]? @[«script»] def $id : ScriptFn := fun $args* => do $seq $[$wds?]?)
24+
| `($[$doc?]? script $id:ident $[($args?*)]? := $defn $[$wds?]?) => do
25+
let args := args?.getD (α := Array FunBinder) #[← `(Term.hole|_)]
26+
`($[$doc?]? @[«script»] def $id : ScriptFn := fun $args* => $defn $[$wds?]?)
2727
| stx => Macro.throwErrorAt stx "ill-formed script declaration"

Diff for: Lake/Util/Binder.lean

+13-25
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,18 @@ instance : Coe Hole BinderIdent where
3939
instance : Coe Ident BinderIdent where
4040
coe s := ⟨s.raw⟩
4141

42-
abbrev SimpleBinder := TSyntax ``Term.simpleBinder
4342
abbrev BracketedBinder := TSyntax ``Term.bracketedBinder
4443
abbrev FunBinder := TSyntax ``Term.funBinder
4544

46-
instance : Coe BinderIdent SimpleBinder where
47-
coe s := ⟨s.raw⟩
48-
49-
instance : Coe SimpleBinder FunBinder where
45+
instance : Coe BinderIdent FunBinder where
5046
coe s := ⟨s.raw⟩
5147

5248
@[runParserAttributeHooks]
53-
def declBinder := Term.simpleBinderWithoutType <|> Term.bracketedBinder
54-
abbrev DeclBinder := TSyntax ``declBinder
55-
56-
abbrev Binder := TSyntax [``Term.simpleBinder, ``Term.bracketedBinder]
49+
def binder := Term.binderIdent <|> Term.bracketedBinder
5750

58-
instance : Coe DeclBinder Binder where
59-
coe s := ⟨s.raw⟩
51+
abbrev Binder := TSyntax ``binder
52+
instance : Coe Binder (TSyntax [identKind, ``Term.hole, ``Term.bracketedBinder]) where
53+
coe stx := ⟨stx.raw⟩
6054

6155
abbrev BinderModifier := TSyntax [``Term.binderTactic, ``Term.binderDefault]
6256

@@ -102,15 +96,9 @@ def expandBinderModifier (optBinderModifier : Syntax) : Option BinderModifier :=
10296

10397
def matchBinder (stx : Syntax) : MacroM (Array BinderSyntaxView) := do
10498
let k := stx.getKind
105-
if k == ``Lean.Parser.Term.simpleBinder then
106-
-- binderIdent+ >> optType
107-
let ids ← getBinderIds stx[0]
108-
let optType := stx[1]
109-
ids.mapM fun id => return {
110-
id := (← expandBinderIdent id),
111-
type := expandOptType id optType,
112-
info := .default
113-
}
99+
if stx.isIdent || k == ``Term.hole then
100+
-- binderIdent
101+
return #[{ id := (← expandBinderIdent stx), type := mkHoleFrom stx, info := .default }]
114102
else if k == ``Lean.Parser.Term.explicitBinder then
115103
-- `(` binderIdent+ binderType (binderDefault <|> binderTactic)? `)`
116104
let ids ← getBinderIds stx[1]
@@ -153,16 +141,16 @@ def matchBinder (stx : Syntax) : MacroM (Array BinderSyntaxView) := do
153141
def BinderSyntaxView.mkBinder : BinderSyntaxView → MacroM Binder
154142
| {id, type, info, modifier?} => do
155143
match info with
156-
| .default => `(declBinder| ($id : $type $[$modifier?]?))
157-
| .implicit => `(declBinder| {$id : $type})
158-
| .strictImplicit => `(declBinder| ⦃$id : $type⦄)
159-
| .instImplicit => `(declBinder| [$id : $type])
144+
| .default => `(binder| ($id : $type $[$modifier?]?))
145+
| .implicit => `(binder| {$id : $type})
146+
| .strictImplicit => `(binder| ⦃$id : $type⦄)
147+
| .instImplicit => `(binder| [$id : $type])
160148
| _ => unreachable!
161149

162150
def BinderSyntaxView.mkArgument : BinderSyntaxView → MacroM NamedArgument
163151
| {id, ..} => `(Term.namedArgument| ($id := $id))
164152

165-
def expandBinders (dbs : Array DeclBinder) : MacroM (Array Binder × Array Term) := do
153+
def expandBinders (dbs : Array Binder) : MacroM (Array Binder × Array Term) := do
166154
let mut bs := #[]
167155
let mut args : Array Term := #[]
168156
for db in dbs do

Diff for: Lake/Util/Opaque.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace Lake
1717
open Lean Parser Command
1818

1919
macro (name := declareOpaqueType)
20-
doc?:optional(docComment) "declare_opaque_type " id:ident dbs:declBinder* : command => do
21-
let (bs, args) ← expandBinders dbs
20+
doc?:optional(docComment) "declare_opaque_type " id:ident bs:binder* : command => do
21+
let (bs, args) ← expandBinders bs
2222
let nonemptyTypeId := id.getId.modifyBase (· ++ `nonemptyType)
2323
let nonemptyType := mkIdentFrom id nonemptyTypeId
2424
let nonemptyTypeApp := Syntax.mkApp nonemptyType args

0 commit comments

Comments
 (0)