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,6 +34,7 @@ x = if true then 1
(expression (expression
(assignment (assignment
(identifier) (identifier)
(statement
(expression (expression
(control_flow (control_flow
(expression (expression
@ -42,5 +43,4 @@ x = if true then 1
(statement (statement
(expression (expression
(value (value
(integer))))))))))) (integer))))))))))))

View File

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

View File

@ -31,28 +31,26 @@ foobar = ['answer', 42]
(expression (expression
(assignment (assignment
(identifier) (identifier)
(statement
(expression (expression
(value (value
(list (list
(value (value
(string)) (string))
(value (value
(integer)))))))))) (integer)))))))))))
================== ==================
List Nesting List Nesting
================== ==================
foobar = ['answers', [42, [666]]] ['answers', [42, [666]]]
--- ---
(root (root
(item (item
(statement (statement
(expression
(assignment
(identifier)
(expression (expression
(value (value
(list (list
@ -65,4 +63,4 @@ foobar = ['answers', [42, [666]]]
(value (value
(list (list
(value (value
(integer)))))))))))))) (integer))))))))))))

View File

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

View File

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

View File

@ -38,6 +38,7 @@ foobar = table <text, number> {
(expression (expression
(assignment (assignment
(identifier) (identifier)
(statement
(expression (expression
(value (value
(table (table
@ -47,7 +48,7 @@ foobar = table <text, number> {
(value (value
(string)) (string))
(value (value
(integer))))))))))) (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",
"members": [
{
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "expression"
},
{
"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