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