<commit_before>from .parse_string import parse_string
from .parse_eval import parse_eval
from .ParseError import *
import re

def parse_condition(to_parse):
    condition = { 'op': '', 'value_type': 'value' }

    if to_parse.match('\s*!'):
        condition['op'] += '! '

    r = parse_string(to_parse)
    if r:
        condition['key'] = r

    elif to_parse.match('eval\s*\(\s*'):
        value = parse_eval(to_parse)

        if not to_parse.match('\s*\)\s*\]'):
            raise ParseError(to_parse, 'Error parsing eval statement')

        condition['op'] = 'eval'
        condition['key'] = value

        return condition

    elif to_parse.match('\s*([a-zA-Z_0-9\\-\.:]+)'):
        condition['key'] = to_parse.match_group(1)

    elif to_parse.match('\s*\/([^\]]*)\/(i?)\]'):
        condition['op'] += 'key_regexp'
        condition['key'] = to_parse.match_group(1)

        if to_parse.match_group(2) == 'i':
            condition['op'] += '_case'

        return condition

    else:
        raise ParseError(to_parse, 'parse condition: Can\'t parse condition key')

    if to_parse.match('\s*(=~|!=|!~|<=|>=|<|>|\^=|\$=|\*=|~=|@=|=)\s*'):
        condition['op'] += to_parse.match_group(1)

    elif to_parse.match('\?\]'):
        condition['value'] = 'yes;true;1'
        condition['op'] += '@='
        return condition

    elif to_parse.match('\?\!\]'):
        condition['value'] = 'no;false;0;'
        condition['op'] += '@='
        return condition

    else:
        condition['op'] += 'has_tag'

    r = parse_string(to_parse)
    if r:
        condition['value'] = r

        if not to_parse.match('\]'):
            raise ParseError(to_parse, 'parse condition: expecting ]')

    elif to_parse.match('eval\s*\(\s*'):
        r = parse_string(to_parse)<commit_msg>Parse Condition: Bugfix, parsing 'has_tag' conditions<commit_after>from .parse_string import parse_string
from .parse_eval import parse_eval
from .ParseError import *
import re

def parse_condition(to_parse):
    condition = { 'op': '', 'value_type': 'value' }

    if to_parse.match('\s*!'):
        condition['op'] += '! '

    r = parse_string(to_parse)
    if r:
        condition['key'] = r

    elif to_parse.match('eval\s*\(\s*'):
        value = parse_eval(to_parse)

        if not to_parse.match('\s*\)\s*\]'):
            raise ParseError(to_parse, 'Error parsing eval statement')

        condition['op'] = 'eval'
        condition['key'] = value

        return condition

    elif to_parse.match('\s*([a-zA-Z_0-9\\-\.:]+)'):
        condition['key'] = to_parse.match_group(1)

    elif to_parse.match('\s*\/([^\]]*)\/(i?)\]'):
        condition['op'] += 'key_regexp'
        condition['key'] = to_parse.match_group(1)

        if to_parse.match_group(2) == 'i':
            condition['op'] += '_case'

        return condition

    else:
        raise ParseError(to_parse, 'parse condition: Can\'t parse condition key')

    if to_parse.match('\s*(=~|!=|!~|<=|>=|<|>|\^=|\$=|\*=|~=|@=|=)\s*'):
        condition['op'] += to_parse.match_group(1)

    elif to_parse.match('\?\]'):
        condition['value'] = 'yes;true;1'
        condition['op'] += '@='
        return condition

    elif to_parse.match('\?\!\]'):
        condition['value'] = 'no;false;0;'
        condition['op'] += '@='
        return condition

    elif to_parse.match('\s*\]'):
        condition['op'] += 'has_tag'
        return condition

    else:
        raise ParseError(to_parse, 'parse condition: Can\'t parse condition')

    r = parse_string(to_parse)
    if r:
        condition['value'] = r

        if not to_parse.match('\]'):
            raise ParseError(to_parse, 'parse condition: expecting ]')

    elif to_parse.match('eval\s*\(\s*'):
        r = parse_string(to_parse)
{'fraction_non_alphanumeric': 0.1975570897503983, 'fraction_numerical': 0.004248539564524694, 'mean_word_length': 2.5876190476190475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4719852', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1237, 'n_words': 239}