-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.js
More file actions
68 lines (64 loc) · 2.42 KB
/
Copy pathgrammar.js
File metadata and controls
68 lines (64 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @file A simple and flexible computer-processable language that supports rigorously verifying, archiving, and presenting mathematical proofs.
* @author Ramiro Santa Ana Anguiano <hi@colima.press>
* @license GPL-2.0
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
// Based on Metamath Language EBNF, Appendix E, https://us.metamath.org/downloads/metamath.pdf
// For a ANTLR4 version cfr. https://github.com/antlr/grammars-v4/blob/master/metamath/metamath.g4
module.exports = grammar({
name: "metamath",
extras: ($) => [$._comment, $._whitechar],
rules: {
// Strictly follow
database: ($) => repeat($.outermost_scope_stmt),
outermost_scope_stmt: ($) =>
choice($.include_stmt, $.constant_stmt, $.stmt),
include_stmt: ($) => seq("$[", $.filename, "$]"),
constant_stmt: ($) => seq("$c", repeat1($.constant), "$."),
stmt: ($) =>
choice(
$.block,
$.variable_stmt,
$.disjoint_stmt,
$.hypothesis_stmt,
$.assert_stmt,
),
block: ($) => seq("${", repeat($.stmt), "$}"),
variable_stmt: ($) => seq("$v", repeat1($.variable), "$."),
disjoint_stmt: ($) =>
seq("$d", $.variable, $.variable, repeat($.variable), "$."),
hypothesis_stmt: ($) => choice($.floating_stmt, $.essential_stmt),
floating_stmt: ($) => seq($.label, "$f", $.typecode, $.variable, "$."),
essential_stmt: ($) =>
seq($.label, "$e", $.typecode, repeat($.math_symbol), "$."),
assert_stmt: ($) => choice($.axiom_stmt, $.provable_stmt),
axiom_stmt: ($) =>
seq($.label, "$a", $.typecode, repeat($.math_symbol), "$."),
provable_stmt: ($) =>
seq(
$.label,
"$p",
$.typecode,
repeat($.math_symbol),
"$=",
$.proof,
"$.",
),
proof: ($) => choice($.uncompressed_proof, $.compressed_proof),
uncompressed_proof: ($) => repeat1(choice($.label, "?")),
compressed_proof: ($) =>
seq("(", repeat($.label), ")", repeat1($.compressed_proof_block)),
typecode: ($) => $.constant,
filename: ($) => $.math_symbol,
constant: ($) => $.math_symbol,
variable: ($) => $.math_symbol,
// Loosely follow
label: ($) => /[\w\.-]+/,
compressed_proof_block: ($) => /[A-Z\?]+/,
math_symbol: ($) => /[\u0021-\u0023\u0025-\u007e]+/u, // ASCII non-whitespace printable characters - $
_comment: ($) => seq("$(", repeat(/[[:ascii:]]/), "$)"),
_whitechar: ($) => /\s+/,
},
});