Implement insert expression

This commit is contained in:
Jeff 2023-09-30 16:17:09 -04:00
parent 77c15c5d54
commit 191970fabb
5 changed files with 6426 additions and 6120 deletions

View File

@ -92,20 +92,10 @@ insert ['bob was here', 0] into foobar
(statement (statement
(open_statement (open_statement
(expression (expression
(identifier))))) (insert
(item (list
(statement
(open_statement
(expression
(operation
(expression
(value (value
(list (string))
(value (value
(string)) (integer)))
(value (identifier)))))))
(integer)))))
(operator)
(expression
(identifier))))))))

View File

@ -18,7 +18,7 @@ module.exports = grammar({
$.yield_statement, $.yield_statement,
)), )),
open_statement: $ => prec.left($.expression), open_statement: $ => prec.right($.expression),
yield_statement: $ => seq($.open_statement, '->', $.open_statement), yield_statement: $ => seq($.open_statement, '->', $.open_statement),
@ -29,6 +29,7 @@ module.exports = grammar({
$.control_flow, $.control_flow,
$.tool, $.tool,
$.select, $.select,
$.insert,
), ),
identifier: $ => /[a-z|_|.]+[0-9]?/, identifier: $ => /[a-z|_|.]+[0-9]?/,
@ -101,11 +102,6 @@ module.exports = grammar({
'||', '||',
'and', 'and',
'or', 'or',
'insert',
'into',
'select',
'from',
'where',
), ),
operation: $ => prec.right(seq( operation: $ => prec.right(seq(
@ -124,6 +120,16 @@ module.exports = grammar({
), ),
)), )),
insert: $ => prec.right(seq(
'insert',
repeat1($.list),
'into',
$.identifier,
optional(
seq('where', $.expression)
),
)),
control_flow: $ => prec.right(seq( control_flow: $ => prec.right(seq(
'if', 'if',
$.expression, $.expression,

View File

@ -60,7 +60,7 @@
} }
}, },
"open_statement": { "open_statement": {
"type": "PREC_LEFT", "type": "PREC_RIGHT",
"value": 0, "value": 0,
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
@ -110,6 +110,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "select" "name": "select"
},
{
"type": "SYMBOL",
"name": "insert"
} }
] ]
}, },
@ -445,26 +449,6 @@
{ {
"type": "STRING", "type": "STRING",
"value": "or" "value": "or"
},
{
"type": "STRING",
"value": "insert"
},
{
"type": "STRING",
"value": "into"
},
{
"type": "STRING",
"value": "select"
},
{
"type": "STRING",
"value": "from"
},
{
"type": "STRING",
"value": "where"
} }
] ]
}, },
@ -535,6 +519,55 @@
] ]
} }
}, },
"insert": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "insert"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "list"
}
},
{
"type": "STRING",
"value": "into"
},
{
"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

@ -44,6 +44,10 @@
"type": "identifier", "type": "identifier",
"named": true "named": true
}, },
{
"type": "insert",
"named": true
},
{ {
"type": "operation", "type": "operation",
"named": true "named": true
@ -82,6 +86,29 @@
] ]
} }
}, },
{
"type": "insert",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "list",
"named": true
}
]
}
},
{ {
"type": "item", "type": "item",
"named": true, "named": true,

12404
src/parser.c

File diff suppressed because it is too large Load Diff