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, $.boolean,
$.function, $.function,
$.table, $.table,
$.map,
), ),
float: $ => /\d+\.\d*/, float: $ => /\d+\.\d*/,
@ -63,15 +64,22 @@ module.exports = grammar({
'function', 'function',
optional(seq('<', repeat(seq($.identifier, optional(','))), '>')), optional(seq('<', repeat(seq($.identifier, optional(','))), '>')),
'{', '{',
repeat($.statement), repeat1($.statement),
'}', '}',
), ),
table: $ => seq( table: $ => seq(
'table', '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", "type": "SYMBOL",
"name": "table" "name": "table"
},
{
"type": "SYMBOL",
"name": "map"
} }
] ]
}, },
@ -253,7 +257,7 @@
"value": "{" "value": "{"
}, },
{ {
"type": "REPEAT", "type": "REPEAT1",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "statement" "name": "statement"
@ -280,7 +284,7 @@
"value": "<" "value": "<"
}, },
{ {
"type": "REPEAT", "type": "REPEAT1",
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -314,19 +318,48 @@
"value": "{" "value": "{"
}, },
{ {
"type": "CHOICE", "type": "REPEAT",
"members": [ "content": {
{ "type": "SYMBOL",
"type": "REPEAT", "name": "list"
"content": { }
},
{
"type": "STRING",
"value": "}"
}
]
},
"map": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "map"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL", "type": "SYMBOL",
"name": "list" "name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "value"
} }
}, ]
{ }
"type": "BLANK"
}
]
}, },
{ {
"type": "STRING", "type": "STRING",

View File

@ -65,7 +65,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "identifier", "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", "type": "open_statement",
"named": true, "named": true,
@ -187,7 +206,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": false, "required": true,
"types": [ "types": [
{ {
"type": "identifier", "type": "identifier",
@ -237,6 +256,10 @@
"type": "list", "type": "list",
"named": true "named": true
}, },
{
"type": "map",
"named": true
},
{ {
"type": "string", "type": "string",
"named": true "named": true
@ -320,6 +343,10 @@
"type": "integer", "type": "integer",
"named": true "named": true
}, },
{
"type": "map",
"named": false
},
{ {
"type": "output", "type": "output",
"named": false "named": false

File diff suppressed because it is too large Load Diff