Resolve grammar bugs; Pass tests

This commit is contained in:
Jeff 2023-08-24 12:53:42 -04:00
parent 7a80c89dc7
commit 012efffa2e
5 changed files with 872 additions and 904 deletions

View File

@ -70,8 +70,9 @@ String
---
(source_file
(expression
(value
(string)))
(string))))
==================
Integer
@ -82,8 +83,9 @@ Integer
---
(source_file
(expression
(value
(integer)))
(integer))))
==================
Float
@ -94,8 +96,9 @@ Float
---
(source_file
(expression
(value
(float)))
(float))))
==================
@ -107,12 +110,15 @@ List
---
(source_file
(expression
(value
(list
(expression
(value
(integer)))
(expression
(value
(integer))))
(integer)))))))
==================
Empty
@ -123,8 +129,9 @@ Empty
---
(source_file
(expression
(value
(empty)))
(empty))))
==================
Tool
@ -137,8 +144,23 @@ random_boolean();
(source_file
(expression
(tool))
(expression
(value
(empty))
(empty)))
(chain))
==================
Boolean
==================
true false
---
(source_file
(expression
(value
(boolean)))
(expression
(value
(boolean))))

View File

@ -5,18 +5,15 @@ module.exports = grammar({
source_file: $ => repeat(choice(
$.comment,
$.expression,
$.value,
$.yield,
$.chain
)),
comment: $ => /(#)(.+?)([\n\r])/,
expression: $ => choice(
$.identifier,
prec(2, $.value),
prec(1, $.identifier),
$.tool,
seq($.identifier, $.operator, $.expression),
seq($.value, $.operator, $.value)
),
value: $ => choice(
@ -25,8 +22,11 @@ module.exports = grammar({
$.string,
$.list,
$.empty,
$.boolean,
),
comment: $ => /(#)(.+?)([\n\r])/,
yield: $ => "->",
chain: $ => ";",
@ -60,6 +60,11 @@ module.exports = grammar({
empty: $ => "()",
boolean: $ => choice(
"true",
"false"
),
list: $ => seq(
'(',
repeat1(seq($.expression, optional(','))),

View File

@ -14,10 +14,6 @@
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "yield"
@ -29,16 +25,24 @@
]
}
},
"comment": {
"type": "PATTERN",
"value": "(#)(.+?)([\\n\\r])"
},
"expression": {
"type": "CHOICE",
"members": [
{
"type": "PREC",
"value": 2,
"content": {
"type": "SYMBOL",
"name": "value"
}
},
{
"type": "PREC",
"value": 1,
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "SYMBOL",
@ -60,23 +64,6 @@
"name": "expression"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "operator"
},
{
"type": "SYMBOL",
"name": "value"
}
]
}
]
},
@ -102,9 +89,17 @@
{
"type": "SYMBOL",
"name": "empty"
},
{
"type": "SYMBOL",
"name": "boolean"
}
]
},
"comment": {
"type": "PATTERN",
"value": "(#)(.+?)([\\n\\r])"
},
"yield": {
"type": "STRING",
"value": "->"
@ -191,6 +186,19 @@
"type": "STRING",
"value": "()"
},
"boolean": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "true"
},
{
"type": "STRING",
"value": "false"
}
]
},
"list": {
"type": "SEQ",
"members": [

View File

@ -1,4 +1,9 @@
[
{
"type": "boolean",
"named": true,
"fields": {}
},
{
"type": "expression",
"named": true,
@ -70,10 +75,6 @@
"type": "expression",
"named": true
},
{
"type": "value",
"named": true
},
{
"type": "yield",
"named": true
@ -94,6 +95,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "boolean",
"named": true
},
{
"type": "empty",
"named": true
@ -161,6 +166,10 @@
"type": "empty",
"named": true
},
{
"type": "false",
"named": false
},
{
"type": "float",
"named": true
@ -197,6 +206,10 @@
"type": "string",
"named": true
},
{
"type": "true",
"named": false
},
{
"type": "yield",
"named": true

File diff suppressed because it is too large Load Diff