Boolean type field attribute syntax
This commit is contained in:
parent
508cd1793e
commit
d61bbaeef0
2 changed files with 19 additions and 3 deletions
|
|
@ -26,7 +26,7 @@ calc_grammar = """
|
||||||
|
|
||||||
?attr_list: attr_pair ("," attr_pair)*
|
?attr_list: attr_pair ("," attr_pair)*
|
||||||
|
|
||||||
?attr_pair: NAME "=" NAME
|
?attr_pair: NAME "=" BOOL
|
||||||
| NAME "=" INT
|
| NAME "=" INT
|
||||||
|
|
||||||
?sum: product
|
?sum: product
|
||||||
|
|
@ -71,12 +71,19 @@ calc_grammar = """
|
||||||
%import common.INT
|
%import common.INT
|
||||||
%import common.WS
|
%import common.WS
|
||||||
|
|
||||||
|
BOOL: "true" | "false"
|
||||||
|
|
||||||
COMMENT: /#.*/
|
COMMENT: /#.*/
|
||||||
|
|
||||||
%ignore COMMENT
|
%ignore COMMENT
|
||||||
%ignore WS
|
%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):
|
def tok_to_int(tok):
|
||||||
"Convert the value of `tok` from string to int, while maintaining line number & column."
|
"Convert the value of `tok` from string to int, while maintaining line number & column."
|
||||||
# tok.type == 'INT'
|
# tok.type == 'INT'
|
||||||
|
|
@ -122,7 +129,16 @@ class VersionInfo(object):
|
||||||
|
|
||||||
def test(terms_raw, report=False):
|
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)
|
ir1 = Stage1(tree)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ nx = - ddx(c) / fsd
|
||||||
ny = - ddy(c) / fsd
|
ny = - ddy(c) / fsd
|
||||||
nz = - ddz(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 }
|
avg { c, fsd, divn }
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue