Beispiel #1
0
def convert_meta(node, state, arguments):
    state.ensure(node, state.pointer == "__metadata__")

    filters = None
    if arguments.parent:
        filters = IR.combine_filters(filters,
                                     metadata_parent(arguments.parent, state))
    return filters
Beispiel #2
0
 def compile_query(self):
     query = compile_query(self.reiz_ql, limit=None, offset=0)
     query.filters = IR.combine_filters(
         query.filters,
         IR.filter(
             IR.attribute(IR.attribute(None, "_module"), "filename"),
             IR.literal(self.expected_filename),
             "=",
         ),
     )
     return IR.construct(query)
Beispiel #3
0
def compile_matcher(node, state):
    if state is None:
        state = CompilerState(node.name)
    else:
        state = CompilerState.from_parent(node.name, state)

    filters = None
    for key, value in node.filters.items():
        if value is grammar.Ignore:
            continue

        if right_filter := state.compile(key, value):
            filters = IR.combine_filters(filters, right_filter)
Beispiel #4
0
def convert_length(node, state, arguments):
    state.ensure(node, any((arguments.min, arguments.max)))

    count = IR.call("count", [state.compute_path()])
    filters = None
    for value, operator in [
        (arguments.min, IR.as_operator(">=")),
        (arguments.max, IR.as_operator("<=")),
    ]:
        if value is None:
            continue

        state.ensure(value, isinstance(value, grammar.Constant))
        state.ensure(value, isinstance(value.value, int))
        filters = IR.combine_filters(
            filters, IR.filter(count, IR.literal(value.value), operator))

    assert filters is not None
    return filters
Beispiel #5
0
        state = CompilerState(node.name)
    else:
        state = CompilerState.from_parent(node.name, state)

    filters = None
    for key, value in node.filters.items():
        if value is grammar.Ignore:
            continue

        if right_filter := state.compile(key, value):
            filters = IR.combine_filters(filters, right_filter)

    if state.is_root:
        state.scope.exit()
        if state_filters := IR.unpack_filters(state.filters):
            filters = IR.combine_filters(filters, state_filters)
        if state.variables:
            namespace = IR.namespace(state.variables)
            filters = IR.add_namespace(namespace, IR.select(filters))
        return IR.select(state.match, filters=filters)

    if filters is None:
        filters = IR.filter(state.parents[-1].compute_path(),
                            IR.wrap(state.match), "IS")

    return filters


@codegen.register(grammar.MatchEnum)
def convert_match_enum(node, state):
    expr = IR.enum_member(node.base, node.name)