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
(assignment
(identifier)
(expression
(control_flow
(expression
(value
(boolean)))
(statement
(statement
(expression
(control_flow
(expression
(value
(integer)))))))))))
(boolean)))
(statement
(expression
(value
(integer))))))))))))

View File

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

View File

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

View File

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

View File

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

View File

@ -38,16 +38,17 @@ foobar = table <text, number> {
(expression
(assignment
(identifier)
(expression
(value
(table
(identifier)
(identifier)
(list
(value
(string))
(value
(integer)))))))))))
(statement
(expression
(value
(table
(identifier)
(identifier)
(list
(value
(string))
(value
(integer))))))))))))
==================
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: $ => prec.left(seq($.statement, '->', $.statement)),
yield: $ => prec.left(
seq(
$.expression,
'->',
$.expression,
repeat(prec.left(seq('->', $.expression)))
)
),
expression: $ => choice(
$._expression_kind,
@ -157,9 +164,7 @@ module.exports = grammar({
function_call: $ => prec.right(seq(
$.identifier,
'<',
repeat(
choice($.identifier, $.value),
),
repeat($.expression),
'>',
)),

View File

@ -63,7 +63,7 @@
"members": [
{
"type": "SYMBOL",
"name": "statement"
"name": "expression"
},
{
"type": "STRING",
@ -71,7 +71,27 @@
},
{
"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",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "value"
}
]
"type": "SYMBOL",
"name": "expression"
}
},
{

View File

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

20801
src/parser.c

File diff suppressed because it is too large Load Diff