[voltLib] Unescape new line in lookup comments

This commit is contained in:
Khaled Hosny 2020-06-04 00:40:52 +02:00
parent 18886da333
commit 3c4f5a75bf
2 changed files with 16 additions and 1 deletions

View File

@ -242,7 +242,7 @@ class Parser(object):
comments = None comments = None
if self.next_token_ == "COMMENTS": if self.next_token_ == "COMMENTS":
self.expect_keyword_("COMMENTS") self.expect_keyword_("COMMENTS")
comments = self.expect_string_() comments = self.expect_string_().replace(r'\n', '\n')
context = [] context = []
while self.next_token_ in ("EXCEPT_CONTEXT", "IN_CONTEXT"): while self.next_token_ in ("EXCEPT_CONTEXT", "IN_CONTEXT"):
context = self.parse_context_() context = self.parse_context_()

View File

@ -473,6 +473,21 @@ class ParserTest(unittest.TestCase):
'END_SUBSTITUTION\n' 'END_SUBSTITUTION\n'
).statements ).statements
def test_lookup_comments(self):
[lookup] = self.parse(
'DEF_LOOKUP "test" PROCESS_BASE PROCESS_MARKS ALL DIRECTION LTR\n'
'COMMENTS "Hello\\nWorld"\n'
'IN_CONTEXT\n'
'END_CONTEXT\n'
'AS_SUBSTITUTION\n'
'SUB GLYPH "a"\n'
'WITH GLYPH "b"\n'
'END_SUB\n'
'END_SUBSTITUTION'
).statements
self.assertEqual(lookup.name, "test")
self.assertEqual(lookup.comments, "Hello\nWorld")
def test_substitution_empty(self): def test_substitution_empty(self):
with self.assertRaisesRegex( with self.assertRaisesRegex(
VoltLibError, VoltLibError,