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
(identifier)
(identifier)
(parameter_list
(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,22 +2,23 @@
Table Declaration
==================
table <messages, numbers> [
['hiya', 42]
['foo', 57]
['bar', 99.99]
table messages numbers [
['hiya' 42]
['foo' 57]
['bar' 99.99]
]
---
(root
(block
(statement
(statement
(expression
(value
(table
(identifier)
(identifier)
(parameter_list
(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,24 +19,27 @@ module.exports = grammar({
seq('{', repeat1($.statement), '}'),
)),
statement: $ => prec.right(choice(
$.assignment,
$.async,
$.expression,
$.filter,
$.find,
$.for,
$.if_else,
$.insert,
$.match,
$.reduce,
$.remove,
$.select,
$.transform,
$.while,
statement: $ => prec.right(seq(
choice(
$.assignment,
$.async,
$.expression,
$.filter,
$.find,
$.for,
$.if_else,
$.insert,
$.match,
$.reduce,
$.remove,
$.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,69 +53,86 @@
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "assignment"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "assignment"
},
{
"type": "SYMBOL",
"name": "async"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "filter"
},
{
"type": "SYMBOL",
"name": "find"
},
{
"type": "SYMBOL",
"name": "for"
},
{
"type": "SYMBOL",
"name": "if_else"
},
{
"type": "SYMBOL",
"name": "insert"
},
{
"type": "SYMBOL",
"name": "match"
},
{
"type": "SYMBOL",
"name": "reduce"
},
{
"type": "SYMBOL",
"name": "remove"
},
{
"type": "SYMBOL",
"name": "select"
},
{
"type": "SYMBOL",
"name": "transform"
},
{
"type": "SYMBOL",
"name": "while"
}
]
},
{
"type": "SYMBOL",
"name": "async"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "filter"
},
{
"type": "SYMBOL",
"name": "find"
},
{
"type": "SYMBOL",
"name": "for"
},
{
"type": "SYMBOL",
"name": "if_else"
},
{
"type": "SYMBOL",
"name": "insert"
},
{
"type": "SYMBOL",
"name": "match"
},
{
"type": "SYMBOL",
"name": "reduce"
},
{
"type": "SYMBOL",
"name": "remove"
},
{
"type": "SYMBOL",
"name": "select"
},
{
"type": "SYMBOL",
"name": "transform"
},
{
"type": "SYMBOL",
"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,15 +604,39 @@
]
}
},
"table": {
"type": "PREC_LEFT",
"value": 0,
"_identifier_list": {
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "table"
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
},
"parameter_list": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_identifier_list"
},
{
"type": "SEQ",
@ -577,34 +646,31 @@
"value": "<"
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
}
"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,63 +850,51 @@
}
},
"if": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "if"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "block"
}
]
}
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "if"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
"else_if": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "else if"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "block"
}
]
}
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "else if"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
"else": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "else"
},
{
"type": "SYMBOL",
"name": "block"
}
]
}
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "else"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
"match": {
"type": "PREC_RIGHT",
@ -1093,36 +1147,8 @@
"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": ">"
"type": "SYMBOL",
"name": "parameter_list"
},
{
"type": "STRING",
@ -1196,41 +1222,8 @@
"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": ">"
}
]
"type": "SYMBOL",
"name": "parameter_list"
},
{
"type": "BLANK"
@ -1267,32 +1260,16 @@
"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": "BLANK"
}
]
}
]
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression_list"
},
{
"type": "BLANK"
}
}
]
}
]
}
@ -1308,32 +1285,16 @@
"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": "BLANK"
}
]
}
]
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression_list"
},
{
"type": "BLANK"
}
}
]
}
]
}

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