Skip to content

Commit 39af1c0

Browse files
authored
feat: scope notations generated for LTS and ReductionSystem (#133)
Closes #124 and #120.
1 parent 5435910 commit 39af1c0

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

Cslib/Foundations/Lint/Basic.lean

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ def topNamespace : Batteries.Tactic.Lint.Linter where
2727
if top.contains declName.components[0]! then
2828
return none
2929
else
30-
let ty := env.find? declName |>.get! |>.type
31-
/- TODO: this is a temporary allowance for unscoped notations generated
32-
for `LTS` and `ReductionSystem`. -/
33-
if ty == .const ``Lean.TrailingParserDescr [] then
34-
return none
35-
else
36-
return m!"{declName} is not namespaced."
30+
return m!"{declName} is not namespaced."
3731

3832
end Cslib.Lint

Cslib/Foundations/Semantics/LTS/Basic.lean

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -719,17 +719,17 @@ elab "create_lts" lt:ident name:ident : command => do
719719
also used this as a constructor name, you will need quotes to access corresponding cases, e.g. «β»
720720
in the above example.
721721
-/
722-
syntax "lts_transition_notation" ident (str)? : command
722+
syntax attrKind "lts_transition_notation" ident (str)? : command
723723
macro_rules
724-
| `(lts_transition_notation $lts $sym) =>
724+
| `($kind:attrKind lts_transition_notation $lts $sym) =>
725725
`(
726-
notation3 t:39 "["μ"]⭢" $sym:str t':39 => (LTS.Tr.toRelation $lts μ) t t'
727-
notation3 t:39 "["μs"]↠" $sym:str t':39 => (LTS.MTr.toRelation $lts μs) t t'
726+
$kind:attrKind notation3 t:39 "["μ"]⭢" $sym:str t':39 => (LTS.Tr.toRelation $lts μ) t t'
727+
$kind:attrKind notation3 t:39 "["μs"]↠" $sym:str t':39 => (LTS.MTr.toRelation $lts μs) t t'
728728
)
729-
| `(lts_transition_notation $lts) =>
729+
| `($kind:attrKind lts_transition_notation $lts) =>
730730
`(
731-
notation3 t:39 "["μ"]⭢" t':39 => (LTS.Tr.toRelation $lts μ) t t'
732-
notation3 t:39 "["μs"]↠" t':39 => (LTS.MTr.toRelation $lts μs) t t'
731+
$kind:attrKind notation3 t:39 "["μ"]⭢" t':39 => (LTS.Tr.toRelation $lts μ) t t'
732+
$kind:attrKind notation3 t:39 "["μs"]↠" t':39 => (LTS.MTr.toRelation $lts μs) t t'
733733
)
734734

735735
/-- This attribute calls the `lts_transition_notation` command for the annotated declaration. -/
@@ -746,11 +746,15 @@ initialize Lean.registerBuiltinAttribute {
746746
sym := Syntax.mkStrLit (sym.getString ++ " ")
747747
let lts := lts.getId.updatePrefix decl.getPrefix |> Lean.mkIdent
748748
liftCommandElabM <| Command.elabCommand (← `(create_lts $(mkIdent decl) $lts))
749-
liftCommandElabM <| Command.elabCommand (← `(lts_transition_notation $lts $sym))
749+
liftCommandElabM <| (do
750+
modifyScope ({ · with currNamespace := decl.getPrefix })
751+
Command.elabCommand (← `(scoped lts_transition_notation $lts $sym)))
750752
| `(attr | lts $lts) =>
751753
let lts := lts.getId.updatePrefix decl.getPrefix |> Lean.mkIdent
752754
liftCommandElabM <| Command.elabCommand (← `(create_lts $(mkIdent decl) $lts))
753-
liftCommandElabM <| Command.elabCommand (← `(lts_transition_notation $lts))
755+
liftCommandElabM <| (do
756+
modifyScope ({ · with currNamespace := decl.getPrefix })
757+
Command.elabCommand (← `(scoped lts_transition_notation $lts)))
754758
| _ => throwError "invalid syntax for 'lts' attribute"
755759
}
756760

Cslib/Foundations/Semantics/ReductionSystem/Basic.lean

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ elab "create_reduction_sys" rel:ident name:ident : command => do
9898
also used this as a constructor name, you will need quotes to access corresponding cases, e.g. «β»
9999
in the above example.
100100
-/
101-
syntax "reduction_notation" ident (str)? : command
101+
syntax attrKind "reduction_notation" ident (str)? : command
102102
macro_rules
103-
| `(reduction_notation $rs $sym) =>
103+
| `($kind:attrKind reduction_notation $rs $sym) =>
104104
`(
105-
notation3 t:39 " ⭢" $sym:str t':39 => (ReductionSystem.Red $rs) t t'
106-
notation3 t:39 " ↠" $sym:str t':39 => (ReductionSystem.MRed $rs) t t'
105+
$kind:attrKind notation3 t:39 " ⭢" $sym:str t':39 => (ReductionSystem.Red $rs) t t'
106+
$kind:attrKind notation3 t:39 " ↠" $sym:str t':39 => (ReductionSystem.MRed $rs) t t'
107107
)
108-
| `(reduction_notation $rs) =>
108+
| `($kind:attrKind reduction_notation $rs) =>
109109
`(
110-
notation3 t:39 " ⭢ " t':39 => (ReductionSystem.Red $rs) t t'
111-
notation3 t:39 " ↠ " t':39 => (ReductionSystem.MRed $rs) t t'
110+
$kind:attrKind notation3 t:39 " ⭢ " t':39 => (ReductionSystem.Red $rs) t t'
111+
$kind:attrKind notation3 t:39 " ↠ " t':39 => (ReductionSystem.MRed $rs) t t'
112112
)
113113

114114

@@ -133,11 +133,15 @@ initialize Lean.registerBuiltinAttribute {
133133
sym := Syntax.mkStrLit (sym.getString ++ " ")
134134
let rs := rs.getId.updatePrefix decl.getPrefix |> Lean.mkIdent
135135
liftCommandElabM <| Command.elabCommand (← `(create_reduction_sys $(mkIdent decl) $rs))
136-
liftCommandElabM <| Command.elabCommand (← `(reduction_notation $rs $sym))
136+
liftCommandElabM <| (do
137+
modifyScope ({ · with currNamespace := decl.getPrefix })
138+
Command.elabCommand (← `(scoped reduction_notation $rs $sym)))
137139
| `(attr | reduction_sys $rs) =>
138140
let rs := rs.getId.updatePrefix decl.getPrefix |> Lean.mkIdent
139141
liftCommandElabM <| Command.elabCommand (← `(create_reduction_sys $(mkIdent decl) $rs))
140-
liftCommandElabM <| Command.elabCommand (← `(reduction_notation $rs))
142+
liftCommandElabM <| (do
143+
modifyScope ({ · with currNamespace := decl.getPrefix })
144+
Command.elabCommand (← `(scoped reduction_notation $rs)))
141145
| _ => throwError "invalid syntax for 'reduction_sys' attribute"
142146
}
143147

0 commit comments

Comments
 (0)