[voltLib] glyphSet() should return tuple
We need to maintain the glyph order and keep any duplicates.
This commit is contained in:
parent
94633e9f46
commit
4236772ec1
@ -83,7 +83,7 @@ class GlyphName(Expression):
|
||||
self.glyph = glyph
|
||||
|
||||
def glyphSet(self):
|
||||
return frozenset((self.glyph,))
|
||||
return (self.glyph,)
|
||||
|
||||
|
||||
class Enum(Expression):
|
||||
@ -106,13 +106,13 @@ class Enum(Expression):
|
||||
return hash(self.glyphSet())
|
||||
|
||||
def glyphSet(self, groups=None):
|
||||
glyphs = set()
|
||||
glyphs = []
|
||||
for element in self.enum:
|
||||
if isinstance(element, (GroupName, Enum)):
|
||||
glyphs = glyphs.union(element.glyphSet(groups))
|
||||
glyphs.extend(element.glyphSet(groups))
|
||||
else:
|
||||
glyphs = glyphs.union(element.glyphSet())
|
||||
return frozenset(glyphs)
|
||||
glyphs.extend(element.glyphSet())
|
||||
return tuple(glyphs)
|
||||
|
||||
|
||||
class GroupName(Expression):
|
||||
@ -142,8 +142,7 @@ class Range(Expression):
|
||||
self.parser = parser
|
||||
|
||||
def glyphSet(self):
|
||||
glyphs = self.parser.glyph_range(self.start, self.end)
|
||||
return frozenset(glyphs)
|
||||
return tuple(self.parser.glyph_range(self.start, self.end))
|
||||
|
||||
|
||||
class ScriptDefinition(Statement):
|
||||
|
@ -531,8 +531,7 @@ class Parser(object):
|
||||
return self.groups_.resolve(group_name)
|
||||
|
||||
def glyph_range(self, start, end):
|
||||
rng = self.glyphs_.range(start, end)
|
||||
return frozenset(rng)
|
||||
return self.glyphs_.range(start, end)
|
||||
|
||||
def parse_ppem_(self):
|
||||
location = self.cur_token_location_
|
||||
|
@ -109,9 +109,9 @@ class ParserTest(unittest.TestCase):
|
||||
).statements
|
||||
self.assertEqual((def_group.name, def_group.enum.glyphSet()),
|
||||
("aaccented",
|
||||
{"aacute", "abreve", "acircumflex", "adieresis",
|
||||
("aacute", "abreve", "acircumflex", "adieresis",
|
||||
"ae", "agrave", "amacron", "aogonek", "aring",
|
||||
"atilde"}))
|
||||
"atilde")))
|
||||
|
||||
def test_def_group_groups(self):
|
||||
parser = self.parser(
|
||||
@ -164,8 +164,8 @@ class ParserTest(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
(test_group3.name, test_group3.enum),
|
||||
("TestGroup3",
|
||||
ast.Enum([ast.GroupName("Group1", parser),
|
||||
ast.GroupName("Group2", parser)])))
|
||||
ast.Enum([ast.GroupName("Group2", parser),
|
||||
ast.GroupName("Group1", parser)])))
|
||||
|
||||
# def test_def_group_groups_undefined(self):
|
||||
# with self.assertRaisesRegex(
|
||||
@ -193,7 +193,7 @@ class ParserTest(unittest.TestCase):
|
||||
).statements
|
||||
items = def_group2.enum.enum
|
||||
self.assertEqual((def_group2.name, items[0].glyphSet(), items[1].group),
|
||||
("KERN_lc_a_2ND", {"a"}, "aaccented"))
|
||||
("KERN_lc_a_2ND", ("a",), "aaccented"))
|
||||
|
||||
def test_def_group_range(self):
|
||||
def_group = self.parse(
|
||||
@ -213,8 +213,8 @@ class ParserTest(unittest.TestCase):
|
||||
).statements[-1]
|
||||
self.assertEqual((def_group.name, def_group.enum.glyphSet()),
|
||||
("KERN_lc_a_2ND",
|
||||
{"a", "agrave", "aacute", "acircumflex", "atilde",
|
||||
"b", "c", "ccaron", "ccedilla", "cdotaccent"}))
|
||||
("a", "agrave", "aacute", "acircumflex", "atilde",
|
||||
"b", "c", "ccaron", "ccedilla", "cdotaccent")))
|
||||
|
||||
def test_group_duplicate(self):
|
||||
self.assertRaisesRegex(
|
||||
|
Loading…
x
Reference in New Issue
Block a user