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 subquery(_): return m.construct( a.SubQuery, svtok('('), m.keyword(query=select), svtok(')'), m.optional(m.keyword(alias=alias)), )
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 unary_op(value, *ops): return m.any( m.construct(a.UnaryOp, m.keyword(op=verbatim_token(*ops)), m.keyword(arg=value)), value, )
'|', '^', '=', '!=', '>', '<', '>=', '<=', '<>', '!>', '!<', } null = m.construct(a.Null, svtok('null')) integer = m.construct(a.Integer, m.keyword(value=regex_token(integer_format))) 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(