Implement select expression

This commit is contained in:
Jeff 2023-09-30 16:06:01 -04:00
parent cbe92941a1
commit 77c15c5d54
6 changed files with 5206 additions and 4552 deletions

View File

@ -51,7 +51,6 @@ x = foobar.0
--- ---
(root (root
(item (item
(statement (statement

View File

@ -66,26 +66,18 @@ select number from foobar where text == 'answer'
(statement (statement
(open_statement (open_statement
(expression (expression
(operation (select
(identifier)
(identifier)
(expression (expression
(identifier)) (operation
(operator) (expression
(expression (identifier))
(value (operator)
(table (expression
(identifier) (value
(identifier) (string)))))))))))
(list
(value
(string))
(value
(integer)))))))))))
(item
(statement
(open_statement
(expression
(value
(42)))))))
================== ==================
Table Insert Table Insert

View File

@ -28,6 +28,7 @@ module.exports = grammar({
$.operation, $.operation,
$.control_flow, $.control_flow,
$.tool, $.tool,
$.select,
), ),
identifier: $ => /[a-z|_|.]+[0-9]?/, identifier: $ => /[a-z|_|.]+[0-9]?/,
@ -42,7 +43,7 @@ module.exports = grammar({
$.function, $.function,
$.table, $.table,
$.map, $.map,
), ),
float: $ => /\d+\.\d*/, float: $ => /\d+\.\d*/,
@ -86,7 +87,7 @@ module.exports = grammar({
'}', '}',
), ),
operator: $ => prec(2, choice( operator: $ => choice(
'=', '=',
'+', '+',
'-', '-',
@ -105,7 +106,7 @@ module.exports = grammar({
'select', 'select',
'from', 'from',
'where', 'where',
)), ),
operation: $ => prec.right(seq( operation: $ => prec.right(seq(
$.expression, $.expression,
@ -113,6 +114,16 @@ module.exports = grammar({
$.expression, $.expression,
)), )),
select: $ => prec.right(seq(
'select',
$.identifier,
'from',
$.identifier,
optional(
seq('where', $.expression)
),
)),
control_flow: $ => prec.right(seq( control_flow: $ => prec.right(seq(
'if', 'if',
$.expression, $.expression,

View File

@ -106,6 +106,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "tool" "name": "tool"
},
{
"type": "SYMBOL",
"name": "select"
} }
] ]
}, },
@ -388,85 +392,81 @@
] ]
}, },
"operator": { "operator": {
"type": "PREC", "type": "CHOICE",
"value": 2, "members": [
"content": { {
"type": "CHOICE", "type": "STRING",
"members": [ "value": "="
{ },
"type": "STRING", {
"value": "=" "type": "STRING",
}, "value": "+"
{ },
"type": "STRING", {
"value": "+" "type": "STRING",
}, "value": "-"
{ },
"type": "STRING", {
"value": "-" "type": "STRING",
}, "value": "*"
{ },
"type": "STRING", {
"value": "*" "type": "STRING",
}, "value": "/"
{ },
"type": "STRING", {
"value": "/" "type": "STRING",
}, "value": "%"
{ },
"type": "STRING", {
"value": "%" "type": "STRING",
}, "value": "=="
{ },
"type": "STRING", {
"value": "==" "type": "STRING",
}, "value": "+="
{ },
"type": "STRING", {
"value": "+=" "type": "STRING",
}, "value": "-="
{ },
"type": "STRING", {
"value": "-=" "type": "STRING",
}, "value": "&&"
{ },
"type": "STRING", {
"value": "&&" "type": "STRING",
}, "value": "||"
{ },
"type": "STRING", {
"value": "||" "type": "STRING",
}, "value": "and"
{ },
"type": "STRING", {
"value": "and" "type": "STRING",
}, "value": "or"
{ },
"type": "STRING", {
"value": "or" "type": "STRING",
}, "value": "insert"
{ },
"type": "STRING", {
"value": "insert" "type": "STRING",
}, "value": "into"
{ },
"type": "STRING", {
"value": "into" "type": "STRING",
}, "value": "select"
{ },
"type": "STRING", {
"value": "select" "type": "STRING",
}, "value": "from"
{ },
"type": "STRING", {
"value": "from" "type": "STRING",
}, "value": "where"
{ }
"type": "STRING", ]
"value": "where"
}
]
}
}, },
"operation": { "operation": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
@ -489,6 +489,52 @@
] ]
} }
}, },
"select": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"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",
"name": "expression"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
},
"control_flow": { "control_flow": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
"value": 0, "value": 0,

View File

@ -48,6 +48,10 @@
"type": "operation", "type": "operation",
"named": true "named": true
}, },
{
"type": "select",
"named": true
},
{ {
"type": "tool", "type": "tool",
"named": true "named": true
@ -185,6 +189,25 @@
] ]
} }
}, },
{
"type": "select",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
{ {
"type": "statement", "type": "statement",
"named": true, "named": true,

File diff suppressed because it is too large Load Diff