예제 #1
0
파일: queryparse.py 프로젝트: jortizcs/smap
def p_formula_multiply(t):
    """formula_multiply : NUMBER '*' formula
                        | formula '*' NUMBER
                        | NUMBER '*' NUMBER
                        | formula '*' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] * t[3]
    elif is_number(t[1]):
        t[0] = formula(ast.nodemaker(stream.get_operator("multiply", ([t[1]], {})), t[3].ast), t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(ast.nodemaker(stream.get_operator("multiply", ([t[3]], {})), t[1].ast), t[1].restrict)
    else:
        t[0] = formula(
            ast.nodemaker(
                operators.make_composition_operator(
                    [
                        stream.get_operator("paste", ([], {"sort": None})),
                        stream.get_operator("product", ([], {"axis": 1})),
                    ]
                ),
                t[1].ast,
                t[3].ast,
            ),
            t[1].restrict + t[3].restrict,
        )
예제 #2
0
def p_formula_multiply(t):
    """formula_multiply : NUMBER '*' formula
                        | formula '*' NUMBER
                        | NUMBER '*' NUMBER
                        | formula '*' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] * t[3]
    elif is_number(t[1]):
        t[0] = formula(
            ast.nodemaker(stream.get_operator('multiply', ([t[1]], {})),
                          t[3].ast), t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(
            ast.nodemaker(stream.get_operator('multiply', ([t[3]], {})),
                          t[1].ast), t[1].restrict)
    else:
        t[0] = formula(
            ast.nodemaker(
                operators.make_composition_operator([
                    stream.get_operator('paste', ([], {
                        'sort': None
                    })),
                    stream.get_operator('product', ([], {
                        'axis': 1
                    }))
                ]), t[1].ast, t[3].ast), t[1].restrict + t[3].restrict)
예제 #3
0
def p_formula_subtract(t):
    """formula_subtract : NUMBER '-' NUMBER
                        | formula '-' NUMBER
                        | formula '-' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] - t[3]
    elif is_number(t[1]):
        t[0] = formula(
            ast.nodemaker(stream.get_operator('add', ([t[1]], {})), t[3].ast),
            t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(
            ast.nodemaker(stream.get_operator('add', ([-t[3]], {})), t[1].ast),
            t[1].restrict)
    else:
        t[0] = formula(
            ast.nodemaker(
                operators.make_composition_operator([
                    stream.get_operator('paste', ([], {
                        'sort': None
                    })),
                    stream.get_operator('diff', ([], {
                        'axis': 1
                    }))
                ]), t[3].ast, t[1].ast), t[3].restrict + t[1].restrict)
예제 #4
0
def p_formula_comparator(t):
    """formula_comparator : formula comparator NUMBER
                          | NUMBER comparator formula
    """
    if is_number(t[1]):
        pass
    else:
        # have to initialize the comparison operator with an
        # appropriate inner AST node.  usually this is done by the
        # parser...
        cmp = ast.nodemaker(stream.get_operator(cmp_names[t[2]], ([t[3]], {})),
                            ast.leafmaker(stream.get_operator('null', ([], {}))))
        t[0] = formula(ast.nodemaker(stream.get_operator('nonzero', ([cmp], {})), t[1].ast),
                       t[1].restrict)
예제 #5
0
def p_formula_comparator(t):
    """formula_comparator : formula comparator NUMBER
                          | NUMBER comparator formula
    """
    if is_number(t[1]):
        pass
    else:
        # have to initialize the comparison operator with an
        # appropriate inner AST node.  usually this is done by the
        # parser...
        cmp = ast.nodemaker(stream.get_operator(cmp_names[t[2]], ([t[3]], {})),
                            ast.leafmaker(stream.get_operator('null', ([], {}))))
        t[0] = formula(ast.nodemaker(stream.get_operator('nonzero', ([cmp], {})), t[1].ast),
                       t[1].restrict)
예제 #6
0
파일: queryparse.py 프로젝트: jortizcs/smap
def p_formula_where_clause(t):
    """formula_where_clause : '[' LVALUE '.' QSTRING ']'
                            | '[' formula ']'
                            | ALL
                            | QSTRING
                            | 
    """
    if len(t) == 6:
        t[0] = formula(ast.leafmaker(stream.get_operator("w", ([t[2], t[4]], {}))), [(t[2], t[4])])
    elif len(t) == 4:
        t[0] = t[2]
    elif len(t) == 2 and t[1] == "all":
        t[0] = formula(ast.leafmaker(stream.get_operator("w", (["uuid", ".*"], {}))), [])
    elif len(t) == 2:
        t[0] = formula(ast.leafmaker(stream.get_operator("w", (["x", t[1]], {}))), [("x", t[1])])
    else:
        t[0] = formula(ast.leafmaker(stream.get_operator("null", ([], {}))), [])
예제 #7
0
def p_formula_subtract(t):
    """formula_subtract : NUMBER '-' NUMBER
                        | formula '-' NUMBER
                        | formula '-' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] - t[3]
    elif is_number(t[1]):
        t[0] = formula(ast.nodemaker(stream.get_operator('add', ([t[1]], {})), t[3].ast),
                       t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(ast.nodemaker(stream.get_operator('add', ([- t[3]], {})), t[1].ast),
                       t[1].restrict)
    else:
        t[0] = formula(ast.nodemaker(operators.make_composition_operator(
                    [stream.get_operator('paste', ([], {'sort': None})),
                     stream.get_operator('diff', ([], {'axis': 1}))]),
                                     t[3].ast, t[1].ast),
                       t[3].restrict + t[1].restrict)
예제 #8
0
def p_formula_where_clause(t):
    """formula_where_clause : '[' LVALUE '.' QSTRING ']'
                            | '[' formula ']'
                            | ALL
                            | QSTRING
                            | 
    """
    if len(t) == 6:
        t[0] = formula(ast.leafmaker(stream.get_operator('w', ([t[2], t[4]], {}))),
                       [(t[2], t[4])])
    elif len(t) == 4:
        t[0] = t[2]
    elif len(t) == 2 and t[1] == 'all':
        t[0] = formula(ast.leafmaker(stream.get_operator('w', (['uuid', '.*'], {}))),
                       [])
    elif len(t) == 2:
        t[0] = formula(ast.leafmaker(stream.get_operator('w', (['x', t[1]], {}))),
                       [('x', t[1])])
    else:
        t[0] = formula(ast.leafmaker(stream.get_operator('null', ([], {}))), [])
예제 #9
0
def p_formula_multiply(t):
    """formula_multiply : NUMBER '*' formula
                        | formula '*' NUMBER
                        | NUMBER '*' NUMBER
                        | formula '*' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] * t[3]
    elif is_number(t[1]):
        t[0] = formula(ast.nodemaker(stream.get_operator('multiply', ([t[1]], {})), t[3].ast),
                       t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(ast.nodemaker(stream.get_operator('multiply', ([t[3]], {})), t[1].ast),
                       t[1].restrict)
    else:
        t[0] = formula(ast.nodemaker(operators.make_composition_operator(
                    [stream.get_operator('paste', ([], {'sort': None})),
                     stream.get_operator('product', ([], {'axis': 1}))]),
                                     t[1].ast, t[3].ast),
                       t[1].restrict + t[3].restrict)
예제 #10
0
def p_formula_where_clause(t):
    """formula_where_clause : '[' LVALUE '.' QSTRING ']'
                            | '[' formula ']'
                            | ALL
                            | QSTRING
                            | 
    """
    if len(t) == 6:
        t[0] = formula(ast.leafmaker(stream.get_operator('w', ([t[2], t[4]], {}))),
                       [(t[2], t[4])])
    elif len(t) == 4:
        t[0] = t[2]
    elif len(t) == 2 and t[1] == 'all':
        t[0] = formula(ast.leafmaker(stream.get_operator('w', (['uuid', '.*'], {}))),
                       [])
    elif len(t) == 2:
        t[0] = formula(ast.leafmaker(stream.get_operator('w', (['x', t[1]], {}))),
                       [('x', t[1])])
    else:
        t[0] = formula(ast.leafmaker(stream.get_operator('null', ([], {}))), [])
예제 #11
0
파일: queryparse.py 프로젝트: jortizcs/smap
def p_formula_subtract(t):
    """formula_subtract : NUMBER '-' NUMBER
                        | formula '-' NUMBER
                        | formula '-' formula
    """
    if is_number(t[1]) and is_number(t[3]):
        t[0] = t[1] - t[3]
    elif is_number(t[1]):
        t[0] = formula(ast.nodemaker(stream.get_operator("add", ([t[1]], {})), t[3].ast), t[3].restrict)
    elif is_number(t[3]):
        t[0] = formula(ast.nodemaker(stream.get_operator("add", ([-t[3]], {})), t[1].ast), t[1].restrict)
    else:
        t[0] = formula(
            ast.nodemaker(
                operators.make_composition_operator(
                    [stream.get_operator("paste", ([], {"sort": None})), stream.get_operator("diff", ([], {"axis": 1}))]
                ),
                t[3].ast,
                t[1].ast,
            ),
            t[3].restrict + t[1].restrict,
        )
예제 #12
0
def p_formula_divide(t):
    """formula_divide : formula '/' NUMBER"""
    t[0] = formula(
        ast.nodemaker(stream.get_operator('multiply', ([1. / t[3]], {})),
                      t[1].ast), t[1].restrict)
예제 #13
0
def p_formula_power(t):
    """formula_power : formula '^' NUMBER"""
    t[0] = formula(ast.nodemaker(stream.get_operator('power', ([t[3]], {})), t[1].ast),
                   t[1].restrict)
예제 #14
0
def p_formula_divide(t):
    """formula_divide : formula '/' NUMBER"""
    t[0] = formula(ast.nodemaker(stream.get_operator('multiply', ([1. / t[3]], {})), t[1].ast),
                   t[1].restrict)
예제 #15
0
def make_operator(name, args, where=None):
    if where == None:
        return stream.get_operator(name, args)
    else:
        return operators.make_composition_operator(
            [where, stream.get_operator(name, args)])
예제 #16
0
def p_formula_power(t):
    """formula_power : formula '^' NUMBER"""
    t[0] = formula(
        ast.nodemaker(stream.get_operator('power', ([t[3]], {})), t[1].ast),
        t[1].restrict)
예제 #17
0
def make_operator(name, args, where=None):
    if where == None:
        return stream.get_operator(name, args)
    else:
        return operators.make_composition_operator(
            [where, stream.get_operator(name, args)])