1
0

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 (expression
(value (value
(function (function
(parameter_list
(identifier) (identifier)
(identifier) (identifier))
(block (block
(statement (statement
(expression (expression

View File

@ -24,7 +24,7 @@ if true { "True" }
Complex If 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 Nested If
================== ==================
if true { if true
if 42 == 12 { if 42 == 12
'hiya' 'hiya'
} else { else
'bye' 'bye'
}
}
--- ---

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff