added block comments

This commit is contained in:
William Ball 2024-11-21 13:14:46 -08:00
parent e5e219e0e9
commit ece43957c9
10 changed files with 853 additions and 679 deletions

View file

@ -10,17 +10,32 @@
module.exports = grammar({
name: "perga",
extras: $ => [
$.comment,
$.block_comment,
/\s/,
],
rules: {
program : $ => repeat(choice(
$.definition,
$.comment,
)),
program : $ => repeat($.definition),
identifier : $ => /[a-zA-Z_]\w*/,
comment : $ => token(seq('--', /.*/)),
block_comment: $ => token(seq(
'[*',
repeat(choice(
/[^\[\]*]/,
/\[[^*]/,
/\*[^\]]/,
/\[\*/,
/\*\]/,
)),
'*]'
)),
param_block : $ => seq(
'(',
field('param', repeat($.identifier)),

65
src/grammar.json generated
View file

@ -4,17 +4,8 @@
"program": {
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "definition"
},
{
"type": "SYMBOL",
"name": "comment"
}
]
"type": "SYMBOL",
"name": "definition"
}
},
"identifier": {
@ -37,6 +28,50 @@
]
}
},
"block_comment": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "[*"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\\[\\]*]"
},
{
"type": "PATTERN",
"value": "\\[[^*]"
},
{
"type": "PATTERN",
"value": "\\*[^\\]]"
},
{
"type": "PATTERN",
"value": "\\[\\*"
},
{
"type": "PATTERN",
"value": "\\*\\]"
}
]
}
},
{
"type": "STRING",
"value": "*]"
}
]
}
},
"param_block": {
"type": "SEQ",
"members": [
@ -342,6 +377,14 @@
}
},
"extras": [
{
"type": "SYMBOL",
"name": "comment"
},
{
"type": "SYMBOL",
"name": "block_comment"
},
{
"type": "PATTERN",
"value": "\\s"

8
src/node-types.json generated
View file

@ -201,10 +201,6 @@
"multiple": true,
"required": false,
"types": [
{
"type": "comment",
"named": true
},
{
"type": "definition",
"named": true
@ -284,6 +280,10 @@
"type": "axiom",
"named": true
},
{
"type": "block_comment",
"named": true
},
{
"type": "comment",
"named": true

1235
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,66 @@
===========
Application
===========
foo (A B : *) (f : A -> B) (x : A) :=
(fun (x : B) => x) (f x);
---
(program
(definition
(identifier)
(param_block
(identifier)
(identifier)
(expr
(app_term
(app
(term
(star))))))
(param_block
(identifier)
(expr
(arrow
(app_term
(app
(term
(identifier))))
(expr
(app_term
(app
(term
(identifier))))))))
(param_block
(identifier)
(expr
(app_term
(app
(term
(identifier))))))
(expr
(app_term
(app
(term
(expr
(app_term
(labs
(param_block
(identifier)
(expr
(app_term
(app
(term
(identifier))))))
(expr
(app_term
(app
(term
(identifier)))))))))
(term
(expr
(app_term
(app
(term
(identifier))
(term
(identifier)))))))))))

View file

@ -10,46 +10,39 @@ foo (A B : *) (f : A -> A -> B) (x : A) := f x x;
(definition
(identifier)
(param_block
(param
(identifier))
(param
(identifier))
(type
(expr
(identifier)
(identifier)
(expr
(app_term
(app
(term
(star))))))
(param_block
(identifier)
(expr
(arrow
(app_term
(app
(term
(star)))))))
(param_block
(param
(identifier))
(type
(expr
(arrow
(app_term
(app
(term
(identifier))))
(expr
(arrow
(identifier))))
(expr
(arrow
(app_term
(app
(term
(identifier))))
(expr
(app_term
(app
(term
(identifier))))
(expr
(app_term
(app
(term
(identifier)))))))))))
(identifier))))))))))
(param_block
(param
(identifier))
(type
(expr
(app_term
(app
(term
(identifier)))))))
(identifier)
(expr
(app_term
(app
(term
(identifier))))))
(expr
(app_term
(app

View file

@ -10,10 +10,9 @@ nat : * := axiom;
(definition
(identifier)
(ascription
(type
(expr
(app_term
(app
(term
(star)))))))
(expr
(app_term
(app
(term
(star))))))
(axiom)))

View file

@ -4,7 +4,10 @@ Comments
-- here's a comment
foo := *;
foo :=
-- and a comment in the middle
[* and a [* nested *] block comment *]
*;
---
@ -12,6 +15,8 @@ foo := *;
(comment)
(definition
(identifier)
(comment)
(block_comment)
(expr
(app_term
(app

View file

@ -12,25 +12,20 @@ foo := fun (A : *) (x : A) => x;
(expr
(app_term
(labs
(lambda)
(param_block
(param
(identifier))
(type
(expr
(app_term
(app
(term
(star)))))))
(identifier)
(expr
(app_term
(app
(term
(star))))))
(param_block
(param
(identifier))
(type
(expr
(app_term
(app
(term
(identifier)))))))
(identifier)
(expr
(app_term
(app
(term
(identifier))))))
(expr
(app_term
(app

View file

@ -12,25 +12,20 @@ rel := forall (A : *) (x : A), *;
(expr
(app_term
(pabs
(pi)
(param_block
(param
(identifier))
(type
(expr
(app_term
(app
(term
(star)))))))
(identifier)
(expr
(app_term
(app
(term
(star))))))
(param_block
(param
(identifier))
(type
(expr
(app_term
(app
(term
(identifier)))))))
(identifier)
(expr
(app_term
(app
(term
(identifier))))))
(expr
(app_term
(app