Expand grammar

This commit is contained in:
Jeff 2023-09-30 15:47:21 -04:00
parent 89e89f3433
commit d58c08125f
7 changed files with 6372 additions and 1627 deletions

View File

@ -47,11 +47,11 @@ foobar = ['answer', 42]
List Access List Access
================== ==================
foobar = ['answer', 42] x = foobar.0
the_answer = foobar.1
--- ---
(root (root
(item (item
(statement (statement
@ -62,29 +62,7 @@ the_answer = foobar.1
(identifier)) (identifier))
(operator) (operator)
(expression (expression
(value (identifier)))))))
(list
(value
(string))
(value
(integer))))))))))
(item
(statement
(open_statement
(expression
(identifier)))))
(item
(statement
(open_statement
(expression
(operation
(expression
(value
(integer)))
(operator)
(expression
(value
(integer)))))))))
================== ==================
List Mutation List Mutation

View File

@ -72,17 +72,17 @@ x = 1 + 1
(item (item
(statement (statement
(open_statement (open_statement
(expression
(operation
(expression (expression
(operation (operation
(expression (expression
(identifier)) (identifier))
(operator) (operator)
(expression
(operation
(expression (expression
(value (value
(integer))))) (integer)))
(operator) (operator)
(expression (expression
(value (value
(integer))))))))) (integer)))))))))))

View File

@ -31,8 +31,6 @@ foobar = table <text, number> {
['answer', 42] ['answer', 42]
} }
foobar
--- ---
(root (root
@ -53,21 +51,12 @@ foobar
(value (value
(string)) (string))
(value (value
(integer))))))))))) (integer))))))))))))
(item
(statement
(open_statement
(expression
(identifier))))))
================== ==================
Table Access Table Access
================== ==================
foobar = table <text, number> {
['answer', 42]
}
select number from foobar where text == 'answer' select number from foobar where text == 'answer'
--- ---
@ -102,10 +91,6 @@ select number from foobar where text == 'answer'
Table Insert Table Insert
================== ==================
foobar = table <text, number> {
['answer', 42]
}
insert ['bob was here', 0] into foobar insert ['bob was here', 0] into foobar
--- ---
@ -115,23 +100,20 @@ insert ['bob was here', 0] into foobar
(statement (statement
(open_statement (open_statement
(expression (expression
(operation (identifier)))))
(expression
(identifier))
(operator)
(expression
(value
(table
(identifier)
(identifier)
(list
(value
(string))
(value
(integer)))))))))))
(item (item
(statement (statement
(open_statement (open_statement
(expression
(operation
(expression (expression
(value (value
(42))))))) (list
(value
(string))
(value
(integer)))))
(operator)
(expression
(identifier))))))))

View File

@ -13,11 +13,14 @@ module.exports = grammar({
comment: $ => prec.left(seq(token('#'), /.*/)), comment: $ => prec.left(seq(token('#'), /.*/)),
statement: $ => choice( statement: $ => prec.right(choice(
$.open_statement, $.open_statement,
), $.yield_statement,
)),
open_statement: $ => prec.left(seq($.expression)), open_statement: $ => prec.left($.expression),
yield_statement: $ => seq($.open_statement, '->', $.open_statement),
expression: $ => choice( expression: $ => choice(
$.value, $.value,
@ -83,14 +86,28 @@ module.exports = grammar({
'}', '}',
), ),
operator: $ => choice( operator: $ => prec(2, choice(
'=',
'+', '+',
'-', '-',
'=', '*',
'/',
'%',
'==', '==',
), '+=',
'-=',
'&&',
'||',
'and',
'or',
'insert',
'into',
'select',
'from',
'where',
)),
operation: $ => prec.left(seq( operation: $ => prec.right(seq(
$.expression, $.expression,
$.operator, $.operator,
$.expression, $.expression,

View File

@ -43,26 +43,46 @@
} }
}, },
"statement": { "statement": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "open_statement" "name": "open_statement"
},
{
"type": "SYMBOL",
"name": "yield_statement"
} }
] ]
}
}, },
"open_statement": { "open_statement": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 0, "value": 0,
"content": { "content": {
"type": "SYMBOL",
"name": "expression"
}
},
"yield_statement": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "expression" "name": "open_statement"
},
{
"type": "STRING",
"value": "->"
},
{
"type": "SYMBOL",
"name": "open_statement"
} }
] ]
}
}, },
"expression": { "expression": {
"type": "CHOICE", "type": "CHOICE",
@ -368,8 +388,15 @@
] ]
}, },
"operator": { "operator": {
"type": "PREC",
"value": 2,
"content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "STRING",
"value": "="
},
{ {
"type": "STRING", "type": "STRING",
"value": "+" "value": "+"
@ -380,16 +407,69 @@
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "=" "value": "*"
},
{
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "%"
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "==" "value": "=="
},
{
"type": "STRING",
"value": "+="
},
{
"type": "STRING",
"value": "-="
},
{
"type": "STRING",
"value": "&&"
},
{
"type": "STRING",
"value": "||"
},
{
"type": "STRING",
"value": "and"
},
{
"type": "STRING",
"value": "or"
},
{
"type": "STRING",
"value": "insert"
},
{
"type": "STRING",
"value": "into"
},
{
"type": "STRING",
"value": "select"
},
{
"type": "STRING",
"value": "from"
},
{
"type": "STRING",
"value": "where"
} }
] ]
}
}, },
"operation": { "operation": {
"type": "PREC_LEFT", "type": "PREC_RIGHT",
"value": 0, "value": 0,
"content": { "content": {
"type": "SEQ", "type": "SEQ",

View File

@ -196,6 +196,10 @@
{ {
"type": "open_statement", "type": "open_statement",
"named": true "named": true
},
{
"type": "yield_statement",
"named": true
} }
] ]
} }
@ -271,14 +275,45 @@
] ]
} }
}, },
{
"type": "yield_statement",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "open_statement",
"named": true
}
]
}
},
{ {
"type": "#", "type": "#",
"named": false "named": false
}, },
{
"type": "%",
"named": false
},
{
"type": "&&",
"named": false
},
{
"type": "*",
"named": false
},
{ {
"type": "+", "type": "+",
"named": false "named": false
}, },
{
"type": "+=",
"named": false
},
{ {
"type": ",", "type": ",",
"named": false "named": false
@ -287,6 +322,18 @@
"type": "-", "type": "-",
"named": false "named": false
}, },
{
"type": "-=",
"named": false
},
{
"type": "->",
"named": false
},
{
"type": "/",
"named": false
},
{ {
"type": "<", "type": "<",
"named": false "named": false
@ -311,6 +358,10 @@
"type": "]", "type": "]",
"named": false "named": false
}, },
{
"type": "and",
"named": false
},
{ {
"type": "else", "type": "else",
"named": false "named": false
@ -327,6 +378,10 @@
"type": "float", "type": "float",
"named": true "named": true
}, },
{
"type": "from",
"named": false
},
{ {
"type": "function", "type": "function",
"named": false "named": false
@ -339,18 +394,34 @@
"type": "if", "type": "if",
"named": false "named": false
}, },
{
"type": "insert",
"named": false
},
{ {
"type": "integer", "type": "integer",
"named": true "named": true
}, },
{
"type": "into",
"named": false
},
{ {
"type": "map", "type": "map",
"named": false "named": false
}, },
{
"type": "or",
"named": false
},
{ {
"type": "output", "type": "output",
"named": false "named": false
}, },
{
"type": "select",
"named": false
},
{ {
"type": "string", "type": "string",
"named": true "named": true
@ -367,10 +438,18 @@
"type": "true", "type": "true",
"named": false "named": false
}, },
{
"type": "where",
"named": false
},
{ {
"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