[feaLib] Move block parsing to a separate method
We will soon support additional blocks beyond `feature`, and keeping this refactoring separate from new functionality makes it easier for code reviewers to follow the changes.
This commit is contained in:
parent
1f2fadc864
commit
6d7540ecac
@ -8,9 +8,9 @@ class FeatureFile(object):
|
||||
|
||||
|
||||
class FeatureBlock(object):
|
||||
def __init__(self, location, tag):
|
||||
def __init__(self, location, name):
|
||||
self.location = location
|
||||
self.tag = tag
|
||||
self.name = name
|
||||
self.statements = []
|
||||
|
||||
|
||||
|
@ -43,7 +43,7 @@ class Parser(object):
|
||||
elif self.is_cur_keyword_("languagesystem"):
|
||||
self.parse_languagesystem_()
|
||||
elif self.is_cur_keyword_("feature"):
|
||||
self.parse_feature_block_()
|
||||
statements.append(self.parse_feature_block_())
|
||||
else:
|
||||
raise ParserError("Expected languagesystem, feature, or "
|
||||
"glyph class definition",
|
||||
@ -214,15 +214,16 @@ class Parser(object):
|
||||
location = self.cur_token_location_
|
||||
tag = self.expect_tag_()
|
||||
vertical = (tag == "vkrn")
|
||||
block = ast.FeatureBlock(location, tag)
|
||||
self.parse_block_(block, vertical)
|
||||
return block
|
||||
|
||||
def parse_block_(self, block, vertical):
|
||||
self.expect_symbol_("{")
|
||||
for symtab in self.symbol_tables_:
|
||||
symtab.enter_scope()
|
||||
|
||||
block = ast.FeatureBlock(location, tag)
|
||||
self.doc_.statements.append(block)
|
||||
statements = block.statements
|
||||
|
||||
while self.next_token_ != "}":
|
||||
self.advance_lexer_()
|
||||
if self.cur_token_type_ is Lexer.GLYPHCLASS:
|
||||
@ -248,9 +249,9 @@ class Parser(object):
|
||||
for symtab in self.symbol_tables_:
|
||||
symtab.exit_scope()
|
||||
|
||||
endtag = self.expect_tag_()
|
||||
if tag != endtag:
|
||||
raise ParserError("Expected \"%s\"" % tag.strip(),
|
||||
name = self.expect_name_()
|
||||
if name != block.name.strip():
|
||||
raise ParserError("Expected \"%s\"" % block.name.strip(),
|
||||
self.cur_token_location_)
|
||||
self.expect_symbol_(";")
|
||||
|
||||
|
@ -286,7 +286,7 @@ class ParserTest(unittest.TestCase):
|
||||
|
||||
def test_feature_block(self):
|
||||
[liga] = self.parse("feature liga {} liga;").statements
|
||||
self.assertEqual(liga.tag, "liga")
|
||||
self.assertEqual(liga.name, "liga")
|
||||
|
||||
def setUp(self):
|
||||
self.tempdir = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user