1
0

Allow empty maps; Write tests

This commit is contained in:
Jeff 2024-01-29 17:36:21 -05:00
parent bd6ca6a6c1
commit df5cf93e58
5 changed files with 21112 additions and 20638 deletions

View File

@ -45,6 +45,11 @@ fn list() {
); );
} }
#[test]
fn empty_list() {
assert_eq!(interpret("[]"), Ok(Value::List(List::new())));
}
#[test] #[test]
fn map() { fn map() {
let map = Map::new(); let map = Map::new();
@ -56,6 +61,11 @@ fn map() {
assert_eq!(interpret("{ x = 1, foo = 'bar' }"), Ok(Value::Map(map))); assert_eq!(interpret("{ x = 1, foo = 'bar' }"), Ok(Value::Map(map)));
} }
#[test]
fn empty_map() {
assert_eq!(interpret("{}"), Ok(Value::Map(Map::new())));
}
#[test] #[test]
fn map_types() { fn map_types() {
let map = Map::new(); let map = Map::new();
@ -119,7 +129,5 @@ fn option() {
#[test] #[test]
fn range() { fn range() {
let result = interpret("0..100"); assert_eq!(interpret("0..100"), Ok(Value::range(0, 100)));
assert_eq!(Ok(Value::range(0, 100)), result);
} }

View File

@ -263,20 +263,23 @@ module.exports = grammar({
), ),
map: $ => map: $ =>
seq( prec(
'{', 1,
repeat1( seq(
seq( '{',
$.identifier, repeat(
optional( seq(
$.type_specification, $.identifier,
optional(
$.type_specification,
),
'=',
$.statement,
optional(','),
), ),
'=',
$.statement,
optional(','),
), ),
'}',
), ),
'}',
), ),
option: $ => option: $ =>

View File

@ -769,61 +769,65 @@
] ]
}, },
"map": { "map": {
"type": "SEQ", "type": "PREC",
"members": [ "value": 1,
{ "content": {
"type": "STRING", "type": "SEQ",
"value": "{" "members": [
}, {
{ "type": "STRING",
"type": "REPEAT1", "value": "{"
"content": { },
"type": "SEQ", {
"members": [ "type": "REPEAT",
{ "content": {
"type": "SYMBOL", "type": "SEQ",
"name": "identifier" "members": [
}, {
{ "type": "SYMBOL",
"type": "CHOICE", "name": "identifier"
"members": [ },
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "type_specification" "members": [
}, {
{ "type": "SYMBOL",
"type": "BLANK" "name": "type_specification"
} },
] {
}, "type": "BLANK"
{ }
"type": "STRING", ]
"value": "=" },
}, {
{ "type": "STRING",
"type": "SYMBOL", "value": "="
"name": "statement" },
}, {
{ "type": "SYMBOL",
"type": "CHOICE", "name": "statement"
"members": [ },
{ {
"type": "STRING", "type": "CHOICE",
"value": "," "members": [
}, {
{ "type": "STRING",
"type": "BLANK" "value": ","
} },
] {
} "type": "BLANK"
] }
]
}
]
}
},
{
"type": "STRING",
"value": "}"
} }
}, ]
{ }
"type": "STRING",
"value": "}"
}
]
}, },
"option": { "option": {
"type": "CHOICE", "type": "CHOICE",

View File

@ -413,7 +413,7 @@
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
"required": true, "required": false,
"types": [ "types": [
{ {
"type": "identifier", "type": "identifier",

File diff suppressed because it is too large Load Diff