[voltLib] lookup name must start with letter

This commit is contained in:
moyogo 2016-01-26 11:44:17 +00:00
parent 1dbb08a296
commit 23106f71ec
2 changed files with 19 additions and 0 deletions

View File

@ -161,6 +161,11 @@ class Parser(object):
assert self.is_cur_keyword_("DEF_LOOKUP") assert self.is_cur_keyword_("DEF_LOOKUP")
location = self.cur_token_location_ location = self.cur_token_location_
name = self.expect_string_() name = self.expect_string_()
if not name[0].isalpha():
raise VoltLibError(
'Lookup name "%s" must start with a letter' % name,
location
)
if self.lookups_.resolve(name) is not None: if self.lookups_.resolve(name) is not None:
raise VoltLibError( raise VoltLibError(
'Lookup "%s" already defined, ' 'Lookup "%s" already defined, '

View File

@ -360,6 +360,20 @@ class ParserTest(unittest.TestCase):
'END_SUBSTITUTION\n' 'END_SUBSTITUTION\n'
).statements ).statements
def test_lookup_name_starts_with_letter(self):
with self.assertRaisesRegex(
VoltLibError,
'Lookup name "\\\lookupname" must start with a letter'
):
[lookup] = self.parse(
'DEF_LOOKUP "\lookupname"\n'
'AS_SUBSTITUTION\n'
'SUB GLYPH "a"\n'
'WITH GLYPH "a.alt"\n'
'END_SUB\n'
'END_SUBSTITUTION\n'
).statements
def test_substitution_empty(self): def test_substitution_empty(self):
with self.assertRaisesRegex( with self.assertRaisesRegex(
VoltLibError, VoltLibError,