[feaLib] Method to parse Character statements
This commit is contained in:
parent
82c54f4601
commit
0667875538
@ -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)
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user