Continue syntax overhaul

This commit is contained in:
Jeff 2023-10-06 13:32:49 -04:00
parent 7398f073ed
commit 03c5664851
6 changed files with 4743 additions and 4069 deletions

View File

@ -21,7 +21,7 @@ function { "Hiya" }
Function Call
==================
foobar("Hiya")
(foobar "Hiya")
---
@ -40,8 +40,8 @@ Complex Function
==================
function <message number> {
output message
output number
(output message)
(output number)
}
---
@ -55,23 +55,23 @@ function <message number> {
(identifier)
(identifier)
(statement
(expression
(identifier)))
(expression
(tool_call
(tool)
(expression
(identifier)))))
(statement
(expression
(identifier)))
(statement
(expression
(identifier)))
(statement
(expression
(identifier)))))))))
(tool_call
(tool)
(expression
(identifier)))))))))))
==================
Complex Function Call
==================
foobar (
(foobar
"hi"
42
{

View File

@ -1,34 +1,170 @@
==================
Match
If
==================
match 21 + 21
42 => true
catch false
if true then "True"
---
(root
(item
(statement
(match
(if_else
(expression
(math
(value
(boolean)))
(statement
(expression
(value
(string))))))))
==================
If Assignment
==================
x = if true then 1
---
(root
(item
(statement
(assignment
(identifier)
(statement
(if_else
(expression
(value
(boolean)))
(statement
(expression
(value
(integer))))))))))
==================
If Else
==================
if false then "True" else "False"
---
(root
(item
(statement
(if_else
(expression
(value
(boolean)))
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))))))
==================
If Else If
==================
if 1 == 1
then "math is fun"
else if 4 == 9
then "math is broken"
---
(root
(item
(statement
(if_else
(expression
(logic
(expression
(value
(integer)))
(math_operator)
(logic_operator)
(expression
(value
(integer)))))
(statement
(expression
(value
(string))))
(statement
(if_else
(expression
(logic
(expression
(value
(integer)))
(logic_operator)
(expression
(value
(integer)))))
(statement
(expression
(value
(string))))))))))
==================
If Else Else If Else
==================
if false
then "no"
else if false
then "no"
else if 1 + 1 == 9
then "not the answer"
else "42"
---
(root
(item
(statement
(if_else
(expression
(value
(integer)))
(boolean)))
(statement
(expression
(value
(boolean))))
(string))))
(statement
(expression
(value
(boolean))))))))
(if_else
(expression
(value
(boolean)))
(statement
(expression
(value
(string))))
(statement
(if_else
(expression
(logic
(expression
(math
(expression
(value
(integer)))
(math_operator)
(expression
(value
(integer)))))
(logic_operator)
(expression
(value
(integer)))))
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))))))))))

View File

@ -35,6 +35,7 @@ module.exports = grammar({
$.value,
$.identifier,
$.function_call,
$.tool_call,
$.math,
$.logic,
),
@ -158,9 +159,9 @@ module.exports = grammar({
)),
function_call: $ => prec.right(seq(
$.identifier,
'(',
repeat(seq($.expression)),
$.identifier,
repeat(seq($.expression, optional(','))),
')',
)),
@ -188,5 +189,18 @@ module.exports = grammar({
'catch',
$.statement
)),
tool_call: $ => prec.right(1, seq(
'(',
$._tool,
')',
)),
_tool: $ => choice(
'input',
$.output,
),
output: $ => seq('output', $.expression),
}
});

View File

@ -124,6 +124,10 @@
"type": "SYMBOL",
"name": "function_call"
},
{
"type": "SYMBOL",
"name": "tool_call"
},
{
"type": "SYMBOL",
"name": "math"
@ -677,14 +681,14 @@
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "REPEAT",
"content": {
@ -693,6 +697,18 @@
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
@ -813,6 +829,53 @@
}
]
}
},
"tool_call": {
"type": "PREC_RIGHT",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_tool"
},
{
"type": "STRING",
"value": ")"
}
]
}
},
"_tool": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "input"
},
{
"type": "SYMBOL",
"name": "output"
}
]
},
"output": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "output"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
"extras": [

View File

@ -52,6 +52,10 @@
"type": "math",
"named": true
},
{
"type": "tool_call",
"named": true
},
{
"type": "value",
"named": true
@ -278,6 +282,21 @@
"named": true,
"fields": {}
},
{
"type": "output",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
},
{
"type": "root",
"named": true,
@ -374,6 +393,21 @@
]
}
},
{
"type": "tool_call",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "output",
"named": true
}
]
}
},
{
"type": "value",
"named": true,
@ -556,6 +590,10 @@
"type": "if",
"named": false
},
{
"type": "input",
"named": false
},
{
"type": "insert",
"named": false
@ -580,6 +618,10 @@
"type": "or",
"named": false
},
{
"type": "output",
"named": false
},
{
"type": "select",
"named": false

File diff suppressed because it is too large Load Diff