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
==================
foobar = ['answer', 42]
the_answer = foobar.1
x = foobar.0
---
(root
(item
(statement
@ -62,29 +62,7 @@ the_answer = foobar.1
(identifier))
(operator)
(expression
(value
(list
(value
(string))
(value
(integer))))))))))
(item
(statement
(open_statement
(expression
(identifier)))))
(item
(statement
(open_statement
(expression
(operation
(expression
(value
(integer)))
(operator)
(expression
(value
(integer)))))))))
(identifier)))))))
==================
List Mutation

View File

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

View File

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

View File

@ -13,11 +13,14 @@ module.exports = grammar({
comment: $ => prec.left(seq(token('#'), /.*/)),
statement: $ => choice(
statement: $ => prec.right(choice(
$.open_statement,
),
$.yield_statement,
)),
open_statement: $ => prec.left(seq($.expression)),
open_statement: $ => prec.left($.expression),
yield_statement: $ => seq($.open_statement, '->', $.open_statement),
expression: $ => choice(
$.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,
$.operator,
$.expression,

View File

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

View File

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

File diff suppressed because it is too large Load Diff