[feaLib] Generalize FeatureNamesBlock

This commit is contained in:
Miguel Sousa 2018-02-05 21:59:51 -08:00 committed by Cosimo Lupo
parent fd807bd70a
commit a4c055c18a
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482
3 changed files with 8 additions and 7 deletions

View File

@ -229,14 +229,15 @@ class FeatureBlock(Block):
return res
class FeatureNamesBlock(Block):
def __init__(self, location=None):
class NestedBlock(Block):
def __init__(self, block_name, location=None):
Block.__init__(self, location)
self.block_name = block_name
def asFea(self, indent=""):
res = indent + "featureNames {\n"
res = "{}{} {{\n".format(indent, self.block_name)
res += Block.asFea(self, indent=indent)
res += indent + "};\n"
res += "{}}};\n".format(indent)
return res

View File

@ -1243,7 +1243,7 @@ class Parser(object):
def parse_featureNames_(self, tag):
assert self.cur_token_ == "featureNames", self.cur_token_
block = self.ast.FeatureNamesBlock(self.cur_token_location_)
block = self.ast.NestedBlock(self.cur_token_location_, self.cur_token_)
self.expect_symbol_("{")
for symtab in self.symbol_tables_:
symtab.enter_scope()

View File

@ -237,7 +237,7 @@ class ParserTest(unittest.TestCase):
[feature] = self.parse(
"feature ss01 { featureNames { # Comment\n }; } ss01;").statements
[featureNames] = feature.statements
self.assertIsInstance(featureNames, ast.FeatureNamesBlock)
self.assertIsInstance(featureNames, ast.NestedBlock)
[comment] = featureNames.statements
self.assertIsInstance(comment, ast.Comment)
self.assertEqual(comment.text, "# Comment")
@ -246,7 +246,7 @@ class ParserTest(unittest.TestCase):
[feature] = self.parse(
"feature ss01 { featureNames { ;;; }; } ss01;").statements
[featureNames] = feature.statements
self.assertIsInstance(featureNames, ast.FeatureNamesBlock)
self.assertIsInstance(featureNames, ast.NestedBlock)
self.assertEqual(featureNames.statements, [])
def test_FontRevision(self):