Change syntax

This commit is contained in:
Jeff 2023-09-30 21:12:35 -04:00
parent 14c294a1db
commit 69fda534a3
8 changed files with 9201 additions and 6770 deletions

@ -1 +1 @@
Subproject commit 327a2d044b4416ffe27d70c6c3485e6dea2b573c Subproject commit f596c6b5811cabc9b1b8ef87b9c6ce627b567c93

View File

@ -20,6 +20,24 @@ function { "Hiya" }
(value (value
(string)))))))))))) (string))))))))))))
==================
Function Call
==================
foobar <"Hiya">
---
(root
(item
(statement
(open_statement
(expression
(function_call
(identifier)
(value
(string))))))))
================== ==================
Complex Function Complex Function
================== ==================
@ -43,7 +61,7 @@ function <message, number> {
(statement (statement
(open_statement (open_statement
(expression (expression
(tool)))) (identifier))))
(statement (statement
(open_statement (open_statement
(expression (expression
@ -51,7 +69,7 @@ function <message, number> {
(statement (statement
(open_statement (open_statement
(expression (expression
(tool)))) (identifier))))
(statement (statement
(open_statement (open_statement
(expression (expression

49
corpus/operators.txt Normal file
View File

@ -0,0 +1,49 @@
==================
Simple Equality
==================
1 == 1
---
(root
(item
(statement
(open_statement
(expression
(operation
(expression
(value
(integer)))
(operator)
(expression
(value
(integer)))))))))
==================
Complex Equality
==================
(1 + 1) == 2
---
(root
(item
(statement
(open_statement
(expression
(operation
(expression
(operation
(expression
(value
(integer)))
(operator)
(expression
(value
(integer)))))
(operator)
(expression
(value
(integer)))))))))

View File

@ -7,7 +7,6 @@ Simple Statements
x x
--- ---
(root (root
(item (item
(statement (statement

View File

@ -11,7 +11,7 @@ module.exports = grammar({
$.statement, $.statement,
), ),
comment: $ => prec.left(seq(token('#'), /.*/)), comment: $ => seq(token('#'), /.*/),
statement: $ => prec.right(choice( statement: $ => prec.right(choice(
$.open_statement, $.open_statement,
@ -23,18 +23,25 @@ module.exports = grammar({
yield_statement: $ => seq($.open_statement, '->', $.open_statement), yield_statement: $ => seq($.open_statement, '->', $.open_statement),
expression: $ => choice( expression: $ => choice(
$._expression_kind,
seq('(', $._expression_kind, ')')
),
_expression_kind: $ => prec.right(choice(
$.value, $.value,
$.identifier, $.identifier,
$.operation,
$.control_flow, $.control_flow,
$.tool,
$.select, $.select,
$.insert, $.insert,
), $.function_call,
$.assignment,
$.math,
$.logic,
)),
identifier: $ => /[a-z|_|.]+[0-9]?/, identifier: $ => /[a-z|_|.]+[0-9]?/,
value: $ => choice( value: $ => prec.left(1, choice(
$.integer, $.integer,
$.float, $.float,
$.string, $.string,
@ -44,13 +51,17 @@ module.exports = grammar({
$.function, $.function,
$.table, $.table,
$.map, $.map,
), )),
float: $ => /\d+\.\d*/, float: $ => /\d+\.\d*/,
integer: $ => /\d+/, integer: $ => /\d+/,
string: $ => /("|'|`)(.*?)("|'|`)/, string: $ => choice(
/'([^"]+)'/,
/"([^"]+)"/,
/`([^"]+)`/
),
empty: $ => '()', empty: $ => '()',
@ -88,25 +99,37 @@ module.exports = grammar({
'}', '}',
), ),
operator: $ => choice( math: $ => prec.right(seq(
'=', $.expression,
$.math_operator,
$.expression,
)),
math_operator: $ => choice(
'+', '+',
'-', '-',
'*', '*',
'/', '/',
'%', '%',
),
logic: $ => prec.right(seq(
$.expression,
$.logic_operator,
$.expression,
)),
logic_operator: $ => choice(
'==', '==',
'+=',
'-=',
'&&', '&&',
'||', '||',
'and', 'and',
'or', 'or',
), ),
operation: $ => prec.right(seq( assignment: $ => prec.right(seq(
$.expression, $.identifier,
$.operator, choice("=", "+=", "-="),
$.expression, $.expression,
)), )),
@ -138,8 +161,13 @@ module.exports = grammar({
optional(seq('else', $.statement)) optional(seq('else', $.statement))
)), )),
tool: $ => choice( function_call: $ => prec.right(seq(
"output", $.identifier,
), '<',
repeat(
choice($.identifier, $.value),
),
'>',
)),
} }
}); });

View File

@ -23,24 +23,20 @@
] ]
}, },
"comment": { "comment": {
"type": "PREC_LEFT", "type": "SEQ",
"value": 0, "members": [
"content": { {
"type": "SEQ", "type": "TOKEN",
"members": [ "content": {
{ "type": "STRING",
"type": "TOKEN", "value": "#"
"content": {
"type": "STRING",
"value": "#"
}
},
{
"type": "PATTERN",
"value": ".*"
} }
] },
} {
"type": "PATTERN",
"value": ".*"
}
]
}, },
"statement": { "statement": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
@ -89,78 +85,120 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "value" "name": "_expression_kind"
}, },
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "identifier" "members": [
}, {
{ "type": "STRING",
"type": "SYMBOL", "value": "("
"name": "operation" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "_expression_kind"
"name": "control_flow" },
}, {
{ "type": "STRING",
"type": "SYMBOL", "value": ")"
"name": "tool" }
}, ]
{
"type": "SYMBOL",
"name": "select"
},
{
"type": "SYMBOL",
"name": "insert"
} }
] ]
}, },
"_expression_kind": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "value"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "control_flow"
},
{
"type": "SYMBOL",
"name": "select"
},
{
"type": "SYMBOL",
"name": "insert"
},
{
"type": "SYMBOL",
"name": "function_call"
},
{
"type": "SYMBOL",
"name": "assignment"
},
{
"type": "SYMBOL",
"name": "math"
},
{
"type": "SYMBOL",
"name": "logic"
}
]
}
},
"identifier": { "identifier": {
"type": "PATTERN", "type": "PATTERN",
"value": "[a-z|_|.]+[0-9]?" "value": "[a-z|_|.]+[0-9]?"
}, },
"value": { "value": {
"type": "CHOICE", "type": "PREC_LEFT",
"members": [ "value": 1,
{ "content": {
"type": "SYMBOL", "type": "CHOICE",
"name": "integer" "members": [
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "integer"
"name": "float" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "float"
"name": "string" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "string"
"name": "list" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "list"
"name": "empty" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "empty"
"name": "boolean" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "boolean"
"name": "function" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "function"
"name": "table" },
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "table"
"name": "map" },
} {
] "type": "SYMBOL",
"name": "map"
}
]
}
}, },
"float": { "float": {
"type": "PATTERN", "type": "PATTERN",
@ -171,8 +209,21 @@
"value": "\\d+" "value": "\\d+"
}, },
"string": { "string": {
"type": "PATTERN", "type": "CHOICE",
"value": "(\"|'|`)(.*?)(\"|'|`)" "members": [
{
"type": "PATTERN",
"value": "'([^\"]+)'"
},
{
"type": "PATTERN",
"value": "\"([^\"]+)\""
},
{
"type": "PATTERN",
"value": "`([^\"]+)`"
}
]
}, },
"empty": { "empty": {
"type": "STRING", "type": "STRING",
@ -395,13 +446,30 @@
} }
] ]
}, },
"operator": { "math": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "math_operator"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
"math_operator": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "STRING",
"value": "="
},
{ {
"type": "STRING", "type": "STRING",
"value": "+" "value": "+"
@ -421,19 +489,37 @@
{ {
"type": "STRING", "type": "STRING",
"value": "%" "value": "%"
}, }
]
},
"logic": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "logic_operator"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
"logic_operator": {
"type": "CHOICE",
"members": [
{ {
"type": "STRING", "type": "STRING",
"value": "==" "value": "=="
}, },
{
"type": "STRING",
"value": "+="
},
{
"type": "STRING",
"value": "-="
},
{ {
"type": "STRING", "type": "STRING",
"value": "&&" "value": "&&"
@ -452,7 +538,7 @@
} }
] ]
}, },
"operation": { "assignment": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
"value": 0, "value": 0,
"content": { "content": {
@ -460,11 +546,24 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "identifier"
}, },
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "operator" "members": [
{
"type": "STRING",
"value": "="
},
{
"type": "STRING",
"value": "+="
},
{
"type": "STRING",
"value": "-="
}
]
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -614,14 +713,42 @@
] ]
} }
}, },
"tool": { "function_call": {
"type": "CHOICE", "type": "PREC_RIGHT",
"members": [ "value": 0,
{ "content": {
"type": "STRING", "type": "SEQ",
"value": "output" "members": [
} {
] "type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "<"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "value"
}
]
}
},
{
"type": "STRING",
"value": ">"
}
]
}
} }
}, },
"extras": [ "extras": [

View File

@ -1,4 +1,23 @@
[ [
{
"type": "assignment",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
{ {
"type": "boolean", "type": "boolean",
"named": true, "named": true,
@ -36,10 +55,18 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "assignment",
"named": true
},
{ {
"type": "control_flow", "type": "control_flow",
"named": true "named": true
}, },
{
"type": "function_call",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -49,17 +76,17 @@
"named": true "named": true
}, },
{ {
"type": "operation", "type": "logic",
"named": true
},
{
"type": "math",
"named": true "named": true
}, },
{ {
"type": "select", "type": "select",
"named": true "named": true
}, },
{
"type": "tool",
"named": true
},
{ {
"type": "value", "type": "value",
"named": true "named": true
@ -86,6 +113,25 @@
] ]
} }
}, },
{
"type": "function_call",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "value",
"named": true
}
]
}
},
{ {
"type": "insert", "type": "insert",
"named": true, "named": true,
@ -143,6 +189,30 @@
] ]
} }
}, },
{
"type": "logic",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "logic_operator",
"named": true
}
]
}
},
{
"type": "logic_operator",
"named": true,
"fields": {}
},
{ {
"type": "map", "type": "map",
"named": true, "named": true,
@ -162,6 +232,30 @@
] ]
} }
}, },
{
"type": "math",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "math_operator",
"named": true
}
]
}
},
{
"type": "math_operator",
"named": true,
"fields": {}
},
{ {
"type": "open_statement", "type": "open_statement",
"named": true, "named": true,
@ -177,30 +271,6 @@
] ]
} }
}, },
{
"type": "operation",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "operator",
"named": true
}
]
}
},
{
"type": "operator",
"named": true,
"fields": {}
},
{ {
"type": "root", "type": "root",
"named": true, "named": true,
@ -254,6 +324,11 @@
] ]
} }
}, },
{
"type": "string",
"named": true,
"fields": {}
},
{ {
"type": "table", "type": "table",
"named": true, "named": true,
@ -273,11 +348,6 @@
] ]
} }
}, },
{
"type": "tool",
"named": true,
"fields": {}
},
{ {
"type": "value", "type": "value",
"named": true, "named": true,
@ -352,6 +422,14 @@
"type": "&&", "type": "&&",
"named": false "named": false
}, },
{
"type": "(",
"named": false
},
{
"type": ")",
"named": false
},
{ {
"type": "*", "type": "*",
"named": false "named": false
@ -464,18 +542,10 @@
"type": "or", "type": "or",
"named": false "named": false
}, },
{
"type": "output",
"named": false
},
{ {
"type": "select", "type": "select",
"named": false "named": false
}, },
{
"type": "string",
"named": true
},
{ {
"type": "table", "type": "table",
"named": false "named": false

15340
src/parser.c

File diff suppressed because it is too large Load Diff