Implement new grammar

This commit is contained in:
Jeff 2023-10-09 14:39:47 -04:00
parent d7ff4e57c5
commit 532c751c36
16 changed files with 6343 additions and 11745 deletions

167
Cargo.lock generated Normal file
View File

@ -0,0 +1,167 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab"
dependencies = [
"memchr",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "cc"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crossbeam-deque"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
dependencies = [
"cfg-if",
]
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "libc"
version = "0.2.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]]
name = "memchr"
version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "memoffset"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [
"autocfg",
]
[[package]]
name = "rayon"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "regex"
version = "1.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "tree-sitter"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e747b1f9b7b931ed39a548c1fae149101497de3c1fc8d9e18c62c1a66c683d3d"
dependencies = [
"cc",
"regex",
]
[[package]]
name = "tree-sitter-dust"
version = "0.0.1"
dependencies = [
"cc",
"rayon",
"tree-sitter",
]

View File

@ -20,6 +20,7 @@ include = [
path = "bindings/rust/lib.rs" path = "bindings/rust/lib.rs"
[dependencies] [dependencies]
rayon = "1.8.0"
tree-sitter = "~0.20.10" tree-sitter = "~0.20.10"
[build-dependencies] [build-dependencies]

View File

@ -13,7 +13,8 @@ not_a_comment
(expression (expression
(identifier)))) (identifier))))
(item (item
(comment))) (statement
(comment))))
================== ==================
Partial Line Comments Partial Line Comments
@ -29,4 +30,5 @@ not_a_comment # comment
(expression (expression
(identifier)))) (identifier))))
(item (item
(comment))) (statement
(comment))))

View File

@ -2,7 +2,7 @@
If If
================== ==================
if true then "True" if true { "True" }
--- ---
@ -10,19 +10,20 @@ if true then "True"
(item (item
(statement (statement
(if_else (if_else
(if
(expression (expression
(value (value
(boolean))) (boolean)))
(statement (statement
(expression (expression
(value (value
(string)))))))) (string)))))))))
================== ==================
If Assignment If Assignment
================== ==================
x = if true then 1 x = if true { 1 }
--- ---
@ -31,21 +32,23 @@ x = if true then 1
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator)
(statement (statement
(if_else (if_else
(if
(expression (expression
(value (value
(boolean))) (boolean)))
(statement (statement
(expression (expression
(value (value
(integer)))))))))) (integer)))))))))))
================== ==================
If Else If Else
================== ==================
if false then "True" else "False" if false { "True" } else { "False" }
--- ---
@ -53,26 +56,29 @@ if false then "True" else "False"
(item (item
(statement (statement
(if_else (if_else
(if
(expression (expression
(value (value
(boolean))) (boolean)))
(statement (statement
(expression (expression
(value (value
(string)))) (string)))))
(else
(statement (statement
(expression (expression
(value (value
(string)))))))) (string)))))))))
================== ==================
If Else If If Else If
================== ==================
if 1 == 1 if 1 == 1 {
then "math is fun" "math is fun"
else if 4 == 9 } else if 4 == 9 {
then "math is broken" "math is broken"
}
--- ---
@ -80,6 +86,7 @@ else if 4 == 9
(item (item
(statement (statement
(if_else (if_else
(if
(expression (expression
(logic (logic
(expression (expression
@ -92,9 +99,8 @@ else if 4 == 9
(statement (statement
(expression (expression
(value (value
(string)))) (string)))))
(statement (else_if
(if_else
(expression (expression
(logic (logic
(expression (expression
@ -107,19 +113,21 @@ else if 4 == 9
(statement (statement
(expression (expression
(value (value
(string)))))))))) (string)))))))))
================== ==================
If Else Else If Else If Else Else If Else
================== ==================
if false if false {
then "no" "no"
else if false } else if false {
then "no" "no"
else if 1 + 1 == 9 } else if 1 + 1 == 9 {
then "not the answer" "not the answer"
else "42" } else {
"42"
}
--- ---
@ -127,24 +135,23 @@ else "42"
(item (item
(statement (statement
(if_else (if_else
(if
(expression (expression
(value (value
(boolean))) (boolean)))
(statement (statement
(expression (expression
(value (value
(string)))) (string)))))
(statement (else_if
(if_else
(expression (expression
(value (value
(boolean))) (boolean)))
(statement (statement
(expression (expression
(value (value
(string)))) (string)))))
(statement (else_if
(if_else
(expression (expression
(logic (logic
(expression (expression
@ -163,8 +170,9 @@ else "42"
(statement (statement
(expression (expression
(value (value
(string)))) (string)))))
(else
(statement (statement
(expression (expression
(value (value
(string)))))))))))) (string)))))))))

View File

@ -12,10 +12,11 @@ function { "Hiya" }
(expression (expression
(value (value
(function (function
(item
(statement (statement
(expression (expression
(value (value
(string)))))))))) (string)))))))))))
================== ==================
Function Call Function Call
@ -54,16 +55,17 @@ function <message number> {
(function (function
(identifier) (identifier)
(identifier) (identifier)
(item
(statement (statement
(expression (expression
(tool_call (function_call
(output (identifier)
(expression (expression
(identifier)))))) (identifier)))))
(statement (statement
(expression (expression
(tool_call (function_call
(output (identifier)
(expression (expression
(identifier)))))))))))) (identifier))))))))))))
@ -98,8 +100,10 @@ Complex Function Call
(value (value
(map (map
(identifier) (identifier)
(expression
(value (value
(integer)) (integer)))
(identifier) (identifier)
(expression
(value (value
(integer)))))))))) (integer)))))))))))

View File

@ -12,16 +12,18 @@ List Declaration
(expression (expression
(value (value
(list (list
(expression
(value (value
(string)) (string)))
(expression
(value (value
(integer)))))))) (integer)))))))))
================== ==================
List Assignment List Assignment
================== ==================
foobar = ['answer', 42] foobar = ['foobar']
--- ---
@ -30,14 +32,14 @@ foobar = ['answer', 42]
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator)
(statement (statement
(expression (expression
(value (value
(list (list
(expression
(value (value
(string)) (string)))))))))))
(value
(integer))))))))))
================== ==================
List Nesting List Nesting
@ -53,38 +55,18 @@ List Nesting
(expression (expression
(value (value
(list (list
(expression
(value (value
(string)) (string)))
(value
(list
(value
(integer))
(value
(list
(value
(integer))))))))))))
==================
Optional Commas
==================
['answers' [42 [666]]]
---
(root
(item
(statement
(expression (expression
(value (value
(list (list
(expression
(value (value
(string)) (integer)))
(expression
(value (value
(list (list
(expression
(value (value
(integer)) (integer)))))))))))))))
(value
(list
(value
(integer))))))))))))

View File

@ -15,8 +15,9 @@ Simple Map
(value (value
(map (map
(identifier) (identifier)
(expression
(value (value
(integer)))))))) (integer)))))))))
================== ==================
Map Assignment Map Assignment
@ -33,13 +34,15 @@ x = {
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator)
(statement (statement
(expression (expression
(value (value
(map (map
(identifier) (identifier)
(expression
(value (value
(integer)))))))))) (integer)))))))))))
================== ==================
Map Access Map Access

View File

@ -1,170 +0,0 @@
==================
If
==================
if true then "True"
---
(root
(item
(statement
(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
(math
(expression
(value
(integer)))
(math_operator)
(expression
(value
(integer)))))
(logic_operator)
(expression
(value
(integer)))))
(statement
(expression
(value
(string))))
(statement
(expression
(value
(string))))))))))))

View File

@ -38,6 +38,7 @@ y = "one"
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator)
(statement (statement
(expression (expression
(value (value
@ -46,6 +47,7 @@ y = "one"
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator)
(statement (statement
(expression (expression
(value (value
@ -64,6 +66,7 @@ x = 1 + 1
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator)
(expression (expression
(math (math
(expression (expression

View File

@ -16,11 +16,15 @@ table <text, number> {
(table (table
(identifier) (identifier)
(identifier) (identifier)
(expression
(value
(list (list
(expression
(value (value
(string)) (string)))
(expression
(value (value
(integer))))))))) (integer))))))))))))
================== ==================
Table Assignment Table Assignment
@ -37,17 +41,22 @@ foobar = table <text, number> {
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator)
(statement (statement
(expression (expression
(value (value
(table (table
(identifier) (identifier)
(identifier) (identifier)
(expression
(value
(list (list
(expression
(value (value
(string)) (string)))
(expression
(value (value
(integer))))))))))) (integer))))))))))))))
================== ==================
Table Access Table Access
@ -86,8 +95,10 @@ insert ['bob was here', 0] into foobar
(statement (statement
(insert (insert
(list (list
(expression
(value (value
(string)) (string)))
(expression
(value (value
(integer))) (integer))))
(identifier))))) (identifier)))))

View File

@ -3,7 +3,7 @@ While Loop
================== ==================
while true { while true {
(output "This is a bad idea...") (print "This is a bad idea...")
} }
--- ---
@ -18,17 +18,17 @@ while true {
(item (item
(statement (statement
(expression (expression
(tool_call (function_call
(output (tool)
(expression (expression
(value (value
(string)))))))))))) (string)))))))))))
================== ==================
While Assignment While Loop Assignment
================== ==================
foo = while true { answer = while false {
42 42
} }
@ -39,6 +39,7 @@ foo = while true {
(statement (statement
(assignment (assignment
(identifier) (identifier)
(assignment_operator)
(statement (statement
(while (while
(expression (expression

View File

@ -1,43 +0,0 @@
==================
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))))))

View File

@ -6,38 +6,24 @@ module.exports = grammar({
rules: { rules: {
root: $ => repeat1($.item), root: $ => repeat1($.item),
item: $ => choice( item: $ => prec.left(repeat1($.statement)),
$.comment,
$.statement,
),
comment: $ => seq('#', /.*/), // TODO: New comment that can be used anyhere.
// Keep this comment type for later use.
statement: $ => choice( statement: $ => choice(
$.comment,
$.assignment, $.assignment,
$.expression, $.expression,
$.if_else, $.if_else,
$.yield,
$.insert, $.insert,
$.select, $.select,
$.loop,
$.match,
$.while, $.while,
), ),
yield: $ => seq( comment: $ => seq(/[#]+.*/),
$.expression,
'->',
$.expression,
repeat(prec.left(seq('->', $.expression)))
),
expression: $ => prec.right(choice( expression: $ => prec.right(choice(
$.value, $.value,
$.identifier, $.identifier,
$.function_call, $.function_call,
$.tool_call,
$.math, $.math,
$.logic, $.logic,
)), )),
@ -68,7 +54,7 @@ module.exports = grammar({
list: $ => seq( list: $ => seq(
'[', '[',
repeat1(seq($.value, optional(','))), repeat(seq($.expression, optional(','))),
']' ']'
), ),
@ -76,7 +62,7 @@ module.exports = grammar({
'function', 'function',
optional(seq('<', repeat(seq($.identifier, optional(','))), '>')), optional(seq('<', repeat(seq($.identifier, optional(','))), '>')),
'{', '{',
repeat1($.item), $.item,
'}', '}',
), ),
@ -84,13 +70,13 @@ module.exports = grammar({
'table', 'table',
seq('<', repeat1(seq($.identifier, optional(','))), '>'), seq('<', repeat1(seq($.identifier, optional(','))), '>'),
'{', '{',
repeat($.list), repeat($.expression),
'}', '}',
), ),
map: $ => seq( map: $ => seq(
'{', '{',
repeat(seq($.identifier, "=", $.value)), // TODO: Replace value with expression repeat(seq($.identifier, "=", $.expression)),
'}', '}',
), ),
@ -119,48 +105,56 @@ module.exports = grammar({
'!=', '!=',
'&&', '&&',
'||', '||',
'>',
'<',
">=",
"<=",
), ),
assignment: $ => prec.right(seq( assignment: $ => prec.right(seq(
$.identifier, $.identifier,
choice("=", "+=", "-="), $.assignment_operator,
$.statement, $.statement,
)), )),
select: $ => prec.right(seq( assignment_operator: $ => choice(
'select', "=",
$.identifier, "+=",
'from', "-=",
$.identifier,
optional(
seq('where', $.expression)
), ),
if_else: $ => prec.left(seq(
$.if,
repeat(seq($.else_if)),
optional(seq($.else)),
)), )),
insert: $ => prec.right(1, seq( if: $ => seq(
'insert',
repeat1($.list),
'into',
$.identifier,
optional(
seq('where', $.logic)
),
)),
if_else: $ => prec.left(1, seq(
'if', 'if',
$.expression, $.expression,
'then', '{',
$.statement, $.statement,
optional(seq( '}',
),
else_if: $ => seq(
'else if',
$.expression,
'{',
$.statement,
'}',
),
else: $ => seq(
'else', 'else',
'{',
$.statement, $.statement,
)), '}',
)), ),
function_call: $ => prec.right(seq( function_call: $ => prec.right(seq(
'(', '(',
$.identifier, choice($.identifier, $.tool),
repeat(seq($.expression, optional(','))), repeat(seq($.expression, optional(','))),
')', ')',
)), )),
@ -173,36 +167,40 @@ module.exports = grammar({
'}', '}',
), ),
loop: $ => seq( for: $ => seq(
'loop', 'for',
$.identifier,
'in',
$.expression,
'{', '{',
repeat($.statement), $.item,
'break',
optional($.value),
'}', '}',
), ),
match: $ => prec.right(seq( tool: $ => choice(
'match', 'print',
$.expression, 'read',
repeat1(seq($.expression, '=>', $.statement)), 'write',
'catch',
$.statement
)),
tool_call: $ => prec.right(1, seq(
'(',
$._tool,
')',
)),
_tool: $ => choice(
$.input,
$.output,
), ),
input: $ => seq('input', $.expression), select: $ => prec.right(seq(
output: $ => seq('output', $.expression), 'select',
read: $ => seq('read', $.expression), $.identifier,
'from',
$.identifier,
optional(
seq('where', $.expression)
),
)),
insert: $ => prec.right(seq(
'insert',
repeat1($.list),
'into',
$.identifier,
optional(
seq('where', $.logic)
),
)),
} }
}); });

View File

@ -10,34 +10,23 @@
} }
}, },
"item": { "item": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "statement"
}
}
},
"statement": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "comment" "name": "comment"
}, },
{
"type": "SYMBOL",
"name": "statement"
}
]
},
"comment": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "#"
},
{
"type": "PATTERN",
"value": ".*"
}
]
},
"statement": {
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "assignment" "name": "assignment"
@ -50,10 +39,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "if_else" "name": "if_else"
}, },
{
"type": "SYMBOL",
"name": "yield"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "insert" "name": "insert"
@ -62,54 +47,18 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "select" "name": "select"
}, },
{
"type": "SYMBOL",
"name": "loop"
},
{
"type": "SYMBOL",
"name": "match"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "while" "name": "while"
} }
] ]
}, },
"yield": { "comment": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "PATTERN",
"name": "expression" "value": "[#]+.*"
},
{
"type": "STRING",
"value": "->"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "REPEAT",
"content": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "->"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
}
} }
] ]
}, },
@ -131,10 +80,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "function_call" "name": "function_call"
}, },
{
"type": "SYMBOL",
"name": "tool_call"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "math" "name": "math"
@ -220,13 +165,13 @@
"value": "[" "value": "["
}, },
{ {
"type": "REPEAT1", "type": "REPEAT",
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "value" "name": "expression"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -306,11 +251,8 @@
"value": "{" "value": "{"
}, },
{ {
"type": "REPEAT1",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "item" "name": "item"
}
}, },
{ {
"type": "STRING", "type": "STRING",
@ -370,7 +312,7 @@
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "list" "name": "expression"
} }
}, },
{ {
@ -401,7 +343,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "value" "name": "expression"
} }
] ]
} }
@ -497,6 +439,22 @@
{ {
"type": "STRING", "type": "STRING",
"value": "||" "value": "||"
},
{
"type": "STRING",
"value": ">"
},
{
"type": "STRING",
"value": "<"
},
{
"type": "STRING",
"value": ">="
},
{
"type": "STRING",
"value": "<="
} }
] ]
}, },
@ -511,6 +469,17 @@
"name": "identifier" "name": "identifier"
}, },
{ {
"type": "SYMBOL",
"name": "assignment_operator"
},
{
"type": "SYMBOL",
"name": "statement"
}
]
}
},
"assignment_operator": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -527,34 +496,27 @@
} }
] ]
}, },
{ "if_else": {
"type": "SYMBOL", "type": "PREC_LEFT",
"name": "statement"
}
]
}
},
"select": {
"type": "PREC_RIGHT",
"value": 0, "value": 0,
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING", "type": "SYMBOL",
"value": "select" "name": "if"
}, },
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "else_if"
}, }
{ ]
"type": "STRING", }
"value": "from"
},
{
"type": "SYMBOL",
"name": "identifier"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@ -562,13 +524,9 @@
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "STRING",
"value": "where"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "else"
} }
] ]
}, },
@ -580,59 +538,7 @@
] ]
} }
}, },
"insert": { "if": {
"type": "PREC_RIGHT",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "insert"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "list"
}
},
{
"type": "STRING",
"value": "into"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "where"
},
{
"type": "SYMBOL",
"name": "logic"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
},
"if_else": {
"type": "PREC_LEFT",
"value": 1,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -645,16 +551,44 @@
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "then" "value": "{"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "statement"
}, },
{ {
"type": "CHOICE", "type": "STRING",
"value": "}"
}
]
},
"else_if": {
"type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING",
"value": "else if"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "statement"
},
{
"type": "STRING",
"value": "}"
}
]
},
"else": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -662,18 +596,18 @@
"value": "else" "value": "else"
}, },
{ {
"type": "SYMBOL", "type": "STRING",
"name": "statement" "value": "{"
}
]
}, },
{ {
"type": "BLANK" "type": "SYMBOL",
"name": "statement"
},
{
"type": "STRING",
"value": "}"
} }
] ]
}
]
}
}, },
"function_call": { "function_call": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
@ -685,10 +619,19 @@
"type": "STRING", "type": "STRING",
"value": "(" "value": "("
}, },
{
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
}, },
{
"type": "SYMBOL",
"name": "tool"
}
]
},
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
@ -745,39 +688,32 @@
} }
] ]
}, },
"loop": { "for": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING", "type": "STRING",
"value": "loop" "value": "for"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "expression"
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "{" "value": "{"
}, },
{ {
"type": "REPEAT",
"content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "item"
}
},
{
"type": "STRING",
"value": "break"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "BLANK"
}
]
}, },
{ {
"type": "STRING", "type": "STRING",
@ -785,7 +721,24 @@
} }
] ]
}, },
"match": { "tool": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "print"
},
{
"type": "STRING",
"value": "read"
},
{
"type": "STRING",
"value": "write"
}
]
},
"select": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
"value": 0, "value": 0,
"content": { "content": {
@ -793,116 +746,93 @@
"members": [ "members": [
{ {
"type": "STRING", "type": "STRING",
"value": "match" "value": "select"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "from"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "where"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "expression"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
},
"insert": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "insert"
}, },
{ {
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "list"
},
{
"type": "STRING",
"value": "=>"
},
{
"type": "SYMBOL",
"name": "statement"
}
]
} }
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "catch" "value": "into"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "identifier"
}
]
}
},
"tool_call": {
"type": "PREC_RIGHT",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
}, },
{ {
"type": "SYMBOL",
"name": "_tool"
},
{
"type": "STRING",
"value": ")"
}
]
}
},
"_tool": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL",
"name": "input"
},
{
"type": "SYMBOL",
"name": "output"
}
]
},
"input": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "STRING", "type": "STRING",
"value": "input" "value": "where"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "logic"
} }
] ]
}, },
"output": {
"type": "SEQ",
"members": [
{ {
"type": "STRING", "type": "BLANK"
"value": "output"
},
{
"type": "SYMBOL",
"name": "expression"
} }
] ]
},
"read": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "read"
},
{
"type": "SYMBOL",
"name": "expression"
} }
] ]
} }
}
}, },
"extras": [ "extras": [
{ {

View File

@ -7,6 +7,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "assignment_operator",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -18,6 +22,11 @@
] ]
} }
}, },
{
"type": "assignment_operator",
"named": true,
"fields": {}
},
{ {
"type": "boolean", "type": "boolean",
"named": true, "named": true,
@ -28,6 +37,40 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "else",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "statement",
"named": true
}
]
}
},
{
"type": "else_if",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "statement",
"named": true
}
]
}
},
{ {
"type": "expression", "type": "expression",
"named": true, "named": true,
@ -52,10 +95,6 @@
"type": "math", "type": "math",
"named": true "named": true
}, },
{
"type": "tool_call",
"named": true
},
{ {
"type": "value", "type": "value",
"named": true "named": true
@ -97,12 +136,16 @@
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "tool",
"named": true
} }
] ]
} }
}, },
{ {
"type": "if_else", "type": "if",
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
@ -121,15 +164,23 @@
} }
}, },
{ {
"type": "input", "type": "if_else",
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": false, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "expression", "type": "else",
"named": true
},
{
"type": "else_if",
"named": true
},
{
"type": "if",
"named": true "named": true
} }
] ]
@ -163,13 +214,9 @@
"named": true, "named": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": false, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "comment",
"named": true
},
{ {
"type": "statement", "type": "statement",
"named": true "named": true
@ -183,10 +230,10 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "value", "type": "expression",
"named": true "named": true
} }
] ]
@ -216,25 +263,6 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "loop",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "statement",
"named": true
},
{
"type": "value",
"named": true
}
]
}
},
{ {
"type": "map", "type": "map",
"named": true, "named": true,
@ -242,32 +270,13 @@
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "value",
"named": true
}
]
}
},
{
"type": "match",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [ "types": [
{ {
"type": "expression", "type": "expression",
"named": true "named": true
}, },
{ {
"type": "statement", "type": "identifier",
"named": true "named": true
} }
] ]
@ -297,21 +306,6 @@
"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,
@ -358,6 +352,10 @@
"type": "assignment", "type": "assignment",
"named": true "named": true
}, },
{
"type": "comment",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -370,14 +368,6 @@
"type": "insert", "type": "insert",
"named": true "named": true
}, },
{
"type": "loop",
"named": true
},
{
"type": "match",
"named": true
},
{ {
"type": "select", "type": "select",
"named": true "named": true
@ -385,10 +375,6 @@
{ {
"type": "while", "type": "while",
"named": true "named": true
},
{
"type": "yield",
"named": true
} }
] ]
} }
@ -401,35 +387,21 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "expression",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "list",
"named": true
} }
] ]
} }
}, },
{ {
"type": "tool_call", "type": "tool",
"named": true, "named": true,
"fields": {}, "fields": {}
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "input",
"named": true
},
{
"type": "output",
"named": true
}
]
}
}, },
{ {
"type": "value", "type": "value",
@ -493,29 +465,10 @@
] ]
} }
}, },
{
"type": "yield",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
},
{ {
"type": "!=", "type": "!=",
"named": false "named": false
}, },
{
"type": "#",
"named": false
},
{ {
"type": "%", "type": "%",
"named": false "named": false
@ -556,10 +509,6 @@
"type": "-=", "type": "-=",
"named": false "named": false
}, },
{
"type": "->",
"named": false
},
{ {
"type": "/", "type": "/",
"named": false "named": false
@ -568,6 +517,10 @@
"type": "<", "type": "<",
"named": false "named": false
}, },
{
"type": "<=",
"named": false
},
{ {
"type": "=", "type": "=",
"named": false "named": false
@ -577,11 +530,11 @@
"named": false "named": false
}, },
{ {
"type": "=>", "type": ">",
"named": false "named": false
}, },
{ {
"type": ">", "type": ">=",
"named": false "named": false
}, },
{ {
@ -592,18 +545,14 @@
"type": "]", "type": "]",
"named": false "named": false
}, },
{
"type": "break",
"named": false
},
{
"type": "catch",
"named": false
},
{ {
"type": "else", "type": "else",
"named": false "named": false
}, },
{
"type": "else if",
"named": false
},
{ {
"type": "false", "type": "false",
"named": false "named": false
@ -612,6 +561,10 @@
"type": "float", "type": "float",
"named": true "named": true
}, },
{
"type": "for",
"named": false
},
{ {
"type": "from", "type": "from",
"named": false "named": false
@ -629,7 +582,7 @@
"named": false "named": false
}, },
{ {
"type": "input", "type": "in",
"named": false "named": false
}, },
{ {
@ -645,15 +598,7 @@
"named": false "named": false
}, },
{ {
"type": "loop", "type": "print",
"named": false
},
{
"type": "match",
"named": false
},
{
"type": "output",
"named": false "named": false
}, },
{ {
@ -672,10 +617,6 @@
"type": "table", "type": "table",
"named": false "named": false
}, },
{
"type": "then",
"named": false
},
{ {
"type": "true", "type": "true",
"named": false "named": false
@ -688,6 +629,10 @@
"type": "while", "type": "while",
"named": false "named": false
}, },
{
"type": "write",
"named": false
},
{ {
"type": "{", "type": "{",
"named": false "named": false

16404
src/parser.c

File diff suppressed because it is too large Load Diff