[feaLib] Parse subtable statements

This commit is contained in:
Sascha Brawer 2015-08-11 15:14:47 +02:00
parent e132741b2c
commit f60d49471d
3 changed files with 18 additions and 0 deletions

View File

@ -65,6 +65,11 @@ class ScriptStatement(object):
self.script = script self.script = script
class SubtableStatement(object):
def __init__(self, location):
self.location = location
class SubstitutionRule(object): class SubstitutionRule(object):
def __init__(self, location, old, new): def __init__(self, location, old, new):
self.location, self.old, self.new = (location, old, new) self.location, self.old, self.new = (location, old, new)

View File

@ -232,6 +232,12 @@ class Parser(object):
rule.lookups = lookups rule.lookups = lookups
return rule return rule
def parse_subtable_(self):
assert self.is_cur_keyword_("subtable")
location = self.cur_token_location_
self.expect_symbol_(";")
return ast.SubtableStatement(location)
def parse_valuerecord_(self, vertical): def parse_valuerecord_(self, vertical):
if self.next_token_type_ is Lexer.NUMBER: if self.next_token_type_ is Lexer.NUMBER:
number, location = self.expect_number_(), self.cur_token_location_ number, location = self.expect_number_(), self.cur_token_location_
@ -308,6 +314,8 @@ class Parser(object):
elif (self.is_cur_keyword_("substitute") or elif (self.is_cur_keyword_("substitute") or
self.is_cur_keyword_("sub")): self.is_cur_keyword_("sub")):
statements.append(self.parse_substitute_()) statements.append(self.parse_substitute_())
elif self.is_cur_keyword_("subtable"):
statements.append(self.parse_subtable_())
elif self.is_cur_keyword_("valueRecordDef"): elif self.is_cur_keyword_("valueRecordDef"):
statements.append(self.parse_valuerecord_definition_(vertical)) statements.append(self.parse_valuerecord_definition_(vertical))
else: else:

View File

@ -299,6 +299,11 @@ class ParserTest(unittest.TestCase):
ParserError, 'Expected "by" or explicit lookup references', ParserError, 'Expected "by" or explicit lookup references',
self.parse, "feature liga {substitute f f i;} liga;") self.parse, "feature liga {substitute f f i;} liga;")
def test_subtable(self):
doc = self.parse("feature test {subtable;} test;")
s = doc.statements[0].statements[0]
self.assertEqual(type(s), ast.SubtableStatement)
def test_valuerecord_format_a_horizontal(self): def test_valuerecord_format_a_horizontal(self):
doc = self.parse("feature liga {valueRecordDef 123 foo;} liga;") doc = self.parse("feature liga {valueRecordDef 123 foo;} liga;")
value = doc.statements[0].statements[0].value value = doc.statements[0].statements[0].value