match stx with
| `(declModifiers| $(_)? @[$[$atts],*] $(_)? $(_)? $(_)? $(_)?) =>
atts.filterMapM fun att ↦domatch att with
| `(attrInstance | AMS $nums*) =>return some nums
| _ =>return none
| _ =>return #[]
run := withSetOptionIn fun stx =>domatch stx with
| `(command| $a:declModifiers theorem$_ $_:bracketedBinder* : $_ := $_)
| `(command| $a:declModifiers lemma$_ $_:bracketedBinder* : $_ := $_)
| `(command| $a:declModifiers example $_:bracketedBinder* : $_ := $_) =>let ams ← toAMS a
let outStx :=match a with
| `(declModifiers| $(_)? $atts $(_)? $(_)? $(_)? $(_)?) => atts.raw
| _ => stx
if ams.size > 1thenlet numerals := ams.flatten
let outCorrect :=m!"{← mkAMSSyntax numerals}"let currentOut :=m!", ".joinSep (← ams.mapM fun nums ↦doreturnm!"{← mkAMSSyntax nums}").toList
logLintIf linter.style.ams_attribute outStx
m!"The AMS tag should be formatted as {outCorrect} rather than {currentOut}"returnif ams.size == 0then
logLintIf linter.style.ams_attribute outStx
"Missing AMS attribute."returnif ams.flatten.isEmpty then-- If we're here then there is at least one AMS tag, but it doesn't have any number.
logLintIf linter.style.ams_attribute outStx
"The AMS tag should have at least one subject number."return-- Avoid AMS tags with leading zeros (e.g. AMS 05 -> AMS 5)for n in ams.flatten doiflet some str := n.raw.reprint thenlet trimmed := str.trimAscii.toString
if trimmed.length > 1 && trimmed.startsWith "0"then
logLintIf linter.style.ams_attribute outStx
m!"AMS subject {trimmed} should not have a leading zero."-- Check there the AMS tags are sorted and do not contain duplicateslet ams_sorted := ams.flatten.qsort (fun n m => n.getNat < m.getNat)
if ams_sorted != ams.flatten then
logLintIf linter.style.ams_attribute outStx
m!"The AMS tags should be ordered as {← mkAMSSyntax ams_sorted}"returnif ams_sorted.dedupSorted != ams_sorted then
logLintIf linter.style.ams_attribute outStx
m!"AMS tags contain duplicates. This should be {← mkAMSSyntax ams_sorted.dedupSorted}"
| _ =>return