fiql_parser/parser.py
def parse_str_to_expression(fiql_str):
    """Parse a FIQL formatted string into an ``Expression``.

    Args:
        fiql_str (string): The FIQL formatted string we want to parse.

    Returns:
        Expression: An ``Expression`` object representing the parsed FIQL
        string.

    Raises:
        FiqlFormatException: Unable to parse string due to incorrect
            formatting.

    Example:

        >>> expression = parse_str_to_expression(
        ...         "name==bar,dob=gt=1990-01-01")

    """
    #pylint: disable=too-many-branches
    nesting_lvl = 0
    last_element = None
    expression = Expression()
    for (preamble, selector, comparison, argument) in iter_parse(fiql_str):
        if preamble:
            for char in preamble:
                if char == '(':
                    if isinstance(last_element, BaseExpression):
                        raise FiqlFormatException(
                            "%s can not be followed by %s" % (
                                last_element.__class__, Expression))
                    expression = expression.create_nested_expression()
                    nesting_lvl += 1
                elif char == ')':
                    expression = expression.get_parent()
                    last_element = expression
                    nesting_lvl -= 1
                else:
                    if not expression.has_constraint():
                        raise FiqlFormatException(
                            "%s proceeding initial %s" % (
                                Operator, Constraint))
                    if isinstance(last_element, Operator):
                        raise FiqlFormatException(
                            "%s can not be followed by %s" % (
                                Operator, Operator))
                    last_element = Operator(char)
                    expression = expression.add_operator(last_element)
        if selector:
            if isinstance(last_element, BaseExpression):
                raise FiqlFormatException("%s can not be followed by %s" % (
                    last_element.__class__, Constraint))
            last_element = Constraint(selector, comparison, argument)
            expression.add_element(last_element)
    if nesting_lvl != 0:
        raise FiqlFormatException(
            "At least one nested expression was not correctly closed")
    if not expression.has_constraint():
        raise FiqlFormatException(
            "Parsed string '%s' contained no constraint" % fiql_str)
    return expression
def parse_str_to_expression(fiql_str):
    #pylint: disable=too-many-branches
    nesting_lvl = 0
    last_element = None
    expression = Expression()
    for (preamble, selector, comparison, argument) in iter_parse(fiql_str):
        if preamble:
            for char in preamble:
                if char == '(':
                    if isinstance(last_element, BaseExpression):
                        raise FiqlFormatException(
                            "%s can not be followed by %s" % (
                                last_element.__class__, Expression))
                    expression = expression.create_nested_expression()
                    nesting_lvl += 1
                elif char == ')':
                    expression = expression.get_parent()
                    last_element = expression
                    nesting_lvl -= 1
                else:
                    if not expression.has_constraint():
                        raise FiqlFormatException(
                            "%s proceeding initial %s" % (
                                Operator, Constraint))
                    if isinstance(last_element, Operator):
                        raise FiqlFormatException(
                            "%s can not be followed by %s" % (
                                Operator, Operator))
                    last_element = Operator(char)
                    expression = expression.add_operator(last_element)
        if selector:
            if isinstance(last_element, BaseExpression):
                raise FiqlFormatException("%s can not be followed by %s" % (
                    last_element.__class__, Constraint))
            last_element = Constraint(selector, comparison, argument)
            expression.add_element(last_element)
    if nesting_lvl != 0:
        raise FiqlFormatException(
            "At least one nested expression was not correctly closed")
    if not expression.has_constraint():
        raise FiqlFormatException(
            "Parsed string '%s' contained no constraint" % fiql_str)
    return expression
def parse_str_to_expression ( fiql_str ) : #pylint: disable=too-many-branches nesting_lvl = 0 last_element = None expression = Expression ( ) for ( preamble , selector , comparison , argument ) in iter_parse ( fiql_str ) : if preamble : for char in preamble : if char == '(' : if isinstance ( last_element , BaseExpression ) : raise FiqlFormatException ( "%s can not be followed by %s" % ( last_element . __class__ , Expression ) ) expression = expression . create_nested_expression ( ) nesting_lvl += 1 elif char == ')' : expression = expression . get_parent ( ) last_element = expression nesting_lvl -= 1 else : if not expression . has_constraint ( ) : raise FiqlFormatException ( "%s proceeding initial %s" % ( Operator , Constraint ) ) if isinstance ( last_element , Operator ) : raise FiqlFormatException ( "%s can not be followed by %s" % ( Operator , Operator ) ) last_element = Operator ( char ) expression = expression . add_operator ( last_element ) if selector : if isinstance ( last_element , BaseExpression ) : raise FiqlFormatException ( "%s can not be followed by %s" % ( last_element . __class__ , Constraint ) ) last_element = Constraint ( selector , comparison , argument ) expression . add_element ( last_element ) if nesting_lvl != 0 : raise FiqlFormatException ( "At least one nested expression was not correctly closed" ) if not expression . has_constraint ( ) : raise FiqlFormatException ( "Parsed string '%s' contained no constraint" % fiql_str ) return expression
Parse a FIQL formatted string into an ``Expression``.

    Args:
        fiql_str (string): The FIQL formatted string we want to parse.

    Returns:
        Expression: An ``Expression`` object representing the parsed FIQL
        string.

    Raises:
        FiqlFormatException: Unable to parse string due to incorrect
            formatting.

    Example:

        >>> expression = parse_str_to_expression(
        ...         "name==bar,dob=gt=1990-01-01")
Parse a FIQL formatted string into an Expression .