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 (source_file
(expression
(value (value
(string))) (string))))
================== ==================
Integer Integer
@ -82,8 +83,9 @@ Integer
--- ---
(source_file (source_file
(expression
(value (value
(integer))) (integer))))
================== ==================
Float Float
@ -94,8 +96,9 @@ Float
--- ---
(source_file (source_file
(expression
(value (value
(float))) (float))))
================== ==================
@ -107,12 +110,15 @@ List
--- ---
(source_file (source_file
(expression
(value (value
(list (list
(expression
(value (value
(integer))) (integer)))
(expression
(value (value
(integer)))) (integer)))))))
================== ==================
Empty Empty
@ -123,8 +129,9 @@ Empty
--- ---
(source_file (source_file
(expression
(value (value
(empty))) (empty))))
================== ==================
Tool Tool
@ -137,8 +144,23 @@ random_boolean();
(source_file (source_file
(expression (expression
(tool)) (tool))
(expression
(value (value
(empty)) (empty)))
(chain)) (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( source_file: $ => repeat(choice(
$.comment, $.comment,
$.expression, $.expression,
$.value,
$.yield, $.yield,
$.chain $.chain
)), )),
comment: $ => /(#)(.+?)([\n\r])/,
expression: $ => choice( expression: $ => choice(
$.identifier, prec(2, $.value),
prec(1, $.identifier),
$.tool, $.tool,
seq($.identifier, $.operator, $.expression), seq($.identifier, $.operator, $.expression),
seq($.value, $.operator, $.value)
), ),
value: $ => choice( value: $ => choice(
@ -25,8 +22,11 @@ module.exports = grammar({
$.string, $.string,
$.list, $.list,
$.empty, $.empty,
$.boolean,
), ),
comment: $ => /(#)(.+?)([\n\r])/,
yield: $ => "->", yield: $ => "->",
chain: $ => ";", chain: $ => ";",
@ -60,6 +60,11 @@ module.exports = grammar({
empty: $ => "()", empty: $ => "()",
boolean: $ => choice(
"true",
"false"
),
list: $ => seq( list: $ => seq(
'(', '(',
repeat1(seq($.expression, optional(','))), repeat1(seq($.expression, optional(','))),

View File

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

View File

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

File diff suppressed because it is too large Load Diff