def make_special_call(name, *args): return m.sequence( m.keyword(func=verbatim_token(name)), svtok('('), m.keyword(args=m.transform(lambda v: [v], m.sequence(*args))), svtok(')'), )
def value(value): value = m.any(m.sequence(svtok('('), value, svtok(')')), case_expression, simplified_case_expression, cast_expression, count_all, call_analytics_function, call_set_function, special_calls, call, null, integer, string, bool_, name, float_) value = m.any( m.construct( a.Cast, m.keyword(value=value), svtok('::'), m.keyword(type=value), ), value, ) value = unary_op(value, '+', '-') value = binary_op(value, '^') value = binary_op(value, '*', '/', '%') value = binary_op(value, '||') value = binary_op(value, '+', '-', '&', '|') value = binary_op(value, '#', '<<', '>>') value = unary_op(value, '~') value = binary_op(value, '=', '!=', '>', '<', '>=', '<=', '<>', '!>', '!<') value = unary_op(value, 'not') value = binary_op(value, 'and') value = m.transform( build_binary_tree, m.list_of( m.any( compound_token('not', 'like'), compound_token('not', 'in'), verbatim_token('in', 'or', 'like'), ), value)) return value
def binary_op(value, *ops): return m.transform(build_binary_tree, m.list_of(verbatim_token(*ops), value))
def compound_token(*parts): return m.transform( lambda s: [' '.join(s)], m.sequence(*[verbatim_token(p) for p in parts]), )
float_ = m.construct(a.Float, m.keyword(value=regex_token(float_format))) bool_ = m.construct(a.Bool, m.keyword(value=verbatim_token('true', 'false'))) string = m.construct(a.String, m.keyword(value=base_string())) base_name = m.any( m.pred(lambda v: v not in keywords and re.match(name_format, v)), base_string('"'), ) name = m.transform( lambda *parts: [a.Name('.'.join(*parts))], m.sequence( m.optional(m.sequence(base_name, svtok('.'))), m.optional(m.sequence(base_name, svtok('.'))), base_name, )) @m.define def value(value): value = m.any(m.sequence(svtok('('), value, svtok(')')), case_expression, simplified_case_expression, cast_expression, count_all, call_analytics_function, call_set_function, special_calls, call, null, integer, string, bool_, name, float_) value = m.any( m.construct( a.Cast,