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

@ -65,6 +65,10 @@ select number from foobar where text == 'answer'
(item (item
(statement (statement
(open_statement (open_statement
(expression
(select
(identifier)
(identifier)
(expression (expression
(operation (operation
(expression (expression
@ -72,20 +76,8 @@ select number from foobar where text == 'answer'
(operator) (operator)
(expression (expression
(value (value
(table (string)))))))))))
(identifier)
(identifier)
(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]?/,
@ -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,9 +392,6 @@
] ]
}, },
"operator": { "operator": {
"type": "PREC",
"value": 2,
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -466,7 +467,6 @@
"value": "where" "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