Skip to content

Instantly share code, notes, and snippets.

@grondilu
Last active October 26, 2023 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/544b66d2b93a9e5b07d030c7b7d5bffe to your computer and use it in GitHub Desktop.
Save grondilu/544b66d2b93a9e5b07d030c7b7d5bffe to your computer and use it in GitHub Desktop.
Metamath raku grammar
# Metamath commentless grammar
# remove comments beforehand with
# .subst: / '$(' ~ '$)' .*? /, '', :g
unit grammar Metamath;
rule TOP { ^ <database> $ }
rule database { <outermost-scope-stmt>* }
rule outermost-scope-stmt {
| <include-stmt>
| <constant-stmt>
| <stmt>
}
rule include-stmt { '$[' ~ '$]' <filename> }
rule constant-stmt { '$c' ~ '$.' <constant>+ }
rule stmt {
<block> |
<variable-stmt> | <disjoint-stmt> | <hypothesis-stmt> | <assert-stmt>
}
rule block { '${' ~ '$}' <stmt>* }
rule variable-stmt { '$v' ~ '$.' <variable>* }
rule disjoint-stmt { '$d' ~ '$.' <variable> ** 2..* }
rule hypothesis-stmt { <floating-stmt> | <essential-stmt> }
rule floating-stmt { <LABEL> '$f' ~ '$.' [<typecode> <variable>] }
rule essential-stmt { <LABEL> '$e' ~ '$.' [<typecode> <MATH-SYMBOL> *] }
rule assert-stmt { <axiom-stmt> | <provable-stmt> }
rule axiom-stmt { <LABEL> '$a' ~ '$.' [ <typecode> <MATH-SYMBOL> * ] }
rule provable-stmt {
<LABEL> '$p' <typecode> <MATH-SYMBOL> * '$=' ~ '$.' <proof>
}
rule proof { <uncompressed-proof> | <compressed-proof> }
rule uncompressed-proof { [ <LABEL> | '?' ] + }
rule compressed-proof { [ '(' ~ ')' <LABEL> * ] <COMPRESSED-PROOF-BLOCK> + }
rule typecode { <constant> }
rule filename { <MATH-SYMBOL> }
rule constant { <MATH-SYMBOL> }
rule variable { <MATH-SYMBOL> }
token MATH-SYMBOL { <+[\H]-[$]>+ }
token LABEL { <+alpha+digit+[.-]>+ }
token COMPRESSED-PROOF-BLOCK { <[A..Z?]>+ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment