Skip to content

Commit

Permalink
use the correct string escape
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan-wanna-M committed Sep 28, 2024
1 parent 249398f commit 9f4b2c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/formatron/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def builtin_literal(current: typing.Type, nonterminal: str):
result = []
for i, arg in enumerate(args):
if isinstance(arg, str):
arg = arg.replace('"', '\\"')
new_items.append(f'"\\\"{arg}\\\""')
new_items.append(f'"\\\"{repr(arg)[1:-1]}\\\""')
elif isinstance(arg, bool):
new_items.append(f'"{str(arg).lower()}"')
elif isinstance(arg, int):
Expand Down
6 changes: 3 additions & 3 deletions tests/snapshots/snap_test_grammar_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
start_concepts_value ::= string;
start_related_queries ::= array_begin (start_related_queries_value (comma start_related_queries_value)*)? array_end;
start_related_queries_value ::= start_related_queries_value_0 | start_related_queries_value_1;
start_related_queries_value_1 ::= string;
start_related_queries_value_0 ::= object_begin \'"foo"\' colon start_related_queries_value_0_foo object_end;
start_related_queries_value_0_foo ::= integer;
start_related_queries_value_1 ::= object_begin \'"foo"\' colon start_related_queries_value_1_foo object_end;
start_related_queries_value_1_foo ::= integer;
start_related_queries_value_0 ::= string;
start_queries ::= array_begin (start_queries_value (comma start_queries_value)*)? array_end;
start_queries_value ::= start_queries_value_0 | start_queries_value_1 | start_queries_value_2;
start_queries_value_2 ::= integer;
Expand Down

0 comments on commit 9f4b2c8

Please sign in to comment.