From 43d1040d76220e39e7f15e1be1a20c8882a03965 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 18 Jul 2020 15:37:49 -0600 Subject: [PATCH] And fix \" escapes --- src/python/flowmetal/parser.py | 6 ++++-- test/python/flowmetal/test_parser.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/python/flowmetal/parser.py b/src/python/flowmetal/parser.py index 291d008..6c06661 100644 --- a/src/python/flowmetal/parser.py +++ b/src/python/flowmetal/parser.py @@ -369,8 +369,8 @@ class Parser(SexpParser): return "\014" # form feed elif ch == 't': return "\t" - elif ch == '""': - return '""' + elif ch == '"': + return '"' @classmethod def parse_str(cls, f: PosTrackingBufferedReader): @@ -382,10 +382,12 @@ class Parser(SexpParser): while True: if not rtb.peek(): raise + # Handle end of string elif rtb.peek() == '"': rtb.read() break + # Handle escape sequences elif rtb.peek() == '\\': rtb.read() # Discard the escape leader diff --git a/test/python/flowmetal/test_parser.py b/test/python/flowmetal/test_parser.py index 5de274f..e4ffd29 100644 --- a/test/python/flowmetal/test_parser.py +++ b/test/python/flowmetal/test_parser.py @@ -135,6 +135,7 @@ def test_ambiguous_floats(txt, tokenization): @pytest.mark.parametrize('txt,', [ + r'""', r'"foo"', r'"foo bar baz qux"', r'"foo\nbar\tbaz\lqux"', @@ -142,8 +143,8 @@ def test_ambiguous_floats(txt, tokenization): bar baz qux"''', - r'""', r'"\000 \x00"', + r'"\"\""', ]) def test_string(txt): """Some examples of strings, and of escape sequences."""