feat: add declModifiers to constructor declarations

The goal is to allow users to attach doc strings and
`private/protected` to constructor declarations.

TODO: reject non applicable modifiers such as `unsafe` and `partial`.

cc @Kha
This commit is contained in:
Leonardo de Moura 2020-07-13 13:03:24 -07:00
parent 83431dc88e
commit 6e12987dd9
2 changed files with 4 additions and 4 deletions

View file

@ -130,10 +130,10 @@ withDeclId declId fun name => do
levelNames ← getLevelNames;
declName ← mkDeclName declId modifiers name;
ctors ← (decl.getArg (numTokens + 2)).getArgs.mapM fun ctor => do {
-- def ctor := parser! " | " >> ident >> optional inferMod >> optDeclSig
let ctorName := ctor.getIdAt 1;
-- def ctor := parser! declModifiers >> " | " >> ident >> optional inferMod >> optDeclSig
let ctorName := ctor.getIdAt 2;
let ctorName := declName ++ ctorName;
checkNotAlreadyDeclared (ctor.getArg 1) ctorName;
checkNotAlreadyDeclared (ctor.getArg 2) ctorName;
pure (ctorName, ctor)
};
pure {

View file

@ -54,7 +54,7 @@ def «instance» := parser! "instance " >> optional declId >> declSig >> d
def «axiom» := parser! "axiom " >> declId >> declSig
def «example» := parser! "example " >> declSig >> declVal
def inferMod := parser! try ("{" >> "}")
def ctor := parser! " | " >> ident >> optional inferMod >> optDeclSig
def ctor := parser! declModifiers >> " | " >> ident >> optional inferMod >> optDeclSig
def «inductive» := parser! "inductive " >> declId >> optDeclSig >> many ctor
def classInductive := parser! try ("class " >> "inductive ") >> declId >> optDeclSig >> many ctor
def structExplicitBinder := parser! "(" >> many ident >> optional inferMod >> optDeclSig >> optional Term.binderDefault >> ")"