[feaLib] Parse rules for multiple substitution (GSUB LookupType 2)
This commit is contained in:
parent
72c1f165b4
commit
fb050c7a7f
@ -219,15 +219,16 @@ class Parser(object):
|
|||||||
location = self.cur_token_location_
|
location = self.cur_token_location_
|
||||||
old_prefix, old, lookups, old_suffix = self.parse_glyph_pattern_()
|
old_prefix, old, lookups, old_suffix = self.parse_glyph_pattern_()
|
||||||
|
|
||||||
|
new = []
|
||||||
if self.next_token_ == "by":
|
if self.next_token_ == "by":
|
||||||
keyword = self.expect_keyword_("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":
|
elif self.next_token_ == "from":
|
||||||
keyword = self.expect_keyword_("from")
|
keyword = self.expect_keyword_("from")
|
||||||
new = [self.parse_glyphclass_(accept_glyphname=False)]
|
new = [self.parse_glyphclass_(accept_glyphname=False)]
|
||||||
else:
|
else:
|
||||||
keyword = None
|
keyword = None
|
||||||
new = []
|
|
||||||
self.expect_symbol_(";")
|
self.expect_symbol_(";")
|
||||||
if len(new) is 0 and not any(lookups):
|
if len(new) is 0 and not any(lookups):
|
||||||
raise ParserError(
|
raise ParserError(
|
||||||
|
@ -289,6 +289,16 @@ class ParserTest(unittest.TestCase):
|
|||||||
self.assertEqual(sub.new, [{"A.sc", "B.sc", "C.sc", "D.sc"}])
|
self.assertEqual(sub.new, [{"A.sc", "B.sc", "C.sc", "D.sc"}])
|
||||||
self.assertEqual(sub.lookups, [None])
|
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
|
def test_substitute_from(self): # GSUB LookupType 3
|
||||||
doc = self.parse("feature test {"
|
doc = self.parse("feature test {"
|
||||||
" substitute a from [a.1 a.2 a.3];"
|
" substitute a from [a.1 a.2 a.3];"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user