Fix tests for new grammar

This commit is contained in:
Jeff 2023-10-01 06:09:29 -04:00
parent 43432591b3
commit 63d495c1e1
11 changed files with 11823 additions and 9227 deletions

View File

@ -34,13 +34,13 @@ x = if true then 1
(expression (expression
(assignment (assignment
(identifier) (identifier)
(expression (statement
(control_flow (expression
(expression (control_flow
(value
(boolean)))
(statement
(expression (expression
(value (value
(integer))))))))))) (boolean)))
(statement
(expression
(value
(integer))))))))))))

View File

@ -32,8 +32,9 @@ foobar <"Hiya">
(expression (expression
(function_call (function_call
(identifier) (identifier)
(value (expression
(string))))))) (value
(string))))))))
================== ==================
Complex Function Complex Function

View File

@ -31,19 +31,20 @@ foobar = ['answer', 42]
(expression (expression
(assignment (assignment
(identifier) (identifier)
(expression (statement
(value (expression
(list (value
(value (list
(string)) (value
(value (string))
(integer)))))))))) (value
(integer)))))))))))
================== ==================
List Nesting List Nesting
================== ==================
foobar = ['answers', [42, [666]]] ['answers', [42, [666]]]
--- ---
@ -51,18 +52,15 @@ foobar = ['answers', [42, [666]]]
(item (item
(statement (statement
(expression (expression
(assignment (value
(identifier) (list
(expression (value
(string))
(value (value
(list (list
(value (value
(string)) (integer))
(value (value
(list (list
(value (value
(integer)) (integer))))))))))))
(value
(list
(value
(integer))))))))))))))

View File

@ -34,12 +34,13 @@ x = map {
(expression (expression
(assignment (assignment
(identifier) (identifier)
(expression (statement
(value (expression
(map
(identifier)
(value (value
(integer)))))))))) (map
(identifier)
(value
(integer)))))))))))
================== ==================
Map Access Map Access

View File

@ -39,17 +39,19 @@ y = "one"
(expression (expression
(assignment (assignment
(identifier) (identifier)
(expression (statement
(value (expression
(integer))))))) (value
(integer))))))))
(item (item
(statement (statement
(expression (expression
(assignment (assignment
(identifier) (identifier)
(expression (statement
(value (expression
(string)))))))) (value
(string)))))))))
================== ==================
Complex Assignment Complex Assignment
@ -65,12 +67,13 @@ x = 1 + 1
(expression (expression
(assignment (assignment
(identifier) (identifier)
(expression (statement
(math (expression
(expression (math
(value (expression
(integer))) (value
(math_operator) (integer)))
(expression (math_operator)
(value (expression
(integer)))))))))) (value
(integer)))))))))))

View File

@ -38,16 +38,17 @@ foobar = table <text, number> {
(expression (expression
(assignment (assignment
(identifier) (identifier)
(expression (statement
(value (expression
(table (value
(identifier) (table
(identifier) (identifier)
(list (identifier)
(value (list
(string)) (value
(value (string))
(integer))))))))))) (value
(integer))))))))))))
================== ==================
Table Access Table Access

71
corpus/yield.txt Normal file
View File

@ -0,0 +1,71 @@
==================
Simple Yield
==================
1 -> output
---
(root
(item
(statement
(yield
(expression
(value
(integer)))
(expression
(identifier))))))
==================
Complex Yield
==================
1 + 1 -> to_string -> output
---
(root
(item
(statement
(yield
(expression
(math
(expression
(value
(integer)))
(math_operator)
(expression
(value
(integer)))))
(expression
(identifier))
(expression
(identifier))))))
==================
Yield Assignment
==================
x = 1 + 1 -> to_string
---
(root
(item
(statement
(expression
(assignment
(identifier)
(statement
(yield
(expression
(math
(expression
(value
(integer)))
(math_operator)
(expression
(value
(integer)))))
(expression
(identifier)))))))))

View File

@ -18,7 +18,14 @@ module.exports = grammar({
$.yield, $.yield,
)), )),
yield: $ => prec.left(seq($.statement, '->', $.statement)), yield: $ => prec.left(
seq(
$.expression,
'->',
$.expression,
repeat(prec.left(seq('->', $.expression)))
)
),
expression: $ => choice( expression: $ => choice(
$._expression_kind, $._expression_kind,
@ -157,9 +164,7 @@ module.exports = grammar({
function_call: $ => prec.right(seq( function_call: $ => prec.right(seq(
$.identifier, $.identifier,
'<', '<',
repeat( repeat($.expression),
choice($.identifier, $.value),
),
'>', '>',
)), )),

View File

@ -63,7 +63,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "expression"
}, },
{ {
"type": "STRING", "type": "STRING",
@ -71,7 +71,27 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "expression"
},
{
"type": "REPEAT",
"content": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "->"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
}
} }
] ]
} }
@ -713,17 +733,8 @@
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "expression"
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "value"
}
]
} }
}, },
{ {

View File

@ -145,11 +145,11 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "identifier", "type": "expression",
"named": true "named": true
}, },
{ {
"type": "value", "type": "identifier",
"named": true "named": true
} }
] ]
@ -460,7 +460,7 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "statement", "type": "expression",
"named": true "named": true
} }
] ]

20801
src/parser.c

File diff suppressed because it is too large Load Diff