operator sections

This commit is contained in:
William Ball 2024-12-10 23:39:53 -08:00
parent 4131069cd4
commit 483fa6ec49
6 changed files with 4345 additions and 4050 deletions

View file

@ -46,15 +46,17 @@ module.exports = grammar({
';'
),
variable_binding : $ => seq(
'(',
repeat1(choice($.identifier, $.symbol)),
':',
field('type', $.expr),
')',
),
variable : $ => seq(
choice('variable', 'hypothesis'),
repeat1(seq(
'(',
repeat1(choice($.identifier, $.symbol)),
':',
field('type', $.expr),
')'
)),
repeat1($.variable_binding),
';'
),
@ -86,9 +88,16 @@ module.exports = grammar({
$.expr,
),
op_section : $ => seq(
'(',
$.symbol,
')',
),
term : $ => choice(
$.identifier,
$.sort,
$.op_section,
seq('(', $.expr, ')'),
),

103
src/grammar.json generated
View file

@ -116,6 +116,47 @@
}
]
},
"variable_binding": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "symbol"
}
]
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "expr"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"variable": {
"type": "SEQ",
"members": [
@ -135,45 +176,8 @@
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "symbol"
}
]
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "expr"
}
},
{
"type": "STRING",
"value": ")"
}
]
"type": "SYMBOL",
"name": "variable_binding"
}
},
{
@ -360,6 +364,23 @@
}
]
},
"op_section": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "symbol"
},
{
"type": "STRING",
"value": ")"
}
]
},
"term": {
"type": "CHOICE",
"members": [
@ -371,6 +392,10 @@
"type": "SYMBOL",
"name": "sort"
},
{
"type": "SYMBOL",
"name": "op_section"
},
{
"type": "SEQ",
"members": [

36
src/node-types.json generated
View file

@ -278,6 +278,21 @@
]
}
},
{
"type": "op_section",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "symbol",
"named": true
}
]
}
},
{
"type": "pabs",
"named": true,
@ -440,6 +455,10 @@
"type": "identifier",
"named": true
},
{
"type": "op_section",
"named": true
},
{
"type": "sort",
"named": true
@ -450,9 +469,24 @@
{
"type": "variable",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "variable_binding",
"named": true
}
]
}
},
{
"type": "variable_binding",
"named": true,
"fields": {
"type": {
"multiple": true,
"multiple": false,
"required": true,
"types": [
{

8143
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,22 @@
=================
Operator Sections
=================
def foo := (+) one two;
---
(program
(definition
(identifier)
(expr
(app_term
(binex
(app
(term
(op_section
(symbol)))
(term
(identifier))
(term
(identifier))))))))

View file

@ -18,39 +18,43 @@ end Test
(identifier)
(program
(variable
(identifier)
(identifier)
(identifier)
(expr
(app_term
(binex
(app
(term
(sort
(star))))))))
(variable_binding
(identifier)
(identifier)
(identifier)
(expr
(app_term
(binex
(app
(term
(sort
(star)))))))))
(variable
(identifier)
(expr
(app_term
(binex
(app
(term
(identifier))))))
(identifier)
(expr
(app_term
(binex
(app
(term
(identifier))))))
(identifier)
(identifier)
(expr
(app_term
(binex
(app
(term
(identifier)))))))
(variable_binding
(identifier)
(expr
(app_term
(binex
(app
(term
(identifier)))))))
(variable_binding
(identifier)
(expr
(app_term
(binex
(app
(term
(identifier)))))))
(variable_binding
(identifier)
(identifier)
(expr
(app_term
(binex
(app
(term
(identifier))))))))
(section
(identifier)
(program