2024-11-20 19:29:09 -08:00
|
|
|
/**
|
|
|
|
|
* @file Basic proof assistant based on Calculus of Constructions
|
|
|
|
|
* @author William Ball <williampi103@gmail.com>
|
|
|
|
|
* @license GPL3
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/// <reference types="tree-sitter-cli/dsl" />
|
|
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
module.exports = grammar({
|
|
|
|
|
name: "perga",
|
|
|
|
|
|
|
|
|
|
rules: {
|
|
|
|
|
|
|
|
|
|
program : $ => repeat(choice(
|
|
|
|
|
$.definition,
|
|
|
|
|
$.comment,
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
|
|
identifier : $ => /[a-zA-Z_]\w*/,
|
|
|
|
|
|
|
|
|
|
comment : $ => token(seq('--', /.*/)),
|
|
|
|
|
|
|
|
|
|
param_block : $ => seq(
|
|
|
|
|
'(',
|
2024-11-20 21:46:51 -08:00
|
|
|
field('param', repeat($.identifier)),
|
2024-11-20 19:29:09 -08:00
|
|
|
':',
|
2024-11-20 21:46:51 -08:00
|
|
|
field('type', $.expr),
|
2024-11-20 19:29:09 -08:00
|
|
|
')'
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
star : $ => "*",
|
|
|
|
|
square : $ => choice('□', '[]'),
|
|
|
|
|
|
|
|
|
|
labs : $ => seq(
|
2024-11-20 21:46:51 -08:00
|
|
|
choice('λ', 'fun'),
|
2024-11-20 19:29:09 -08:00
|
|
|
repeat1($.param_block),
|
|
|
|
|
choice('=>', '⇒'),
|
|
|
|
|
$.expr,
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
pabs : $ => seq(
|
2024-11-20 21:46:51 -08:00
|
|
|
choice('∏', 'forall'),
|
2024-11-20 19:29:09 -08:00
|
|
|
repeat1($.param_block),
|
|
|
|
|
',',
|
|
|
|
|
$.expr,
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
term : $ => choice(
|
|
|
|
|
$.identifier,
|
|
|
|
|
$.star,
|
|
|
|
|
$.square,
|
|
|
|
|
seq('(', $.expr, ')'),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
app : $ => repeat1($.term),
|
|
|
|
|
|
|
|
|
|
axiom : $ => 'axiom',
|
|
|
|
|
|
|
|
|
|
arrow : $ => prec.left(1, seq(
|
|
|
|
|
$.app_term,
|
|
|
|
|
choice('->', '→'),
|
|
|
|
|
$.expr,
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
|
|
app_term : $ => choice(
|
|
|
|
|
$.labs,
|
|
|
|
|
$.pabs,
|
|
|
|
|
$.app,
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
expr : $ => choice(
|
|
|
|
|
$.app_term,
|
|
|
|
|
$.arrow,
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
ascription : $ => seq(
|
|
|
|
|
':',
|
2024-11-20 21:46:51 -08:00
|
|
|
field('type', $.expr),
|
2024-11-20 19:29:09 -08:00
|
|
|
),
|
|
|
|
|
|
|
|
|
|
definition : $ => seq(
|
2024-11-20 21:46:51 -08:00
|
|
|
field('name', $.identifier),
|
2024-11-20 19:29:09 -08:00
|
|
|
repeat($.param_block),
|
|
|
|
|
optional($.ascription),
|
|
|
|
|
':=',
|
|
|
|
|
choice($.expr, $.axiom),
|
|
|
|
|
';',
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|