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']
suspects = ['White' 'Green' 'Scarlett']
weapons = ['Rope' 'Lead_Pipe' 'Knife']
@ -38,7 +38,7 @@ make_guess = |current_room <str>, cards <map>| {
+ current_room
+ ' with the '
+ (random cards:weapons)
+ '!')
+ '.')
}
}

View File

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

View File

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

View File

@ -89,7 +89,7 @@ mod tests {
#[test]
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);
}

View File

@ -166,7 +166,7 @@ mod tests {
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]

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff