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 Function Call
================== ==================
foobar("Hiya") (foobar "Hiya")
--- ---
@ -40,8 +40,8 @@ Complex Function
================== ==================
function <message number> { function <message number> {
output message (output message)
output number (output number)
} }
--- ---
@ -56,22 +56,22 @@ function <message number> {
(identifier) (identifier)
(statement (statement
(expression (expression
(identifier))) (tool_call
(tool)
(expression
(identifier)))))
(statement (statement
(expression (expression
(identifier))) (tool_call
(statement (tool)
(expression (expression
(identifier))) (identifier)))))))))))
(statement
(expression
(identifier)))))))))
================== ==================
Complex Function Call Complex Function Call
================== ==================
foobar ( (foobar
"hi" "hi"
42 42
{ {

View File

@ -1,17 +1,152 @@
================== ==================
Match If
================== ==================
match 21 + 21 if true then "True"
42 => true
catch false
--- ---
(root (root
(item (item
(statement (statement
(match (if_else
(expression
(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)))
(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
(boolean)))
(statement
(expression
(value
(string))))
(statement
(if_else
(expression
(value
(boolean)))
(statement
(expression
(value
(string))))
(statement
(if_else
(expression
(logic
(expression (expression
(math (math
(expression (expression
@ -21,14 +156,15 @@ catch false
(expression (expression
(value (value
(integer))))) (integer)))))
(logic_operator)
(expression (expression
(value (value
(integer))) (integer)))))
(statement (statement
(expression (expression
(value (value
(boolean)))) (string))))
(statement (statement
(expression (expression
(value (value
(boolean)))))))) (string))))))))))))

View File

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

View File

@ -124,6 +124,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "function_call" "name": "function_call"
}, },
{
"type": "SYMBOL",
"name": "tool_call"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "math" "name": "math"
@ -677,14 +681,14 @@
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{ {
"type": "STRING", "type": "STRING",
"value": "(" "value": "("
}, },
{
"type": "SYMBOL",
"name": "identifier"
},
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
@ -693,6 +697,18 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "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": [ "extras": [

View File

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

File diff suppressed because it is too large Load Diff