# Path: core/ezdxf/tools/c23.py
# PY3 = sys.version_info.major > 2
# def isstring(s):
# 
# Path: core/ezdxf/queryparser.py
# LBRK = Suppress('[')
# RBRK = Suppress(']')


import re
import operator
from .tools.c23 import isstring, Sequence
from .queryparser import EntityQueryParser
        self.tokens = tokens

    def __iter__(self):
        return iter(self.tokens)

    def evaluate(self, entity):
        if isinstance(self.tokens, Relation):  # expression is just one relation, no bool operations
            return self.tokens.evaluate(entity)

        values = []  # first in, first out
        operators = []  # first in, first out
        for token in self.tokens:
            if hasattr(token, 'evaluate'):
                values.append(token.evaluate(entity))
            else:  # bool operator
                operators.append(token)
        values.reverse()  # revert values -> pop() == pop(0) & append(value) == insert(0, value)
        for op in operators:  # as queue -> first in, first out
            if op == '!':
                value = not values.pop()
            else:
                value = BoolExpression.OPERATORS[op](values.pop(), values.pop())
            values.append(value)
        return values.pop()


def _compile_tokens(tokens, ignore_case):
    def is_relation(tokens):
        return len(tokens) == 3 and tokens[1] in Relation.VALID_CMP_OPERATORS


# Path: core/ezdxf/tools/c23.py
# PY3 = sys.version_info.major > 2
# def isstring(s):
# 
# Path: core/ezdxf/queryparser.py
# LBRK = Suppress('[')
# RBRK = Suppress(']')


# Path: core/ezdxf/query.py
import re
import operator
from .tools.c23 import isstring, Sequence
from .queryparser import EntityQueryParser

        self.tokens = tokens

    def __iter__(self):
        return iter(self.tokens)

    def evaluate(self, entity):
        if isinstance(self.tokens, Relation):  # expression is just one relation, no bool operations
            return self.tokens.evaluate(entity)

        values = []  # first in, first out
        operators = []  # first in, first out
        for token in self.tokens:
            if hasattr(token, 'evaluate'):
                values.append(token.evaluate(entity))
            else:  # bool operator
                operators.append(token)
        values.reverse()  # revert values -> pop() == pop(0) & append(value) == insert(0, value)
        for op in operators:  # as queue -> first in, first out
            if op == '!':
                value = not values.pop()
            else:
                value = BoolExpression.OPERATORS[op](values.pop(), values.pop())
            values.append(value)
        return values.pop()


def _compile_tokens(tokens, ignore_case):
    def is_relation(tokens):
        return len(tokens) == 3 and tokens[1] in Relation.VALID_CMP_OPERATORS


    if isstring(tokens):  # bool operator as string