[feaLib] Method to parse Character statements

This commit is contained in:
Miguel Sousa 2018-02-05 23:17:16 -08:00 committed by Cosimo Lupo
parent 82c54f4601
commit 0667875538
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482
2 changed files with 30 additions and 0 deletions

View File

@ -1153,6 +1153,19 @@ class SizeParameters(Statement):
return res + ";"
class CharacterStatement(Statement):
"""
Statement used in cvParameters blocks of Character Variant features (cvXX).
The Unicode value may be written with either decimal or hexadecimal
notation. The value must be preceded by '0x' if it is a hexadecimal value.
The largest Unicode value allowed is 0xFFFFFF.
"""
def __init__(self, location, character, tag):
Statement.__init__(self, location)
self.character = character
self.tag = tag
class BaseAxis(Statement):
def __init__(self, bases, scripts, vertical, location=None):
Statement.__init__(self, location)

View File

@ -1310,6 +1310,16 @@ class Parser(object):
self.expect_symbol_(";")
return block
def parse_cvCharacter_(self, tag):
assert self.cur_token_ == "Character", self.cur_token_
location, character = self.cur_token_location_, self.expect_decimal_or_hexadecimal_()
self.expect_symbol_(";")
if not (0xFFFFFF >= character >= 0):
raise FeatureLibError("Character value must be between "
"{:#x} and {:#x}".format(0, 0xFFFFFF),
location)
return self.ast.CharacterStatement(location, character, tag)
def parse_FontRevision_(self):
assert self.cur_token_ == "FontRevision", self.cur_token_
location, version = self.cur_token_location_, self.expect_float_()
@ -1530,6 +1540,13 @@ class Parser(object):
raise FeatureLibError("Expected an integer or floating-point number",
self.cur_token_location_)
def expect_decimal_or_hexadecimal_(self):
self.advance_lexer_()
if self.cur_token_type_ is Lexer.NUMBER:
return self.cur_token_
raise FeatureLibError("Expected a decimal or hexadecimal number",
self.cur_token_location_)
def expect_string_(self):
self.advance_lexer_()
if self.cur_token_type_ is Lexer.STRING: