1
0

Change map syntax

This commit is contained in:
Jeff 2023-11-28 11:01:38 -05:00
parent 43d46cb289
commit c412836487
10 changed files with 10274 additions and 9780 deletions

View File

@ -1,4 +1,4 @@
all_cards <map> = { all_cards = {
rooms = ['Library' 'Kitchen' 'Conservatory'] rooms = ['Library' 'Kitchen' 'Conservatory']
suspects = ['White' 'Green' 'Scarlett'] suspects = ['White' 'Green' 'Scarlett']
weapons = ['Rope' 'Lead_Pipe' 'Knife'] weapons = ['Rope' 'Lead_Pipe' 'Knife']
@ -38,7 +38,7 @@ make_guess = |current_room <str>, cards <map>| {
+ current_room + current_room
+ ' with the ' + ' with the '
+ (random cards:weapons) + (random cards:weapons)
+ '!') + '.')
} }
} }

View File

@ -3,10 +3,10 @@ data = (from_json (read 'examples/assets/jq_data.json'))
new_data = []; new_data = [];
for commit_data in data { for commit_data in data {
new_data += ( new_data += {
message = commit_data.commit.message message = commit_data.commit.message
name = commit_data.commit.committer.name name = commit_data.commit.committer.name
) }
} }
new_data new_data

View File

@ -1,7 +1,7 @@
dictionary = ( dictionary = {
dust = "awesome" dust = "awesome"
answer = 42 answer = 42
) }
(output (output
'Dust is ' 'Dust is '

View File

@ -89,7 +89,7 @@ mod tests {
#[test] #[test]
fn evaluate_map_index() { fn evaluate_map_index() {
let test = evaluate("x = (y = (z = 2)) x:y:z").unwrap(); let test = evaluate("x = {y = {z = 2}} x:y:z").unwrap();
assert_eq!(Value::Integer(2), test); assert_eq!(Value::Integer(2), test);
} }

View File

@ -166,7 +166,7 @@ mod tests {
variables.insert("foo".to_string(), Value::String("bar".to_string())); variables.insert("foo".to_string(), Value::String("bar".to_string()));
} }
assert_eq!(evaluate("( x = 1, foo = 'bar' )"), Ok(Value::Map(map))); assert_eq!(evaluate("{ x = 1, foo = 'bar' }"), Ok(Value::Map(map)));
} }
#[test] #[test]

View File

@ -103,10 +103,10 @@ Complex Function Call
(foobar (foobar
"hi" "hi"
42 42
( {
x = 1 x = 1
y = 2 y = 2
) }
) )
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -2,7 +2,7 @@
Simple Map Simple Map
================================================================================ ================================================================================
( answer = 42 ) { answer = 42 }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -21,15 +21,15 @@ Simple Map
Nested Maps Nested Maps
================================================================================ ================================================================================
x = ( x = {
y = ( y = {
foo = 'bar' foo = 'bar'
z = ( z = {
message = 'hiya' message = 'hiya'
) }
) }
f = 12 f = 12
) }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -5,10 +5,6 @@ module.exports = grammar({
extras: $ => [ /\s/, $._comment ], extras: $ => [ /\s/, $._comment ],
conflicts: $ => [
[$.map, $.assignment_operator],
],
rules: { rules: {
root: $ => prec(1, repeat1($.statement)), root: $ => prec(1, repeat1($.statement)),
@ -100,14 +96,14 @@ module.exports = grammar({
), ),
map: $ => seq( map: $ => seq(
'(', '{',
repeat(seq( repeat(seq(
$.identifier, $.identifier,
"=", "=",
$.statement, $.statement,
optional(',') optional(',')
)), )),
')', '}',
), ),
index: $ => prec.left(1, seq( index: $ => prec.left(1, seq(
@ -164,11 +160,11 @@ module.exports = grammar({
$.statement, $.statement,
), ),
assignment_operator: $ => choice( assignment_operator: $ => prec.right(choice(
"=", "=",
"+=", "+=",
"-=", "-=",
), )),
if_else: $ => prec.right(seq( if_else: $ => prec.right(seq(
$.if, $.if,

View File

@ -518,7 +518,7 @@
"members": [ "members": [
{ {
"type": "STRING", "type": "STRING",
"value": "(" "value": "{"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -554,7 +554,7 @@
}, },
{ {
"type": "STRING", "type": "STRING",
"value": ")" "value": "}"
} }
] ]
}, },
@ -767,21 +767,25 @@
] ]
}, },
"assignment_operator": { "assignment_operator": {
"type": "CHOICE", "type": "PREC_RIGHT",
"members": [ "value": 0,
{ "content": {
"type": "STRING", "type": "CHOICE",
"value": "=" "members": [
}, {
{ "type": "STRING",
"type": "STRING", "value": "="
"value": "+=" },
}, {
{ "type": "STRING",
"type": "STRING", "value": "+="
"value": "-=" },
} {
] "type": "STRING",
"value": "-="
}
]
}
}, },
"if_else": { "if_else": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
@ -1474,12 +1478,7 @@
"name": "_comment" "name": "_comment"
} }
], ],
"conflicts": [ "conflicts": [],
[
"map",
"assignment_operator"
]
],
"precedences": [], "precedences": [],
"externals": [], "externals": [],
"inline": [], "inline": [],

File diff suppressed because it is too large Load Diff