[feaLib.parser] Parse a feature file with only comments
This commit is contained in:
parent
29deb7e6fb
commit
d6a5a489c0
@ -47,7 +47,7 @@ class Parser(object):
|
|||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
statements = self.doc_.statements
|
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)
|
self.advance_lexer_(comments=True)
|
||||||
if self.cur_token_type_ is Lexer.COMMENT:
|
if self.cur_token_type_ is Lexer.COMMENT:
|
||||||
statements.append(self.ast.Comment(self.cur_token_location_, self.cur_token_))
|
statements.append(self.ast.Comment(self.cur_token_location_, self.cur_token_))
|
||||||
|
@ -9,6 +9,7 @@ import unittest
|
|||||||
def lex(s):
|
def lex(s):
|
||||||
return [(typ, tok) for (typ, tok, _) in Lexer(s, "test.fea")]
|
return [(typ, tok) for (typ, tok, _) in Lexer(s, "test.fea")]
|
||||||
|
|
||||||
|
|
||||||
class LexerTest(unittest.TestCase):
|
class LexerTest(unittest.TestCase):
|
||||||
def __init__(self, methodName):
|
def __init__(self, methodName):
|
||||||
unittest.TestCase.__init__(self, methodName)
|
unittest.TestCase.__init__(self, methodName)
|
||||||
|
@ -86,6 +86,15 @@ class ParserTest(unittest.TestCase):
|
|||||||
self.assertEqual(c2.text, "# simple")
|
self.assertEqual(c2.text, "# simple")
|
||||||
self.assertEqual(doc.statements[1].name, "test")
|
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):
|
def test_anchor_format_a(self):
|
||||||
doc = self.parse(
|
doc = self.parse(
|
||||||
"feature test {"
|
"feature test {"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user