Beispiel #1
0
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
Beispiel #2
0
def binary_op(value, *ops):
    return m.transform(build_binary_tree, m.list_of(verbatim_token(*ops),
                                                    value))
Beispiel #3
0
)

count_all = m.construct(
    a.CallSetFunction,
    m.keyword(func=verbatim_token('count')),
    svtok('('),
    m.keyword(
        args=m.transform(lambda t: [[a.WildCard()]], verbatim_token('*'))),
    svtok(')'),
)

call = m.construct(
    a.Call,
    m.keyword(func=base_name),
    svtok('('),
    m.any(m.keyword(args=m.list_of(svtok(','), value)),
          m.keyword(args=m.literal([]))),
    svtok(')'),
)

special_calls = m.construct(
    a.Call,
    m.any(
        make_special_call(
            'trim',
            m.any(
                m.map(a.String.make,
                      verbatim_token('both', 'leading', 'trailing')),
                m.literal(a.String("'both'")),
            ),
            m.any(string, m.literal(a.String("' '"))),