Example #1
0
def lex(q):
    keywords = ["attr"]
    keywords.extend(SEARCH_KEYWORDS)
    keywords.extend(BOOLEAN_OPERATORS.keys())
    keywords.extend(UNARY_BOOLEAN_OPERATORS.keys())
    keywords.extend(INFIX_OPERATORS.keys())
    keywords.extend(("(", ")"))
    keywords.sort(key=len, reverse=True)
    results = []
    while q:
        q = q.lstrip()
        for keyword in keywords:
            if q.startswith(keyword):
                if _unquoted_string_re.match(keyword):
                    if not _separator_re.match(consume(keyword, q)):
                        continue
                results.append(keyword)
                q = consume(keyword, q)
                break
        else:
            result, q = lex_string(q)
            results.append(result)
    return results
Example #2
0
def lex(q):
    keywords = ["attr"]
    keywords.extend(SEARCH_KEYWORDS)
    keywords.extend(BOOLEAN_OPERATORS.keys())
    keywords.extend(UNARY_BOOLEAN_OPERATORS.keys())
    keywords.extend(INFIX_OPERATORS.keys())
    keywords.extend(("(", ")"))
    keywords.sort(key=len, reverse=True)
    results = []
    while q:
        q = q.lstrip()
        for keyword in keywords:
            if q.startswith(keyword):
                if _unquoted_string_re.match(keyword):
                    if not _separator_re.match(consume(keyword, q)):
                        continue
                results.append(keyword)
                q = consume(keyword, q)
                break
        else:
            result, q = lex_string(q)
            results.append(result)
    return results