Implement map syntax

This commit is contained in:
Jeff 2023-09-29 15:25:10 -04:00
parent 0fa436832d
commit 5a6c92372a
5 changed files with 1041 additions and 776 deletions

79
corpus/maps.txt Normal file
View File

@ -0,0 +1,79 @@
==================
Simple Maps
==================
map {
answer = 42
}
---
(root
(item
(statement
(open_statement
(expression
(value
(map
(identifier)
(value
(integer)))))))))
==================
Map Assignment
==================
x = map {
answer = 42
}
---
(root
(item
(statement
(open_statement
(expression
(operation
(expression
(identifier))
(operator)
(expression
(value
(map
(identifier)
(value
(integer)))))))))))
==================
Map Access
==================
x = map {
answer = 42
}
x.answer
---
(root
(item
(statement
(open_statement
(expression
(operation
(expression
(identifier))
(operator)
(expression
(value
(map
(identifier)
(value
(integer))))))))))
(item
(statement
(open_statement
(expression
(identifier))))))

View File

@ -38,6 +38,7 @@ module.exports = grammar({
$.boolean,
$.function,
$.table,
$.map,
),
float: $ => /\d+\.\d*/,
@ -63,15 +64,22 @@ module.exports = grammar({
'function',
optional(seq('<', repeat(seq($.identifier, optional(','))), '>')),
'{',
repeat($.statement),
repeat1($.statement),
'}',
),
table: $ => seq(
'table',
seq('<', repeat(seq($.identifier, optional(','))), '>'),
seq('<', repeat1(seq($.identifier, optional(','))), '>'),
'{',
optional(repeat($.list)),
repeat($.list),
'}',
),
map: $ => seq(
'map',
'{',
repeat(seq($.identifier, "=", $.value)),
'}',
),

View File

@ -127,6 +127,10 @@
{
"type": "SYMBOL",
"name": "table"
},
{
"type": "SYMBOL",
"name": "map"
}
]
},
@ -253,7 +257,7 @@
"value": "{"
},
{
"type": "REPEAT",
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "statement"
@ -280,7 +284,7 @@
"value": "<"
},
{
"type": "REPEAT",
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
@ -314,19 +318,48 @@
"value": "{"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "list"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"map": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "map"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "list"
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "value"
}
},
{
"type": "BLANK"
}
]
]
}
},
{
"type": "STRING",

View File

@ -65,7 +65,7 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "identifier",
@ -112,6 +112,25 @@
]
}
},
{
"type": "map",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "value",
"named": true
}
]
}
},
{
"type": "open_statement",
"named": true,
@ -187,7 +206,7 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "identifier",
@ -237,6 +256,10 @@
"type": "list",
"named": true
},
{
"type": "map",
"named": true
},
{
"type": "string",
"named": true
@ -320,6 +343,10 @@
"type": "integer",
"named": true
},
{
"type": "map",
"named": false
},
{
"type": "output",
"named": false

File diff suppressed because it is too large Load Diff