diff --git a/pyquil/_parser/grammar.lark b/pyquil/_parser/grammar.lark index 4993172c3..5f0b93a62 100644 --- a/pyquil/_parser/grammar.lark +++ b/pyquil/_parser/grammar.lark @@ -60,7 +60,7 @@ def_circuit : "DEFCIRCUIT" name [ variables ] [ qubit_designators ] ":" indented // | "DEFCIRCUIT" name [ variables ] qubit_designators ":" indented_instrs -> def_circuit_qubits def_frame : "DEFFRAME" frame ( ":" frame_spec+ )? -frame_spec : _NEWLINE_TAB frame_attr ":" (expression | "\"" name "\"" ) +frame_spec : _NEWLINE_TAB frame_attr ":" (expression | string ) !frame_attr : "SAMPLE-RATE" | "INITIAL-FREQUENCY" | "DIRECTION" diff --git a/pyquil/_parser/parser.py b/pyquil/_parser/parser.py index b8984ea4b..0b345fdc7 100644 --- a/pyquil/_parser/parser.py +++ b/pyquil/_parser/parser.py @@ -142,6 +142,9 @@ def def_frame(self, frame, *specs): for (spec_name, spec_value) in specs: name = names.get(spec_name, None) if name: + if isinstance(spec_value, str) and spec_value[0] == '"' and spec_value[-1] == '"': + # Strip quotes if necessary + spec_value = spec_value[1:-1] options[name] = spec_value else: raise ValueError( diff --git a/test/unit/test_parser.py b/test/unit/test_parser.py index 9cd241c41..16b190bd8 100644 --- a/test/unit/test_parser.py +++ b/test/unit/test_parser.py @@ -684,3 +684,14 @@ def test_parse_defgate_as_pauli(): ) def test_parse_comments(program): Program(program) + + +def test_parse_strings_with_spaces(): + Program(str(Program(""" +DEFFRAME 0 "readout_tx": + DIRECTION: "tx" + INITIAL-FREQUENCY: 7220000000.0 + CENTER-FREQUENCY: 7125000000 + HARDWARE-OBJECT: "A_string_with_one space" + SAMPLE-RATE: 1000000000.0 +""")))