diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-04-13 13:39:44 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-04-13 13:39:44 -0400 |
| commit | 63e6ba596ae8e35727289a69b11d5640bfc5e49e (patch) | |
| tree | 2a6e3022103f42898da7c02640e2dab817b36b88 | |
| parent | cc0763713495a2b5b154d318772fc7f745e96635 (diff) | |
Change table syntax to {key:value} instead of {key=>value}
| -rw-r--r-- | builtins/table.c | 4 | ||||
| -rw-r--r-- | parse.c | 8 | ||||
| -rw-r--r-- | test/enums.tm | 2 | ||||
| -rw-r--r-- | test/for.tm | 12 | ||||
| -rw-r--r-- | test/structs.tm | 8 | ||||
| -rw-r--r-- | test/tables.tm | 34 | ||||
| -rw-r--r-- | types.c | 2 |
7 files changed, 35 insertions, 35 deletions
diff --git a/builtins/table.c b/builtins/table.c index 956c0565..3a52d0c5 100644 --- a/builtins/table.c +++ b/builtins/table.c @@ -510,7 +510,7 @@ public CORD Table$as_text(const table_t *t, bool colorize, const TypeInfo *type) auto table = type->TableInfo; if (!t) - return CORD_all("{", generic_as_text(NULL, false, table.key), "=>", generic_as_text(NULL, false, table.value), "}"); + return CORD_all("{", generic_as_text(NULL, false, table.key), ":", generic_as_text(NULL, false, table.value), "}"); int64_t val_off = value_offset(type); CORD c = "{"; @@ -519,7 +519,7 @@ public CORD Table$as_text(const table_t *t, bool colorize, const TypeInfo *type) c = CORD_cat(c, ", "); void *entry = GET_ENTRY(*t, i); c = CORD_cat(c, generic_as_text(entry, colorize, table.key)); - c = CORD_cat(c, "=>"); + c = CORD_cat(c, ":"); c = CORD_cat(c, generic_as_text(entry + val_off, colorize, table.value)); } @@ -466,7 +466,7 @@ type_ast_t *parse_table_type(parse_ctx_t *ctx, const char *pos) { if (!key_type) return NULL; pos = key_type->end; whitespace(&pos); - if (!match(&pos, "=>")) return NULL; + if (!match(&pos, ":")) return NULL; type_ast_t *value_type = expect(ctx, start, &pos, parse_type, "I couldn't parse the rest of this table type"); whitespace(&pos); expect_closing(ctx, &pos, "}", "I wasn't able to parse the rest of this table type"); @@ -658,8 +658,8 @@ PARSER(parse_table) { whitespace(&pos); key_type = expect(ctx, pos-1, &pos, parse_type, "I couldn't parse a key type for this table"); whitespace(&pos); - if (!match(&pos, "=>")) - parser_err(ctx, pos, pos, "I expected an '=>' for this table type"); + if (!match(&pos, ":")) + parser_err(ctx, pos, pos, "I expected an ':' for this table type"); value_type = expect(ctx, pos-1, &pos, parse_type, "I couldn't parse a value type for this table"); whitespace(&pos); } @@ -669,7 +669,7 @@ PARSER(parse_table) { ast_t *key = optional(ctx, &pos, parse_extended_expr); if (!key) break; whitespace(&pos); - if (!match(&pos, "=>")) return NULL; + if (!match(&pos, ":")) return NULL; ast_t *value = expect(ctx, pos-1, &pos, parse_expr, "I couldn't parse the value for this table entry"); ast_t *entry = NewAST(ctx->file, entry_start, pos, TableEntry, .key=key, .value=value); ast_t *suffixed = parse_comprehension_suffix(ctx, entry); diff --git a/test/enums.tm b/test/enums.tm index f321af8c..c06862a3 100644 --- a/test/enums.tm +++ b/test/enums.tm @@ -21,7 +21,7 @@ func main() = yes >> x := Foo.One(123) - >> t := {x=>"found"; default="missing"} + >> t := {x:"found"; default="missing"} >> t[x] = "found" >> t[Foo.Zero] diff --git a/test/for.tm b/test/for.tm index 51940973..63656380 100644 --- a/test/for.tm +++ b/test/for.tm @@ -15,14 +15,14 @@ func labeled_nums(nums:[Int])->Text return "EMPTY" return result -func table_str(t:{Text=>Text})->Text +func table_str(t:{Text:Text})->Text str := "" for k,v in t - str ++= "{k}=>{v}," + str ++= "{k}:{v}," else return "EMPTY" return str -func table_key_str(t:{Text=>Text})->Text +func table_key_str(t:{Text:Text})->Text str := "" for k in t str ++= "{k}," @@ -40,10 +40,10 @@ func main() >> labeled_nums([:Int]) = "EMPTY" - >> t := {"key1"=>"value1", "key2"=>"value2"} + >> t := {"key1":"value1", "key2":"value2"} >> table_str(t) - = "key1=>value1,key2=>value2," - >> table_str({:Text=>Text}) + = "key1:value1,key2:value2," + >> table_str({:Text:Text}) = "EMPTY" >> table_key_str(t) diff --git a/test/structs.tm b/test/structs.tm index 1d9de8d0..9fe2f6a7 100644 --- a/test/structs.tm +++ b/test/structs.tm @@ -26,7 +26,7 @@ func test_metamethods() >> x < Pair(11, 20) = yes - >> t2 := {x=> "found"; default="missing"} + >> t2 := {x:"found"; default="missing"} >> t2[x] = "found" >> t2[y] @@ -43,7 +43,7 @@ func test_mixed() = no >> x < Mixed(11, "Hello") = yes - >> t := {x=> "found"; default="missing"} + >> t := {x:"found"; default="missing"} >> t[x] = "found" >> t[y] @@ -58,8 +58,8 @@ func main() >> my_pass := Password("Swordfish") = Password(...) - >> users_by_password := {my_pass=> "User1", Password("xxx")=>"User2"} - = {Password(...)=>"User1", Password(...)=>"User2"} + >> users_by_password := {my_pass:"User1", Password("xxx"):"User2"} + = {Password(...):"User1", Password(...):"User2"} >> users_by_password[my_pass] = "User1" diff --git a/test/tables.tm b/test/tables.tm index a55e4238..2ba42714 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -1,6 +1,6 @@ func main() - >> t := {"one"=>1, "two"=>2; default=999} - = {"one"=>1, "two"=>2; default=999} + >> t := {"one":1, "two":2; default=999} + = {"one":1, "two":2; default=999} >> t["one"] = 1 @@ -11,24 +11,24 @@ func main() t_str := "" for k,v in t - t_str ++= "({k}=>{v})" + t_str ++= "({k}:{v})" >> t_str - = "(one=>1)(two=>2)" + = "(one:1)(two:2)" >> #t = 2 >> t.default = ?%999 >> t.fallback - = !{Text=>Int} + = !{Text:Int} >> t.keys = ["one", "two"] >> t.values = [1, 2] - >> t2 := {"three"=>3; fallback=t} - = {"three"=>3; fallback={"one"=>1, "two"=>2; default=999}} + >> t2 := {"three":3; fallback=t} + = {"three":3; fallback={"one":1, "two":2; default=999}} >> t2["one"] = 1 @@ -42,17 +42,17 @@ func main() >> t2.default = !Int >> t2.fallback - = ?%{"one"=>1, "two"=>2; default=999} + = ?%{"one":1, "two":2; default=999} t2_str := "" for k,v in t2 - t2_str ++= "({k}=>{v})" + t2_str ++= "({k}:{v})" >> t2_str - = "(three=>3)" - - >> {i=>10*i for i in 5} - = {1=>10, 2=>20, 3=>30, 4=>40, 5=>50} - >> {i=>10*i for i in 5 if i mod 2 != 0} - = {1=>10, 3=>30, 5=>50} - >> {x=>10*x for x in y if x > 1 for y in [3, 4, 5] if y < 5} - = {2=>20, 3=>30, 4=>40} + = "(three:3)" + + >> {i:10*i for i in 5} + = {1:10, 2:20, 3:30, 4:40, 5:50} + >> {i:10*i for i in 5 if i mod 2 != 0} + = {1:10, 3:30, 5:50} + >> {x:10*x for x in y if x > 1 for y in [3, 4, 5] if y < 5} + = {2:20, 3:30, 4:40} @@ -25,7 +25,7 @@ CORD type_to_cord(type_t *t) { } case TableType: { auto table = Match(t, TableType); - return CORD_asprintf("{%r=>%r}", type_to_cord(table->key_type), type_to_cord(table->value_type)); + return CORD_asprintf("{%r:%r}", type_to_cord(table->key_type), type_to_cord(table->value_type)); } case ClosureType: { return type_to_cord(Match(t, ClosureType)->fn); |
