[feaLib.parser] Parse a feature file with only comments

This commit is contained in:
Jany Belluz 2018-01-22 17:07:28 +00:00
parent 29deb7e6fb
commit d6a5a489c0
3 changed files with 11 additions and 1 deletions

View File

@ -47,7 +47,7 @@ class Parser(object):
def parse(self):
statements = self.doc_.statements
while self.next_token_type_ is not None:
while self.next_token_type_ is not None or self.cur_comments_:
self.advance_lexer_(comments=True)
if self.cur_token_type_ is Lexer.COMMENT:
statements.append(self.ast.Comment(self.cur_token_location_, self.cur_token_))

View File

@ -9,6 +9,7 @@ import unittest
def lex(s):
return [(typ, tok) for (typ, tok, _) in Lexer(s, "test.fea")]
class LexerTest(unittest.TestCase):
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)

View File

@ -86,6 +86,15 @@ class ParserTest(unittest.TestCase):
self.assertEqual(c2.text, "# simple")
self.assertEqual(doc.statements[1].name, "test")
def test_only_comments(self):
doc = self.parse("""\
# Initial
""")
c1 = doc.statements[0]
self.assertEqual(type(c1), ast.Comment)
self.assertEqual(c1.text, "# Initial")
self.assertEqual(str(c1), "# Initial")
def test_anchor_format_a(self):
doc = self.parse(
"feature test {"