Boolean type field attribute syntax

This commit is contained in:
ignis 2019-07-07 11:43:19 +09:00
parent 508cd1793e
commit d61bbaeef0
2 changed files with 19 additions and 3 deletions

View file

@ -26,7 +26,7 @@ calc_grammar = """
?attr_list: attr_pair ("," attr_pair)*
?attr_pair: NAME "=" NAME
?attr_pair: NAME "=" BOOL
| NAME "=" INT
?sum: product
@ -71,12 +71,19 @@ calc_grammar = """
%import common.INT
%import common.WS
BOOL: "true" | "false"
COMMENT: /#.*/
%ignore COMMENT
%ignore WS
"""
def tok_to_bool(tok):
"Convert the value of `tok` from string to bool, while maintaining line number & column."
# tok.type == 'BOOL'
return Token.new_borrow_pos(tok.type, tok.value == "true", tok)
def tok_to_int(tok):
"Convert the value of `tok` from string to int, while maintaining line number & column."
# tok.type == 'INT'
@ -122,7 +129,16 @@ class VersionInfo(object):
def test(terms_raw, report=False):
tree = Lark(calc_grammar, parser='lalr', lexer_callbacks = {'INT': tok_to_int}).parse(terms_raw)
parser = Lark(calc_grammar,
parser='lalr',
lexer_callbacks =
{
'INT': tok_to_int,
'BOOL': tok_to_bool
}
)
tree = parser.parse(terms_raw)
ir1 = Stage1(tree)

View file

@ -10,6 +10,6 @@ nx = - ddx(c) / fsd
ny = - ddy(c) / fsd
nz = - ddz(c) / fsd
divn (a=1, b=kill, xlow=128, xupp=320) = ddx(nx) + ddy(ny) + ddz(nz)
divn (export=true, x0=128, x1=320) = ddx(nx) + ddy(ny) + ddz(nz)
avg { c, fsd, divn }