[voltLib] expand enum when creating GroupDefinition
This commit is contained in:
parent
7ab01f730c
commit
1c4de40936
@ -17,7 +17,9 @@ class GlyphDefinition(ast.Statement):
|
|||||||
self.components = components
|
self.components = components
|
||||||
|
|
||||||
class GroupDefinition(ast.Statement):
|
class GroupDefinition(ast.Statement):
|
||||||
def __init__(self, location, name, enum):
|
def __init__(self, location, name, glyphs, groups, ranges):
|
||||||
ast.Statement.__init__(self,location)
|
ast.Statement.__init__(self,location)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.enum = enum
|
self.enum = {"glyphs": glyphs,
|
||||||
|
"groups": groups,
|
||||||
|
"ranges": ranges}
|
||||||
|
@ -81,10 +81,37 @@ class Parser(object):
|
|||||||
if self.groups_.resolve(name) is not None:
|
if self.groups_.resolve(name) is not None:
|
||||||
raise VoltLibError('Glyph group "%s" already defined' % name,
|
raise VoltLibError('Glyph group "%s" already defined' % name,
|
||||||
location)
|
location)
|
||||||
def_group = ast.GroupDefinition(location, name, enum)
|
def_group = ast.GroupDefinition(location, name, **enum)
|
||||||
self.groups_.define(name, def_group)
|
self.groups_.define(name, def_group)
|
||||||
return def_group
|
return def_group
|
||||||
|
|
||||||
|
def parse_def_script_(self):
|
||||||
|
assert self.is_cur_keyword_("DEF_SCRIPT")
|
||||||
|
location = self.cur_token_location_
|
||||||
|
self.expect_keyword_("NAME")
|
||||||
|
name = self.expect_string_()
|
||||||
|
self.expect_keyword_("TAG")
|
||||||
|
tag = self.expect_string_()
|
||||||
|
langs = []
|
||||||
|
while self.next_token_ != "END_SCRIPT":
|
||||||
|
self.advance_lexer_()
|
||||||
|
lang = self.parse_langsys_()
|
||||||
|
self.expect_keyword_("END_LANGSYS")
|
||||||
|
langs.append(lang)
|
||||||
|
self.expect_keyword_("END_SCRIPT")
|
||||||
|
def_script = ast.ScriptDefinition(location, name, tag, langs)
|
||||||
|
return def_script
|
||||||
|
|
||||||
|
def parse_langsys_(self):
|
||||||
|
assert self.is_cur_keyword_("DEF_LANGSYS")
|
||||||
|
location = self.cur_token_location_
|
||||||
|
self.expect_keyword_("NAME")
|
||||||
|
name = self.expect_string_()
|
||||||
|
self.expect_keyword_("TAG")
|
||||||
|
tag = self.expect_string_()
|
||||||
|
def_langsys = ast.LangSysDefinition(location, name, tag)
|
||||||
|
return def_langsys
|
||||||
|
|
||||||
def parse_unicode_values_(self):
|
def parse_unicode_values_(self):
|
||||||
location = self.cur_token_location_
|
location = self.cur_token_location_
|
||||||
unicode_values = self.expect_string_().split(',')
|
unicode_values = self.expect_string_().split(',')
|
||||||
|
@ -99,6 +99,21 @@ class ParserTest(unittest.TestCase):
|
|||||||
'END_GROUP\n'
|
'END_GROUP\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_langsys(self):
|
||||||
|
[def_script] = self.parse(
|
||||||
|
'DEF_SCRIPT NAME "Latin" TAG "latn"\n'
|
||||||
|
'DEF_LANGSYS NAME "Romanian" TAG "ROM "\n'
|
||||||
|
'END_LANGSYS\n'
|
||||||
|
'END_SCRIPT'
|
||||||
|
).statements
|
||||||
|
self.assertEqual((def_script.name, def_script.tag),
|
||||||
|
("Latin",
|
||||||
|
"latn"))
|
||||||
|
def_lang = def_script.langs[0]
|
||||||
|
self.assertEqual((def_lang.name, def_lang.tag),
|
||||||
|
("Romanian",
|
||||||
|
"ROM "))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.tempdir = None
|
self.tempdir = None
|
||||||
self.num_tempfiles = 0
|
self.num_tempfiles = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user