Revise syntax

This commit is contained in:
Jeff 2023-10-31 16:25:13 -04:00
parent df7cd0e972
commit ea4ffb492c
8 changed files with 39118 additions and 40842 deletions

View File

@ -53,8 +53,9 @@ function <message number> {
(expression
(value
(function
(parameter_list
(identifier)
(identifier)
(identifier))
(block
(statement
(expression

View File

@ -24,7 +24,7 @@ if true { "True" }
Complex If
==================
if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
if 1 == 1 && 2 == 2 && 3 == 3 "True"
---
@ -76,13 +76,11 @@ if 1 == 1 && 2 == 2 && 3 == 3 { "True" }
Nested If
==================
if true {
if 42 == 12 {
if true
if 42 == 12
'hiya'
} else {
else
'bye'
}
}
---

View File

@ -3,7 +3,7 @@ Simple Statements
==================
1
"one"
"one";
x
---
@ -26,7 +26,7 @@ x
Simple Assignment
==================
x = 1
x = 1;
y = "one"
---

View File

@ -2,10 +2,10 @@
Table Declaration
==================
table <messages, numbers> [
['hiya', 42]
['foo', 57]
['bar', 99.99]
table messages numbers [
['hiya' 42]
['foo' 57]
['bar' 99.99]
]
---
@ -16,8 +16,9 @@ table <messages, numbers> [
(expression
(value
(table
(parameter_list
(identifier)
(identifier)
(identifier))
(expression
(value
(list
@ -63,7 +64,8 @@ select <number> from foobar {
(block
(statement
(select
(identifier)
(parameter_list
(identifier))
(expression
(identifier))
(block

View File

@ -19,7 +19,8 @@ module.exports = grammar({
seq('{', repeat1($.statement), '}'),
)),
statement: $ => prec.right(choice(
statement: $ => prec.right(seq(
choice(
$.assignment,
$.async,
$.expression,
@ -34,9 +35,11 @@ module.exports = grammar({
$.select,
$.transform,
$.while,
),
optional(';'),
)),
expression: $ => prec.left(choice(
expression: $ => prec.right(choice(
$._expression_kind,
seq('(', $._expression_kind, ')'),
)),
@ -50,6 +53,8 @@ module.exports = grammar({
$.value,
)),
_expression_list: $ => repeat1(prec.right(seq($.expression, optional(',')))),
identifier: $ => /[_a-zA-Z]+[_a-zA-Z0-9]?/,
value: $ => choice(
@ -111,9 +116,16 @@ module.exports = grammar({
)),
)),
table: $ => prec.left(seq(
_identifier_list: $ => repeat1(seq($.identifier, optional(','))),
parameter_list: $ => prec.right(choice(
$._identifier_list,
seq('<', $._identifier_list, '>'),
)),
table: $ => prec.right(seq(
'table',
seq('<', repeat1(seq($.identifier, optional(','))), '>'),
$.parameter_list,
$.expression,
)),
@ -160,28 +172,28 @@ module.exports = grammar({
"-=",
),
if_else: $ => prec.left(seq(
if_else: $ => prec.right(seq(
$.if,
repeat($.else_if),
optional($.else),
)),
if: $ => prec.left(seq(
if: $ => seq(
'if',
$.expression,
$.block,
)),
),
else_if: $ => prec.left(seq(
else_if: $ => seq(
'else if',
$.expression,
$.block,
)),
),
else: $ => prec.left(seq(
else: $ => seq(
'else',
$.block,
)),
),
match: $ => prec.right(seq(
'match',
@ -252,9 +264,7 @@ module.exports = grammar({
select: $ => prec.right(seq(
'select',
'<',
repeat(seq($.identifier, optional(','))),
'>',
$.parameter_list,
'from',
$.expression,
optional($.block),
@ -274,7 +284,7 @@ module.exports = grammar({
function: $ => seq(
'function',
optional(seq('<', repeat(seq($.identifier, optional(','))), '>')),
optional($.parameter_list),
$.block,
),
@ -285,12 +295,12 @@ module.exports = grammar({
_context_defined_function: $ => prec.right(seq(
$.identifier,
repeat(prec.right(seq($.expression, optional(',')))),
optional($._expression_list),
)),
built_in_function: $ => prec.right(seq(
$._built_in_function_name,
repeat(prec.right(seq($.expression, optional(',')))),
optional($._expression_list),
)),
_built_in_function_name: $ => choice(

View File

@ -53,6 +53,9 @@
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
@ -112,10 +115,24 @@
"name": "while"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
}
]
}
]
}
},
"expression": {
"type": "PREC_LEFT",
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
@ -177,6 +194,34 @@
]
}
},
"_expression_list": {
"type": "REPEAT1",
"content": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
}
},
"identifier": {
"type": "PATTERN",
"value": "[_a-zA-Z]+[_a-zA-Z0-9]?"
@ -559,24 +604,7 @@
]
}
},
"table": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "table"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<"
},
{
"_identifier_list": {
"type": "REPEAT1",
"content": {
"type": "SEQ",
@ -600,11 +628,49 @@
]
}
},
"parameter_list": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_identifier_list"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<"
},
{
"type": "SYMBOL",
"name": "_identifier_list"
},
{
"type": "STRING",
"value": ">"
}
]
}
]
}
},
"table": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "table"
},
{
"type": "SYMBOL",
"name": "parameter_list"
},
{
"type": "SYMBOL",
@ -752,7 +818,7 @@
]
},
"if_else": {
"type": "PREC_LEFT",
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
@ -784,9 +850,6 @@
}
},
"if": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
@ -802,12 +865,8 @@
"name": "block"
}
]
}
},
"else_if": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
@ -823,12 +882,8 @@
"name": "block"
}
]
}
},
"else": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
@ -840,7 +895,6 @@
"name": "block"
}
]
}
},
"match": {
"type": "PREC_RIGHT",
@ -1092,37 +1146,9 @@
"type": "STRING",
"value": "select"
},
{
"type": "STRING",
"value": "<"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
{
"type": "STRING",
"value": ">"
"name": "parameter_list"
},
{
"type": "STRING",
@ -1194,43 +1220,10 @@
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
{
"type": "STRING",
"value": ">"
}
]
"name": "parameter_list"
},
{
"type": "BLANK"
@ -1266,24 +1259,12 @@
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "REPEAT",
"content": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
"type": "SYMBOL",
"name": "_expression_list"
},
{
"type": "BLANK"
@ -1292,10 +1273,6 @@
}
]
}
}
}
]
}
},
"built_in_function": {
"type": "PREC_RIGHT",
@ -1307,24 +1284,12 @@
"type": "SYMBOL",
"name": "_built_in_function_name"
},
{
"type": "REPEAT",
"content": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
"type": "SYMBOL",
"name": "_expression_list"
},
{
"type": "BLANK"
@ -1333,10 +1298,6 @@
}
]
}
}
}
]
}
},
"_built_in_function_name": {
"type": "CHOICE",

View File

@ -251,7 +251,7 @@
"named": true
},
{
"type": "identifier",
"type": "parameter_list",
"named": true
}
]
@ -457,6 +457,21 @@
"named": true,
"fields": {}
},
{
"type": "parameter_list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "reduce",
"named": true,
@ -535,7 +550,7 @@
"named": true
},
{
"type": "identifier",
"type": "parameter_list",
"named": true
}
]
@ -621,7 +636,7 @@
"named": true
},
{
"type": "identifier",
"type": "parameter_list",
"named": true
}
]
@ -768,6 +783,10 @@
"type": ":",
"named": false
},
{
"type": ";",
"named": false
},
{
"type": "<",
"named": false

File diff suppressed because it is too large Load Diff