[feaLib] Fix writing back nested glyph classes

Before this change, the following glyph class:

  @Vowels = [@Vowels.lc @Vowels.uc y Y];

Would be written back as:

  @Vowels = [@Vowels.lc = [a e i o u]; @Vowels.uc = [A E I O U]; y Y];

Which is clearly invalid. It seems for GlyphClass.asFea() to work
correctly here we should be using GlyphClassName not GlyphClass
for the nested classes (similar to the code at the beginning of
parse_glyphclass_()).
This commit is contained in:
Khaled Hosny 2017-10-27 21:20:30 +02:00
parent 26a2616286
commit 534326bd1d
2 changed files with 6 additions and 0 deletions

View File

@ -293,6 +293,10 @@ class Parser(object):
raise FeatureLibError(
"Unknown glyph class @%s" % self.cur_token_,
self.cur_token_location_)
if isinstance(gc, self.ast.MarkClass):
gc = self.ast.MarkClassName(self.cur_token_location_, gc)
else:
gc = self.ast.GlyphClassName(self.cur_token_location_, gc)
glyphs.add_class(gc)
else:
raise FeatureLibError(

View File

@ -363,6 +363,8 @@ class ParserTest(unittest.TestCase):
self.assertEqual(vowels_lc.glyphSet(), tuple("aeiou"))
self.assertEqual(vowels_uc.glyphSet(), tuple("AEIOU"))
self.assertEqual(vowels.glyphSet(), tuple("aeiouAEIOUyY"))
self.assertEqual(vowels.asFea(),
"@Vowels = [@Vowels.lc @Vowels.uc y Y];")
self.assertRaisesRegex(
FeatureLibError, "Unknown glyph class @unknown",
self.parse, "@bad = [@unknown];")