[feaLib] Parse rules for multiple substitution (GSUB LookupType 2)

This commit is contained in:
Sascha Brawer 2015-08-11 16:45:54 +02:00
parent 72c1f165b4
commit fb050c7a7f
2 changed files with 13 additions and 2 deletions

View File

@ -219,15 +219,16 @@ class Parser(object):
location = self.cur_token_location_
old_prefix, old, lookups, old_suffix = self.parse_glyph_pattern_()
new = []
if self.next_token_ == "by":
keyword = self.expect_keyword_("by")
new = [self.parse_glyphclass_(accept_glyphname=True)]
while self.next_token_ != ";":
new.append(self.parse_glyphclass_(accept_glyphname=True))
elif self.next_token_ == "from":
keyword = self.expect_keyword_("from")
new = [self.parse_glyphclass_(accept_glyphname=False)]
else:
keyword = None
new = []
self.expect_symbol_(";")
if len(new) is 0 and not any(lookups):
raise ParserError(

View File

@ -289,6 +289,16 @@ class ParserTest(unittest.TestCase):
self.assertEqual(sub.new, [{"A.sc", "B.sc", "C.sc", "D.sc"}])
self.assertEqual(sub.lookups, [None])
def test_substitute_multiple(self): # GSUB LookupType 2
doc = self.parse("lookup Look {substitute f_f_i by f f i;} Look;")
sub = doc.statements[0].statements[0]
self.assertEqual(type(sub), ast.SubstitutionRule)
self.assertEqual(sub.old_prefix, [])
self.assertEqual(sub.old, [{"f_f_i"}])
self.assertEqual(sub.old_suffix, [])
self.assertEqual(sub.new, [{"f"}, {"f"}, {"i"}])
self.assertEqual(sub.lookups, [None])
def test_substitute_from(self): # GSUB LookupType 3
doc = self.parse("feature test {"
" substitute a from [a.1 a.2 a.3];"