<commit_before>from .compile_selector_part import compile_selector_part
import pg

def print_props_and_tags(current_pseudo_element, prop_to_set, tags_to_set):
  ret = ''

  if len(prop_to_set):
      ret += 'current.styles[' + current_pseudo_element + '] = ' +\
          'current.styles[' + current_pseudo_element + '] || ' +\
          pg.format(prop_to_set) + ';\n'
      prop_to_set.clear()

  if len(tags_to_set):
      ret += 'current.tags = current.tags || ' +\
          pg.format(tags_to_set) + ';\n'
      tags_to_set.clear()

  return ret

def compile_statement(statement, stat):
    ret = ''
    object_selector = statement['selectors']

    ret += 'if (' + compile_selector_part(object_selector, stat) + ')\nthen\n'
# TODO: link

    # set current.pseudo_element_ind
    if object_selector['pseudo_element'] == '*':
        current_pseudo_element = 'i'
        ret += 'for i in 1..array_upper(current.pseudo_elements, 1) loop\n'
    else:
        current_pseudo_element = str(stat['pseudo_elements'].index(object_selector['pseudo_element']))
    ret += 'current.pseudo_element_ind = ' + current_pseudo_element + ';\n'

    prop_to_set = {}
    tags_to_set = {}

# TODO: prop_type
    for prop in statement['properties']:
        if prop['assignment_type'] == 'P':
            if prop['value_type'] == 0:
                prop_to_set[prop['key']] = prop['value']

                if not prop['key'] in stat['properties_values']:
                    stat['properties_values'][prop['key']] = set()

                stat['properties_values'][prop['key']].add(prop['value'])

        elif prop['assignment_type'] == 'T':
            if prop['value_type'] == 0:
                tags_to_set[prop['key']] = prop['value']

    ret += print_props_and_tags(current_pseudo_element, prop_to_set, tags_to_set)

    if object_selector['pseudo_element'] == '*':
        ret += 'end loop;\n'

# create_pseudo_element
    if not 'create_pseudo_element' in object_selector or \
        object_selector['create_pseudo_element']:<commit_msg>python-reimpl: compile statement: fix pseudo element (arrays start with 1)<commit_after>from .compile_selector_part import compile_selector_part
import pg

def print_props_and_tags(current_pseudo_element, prop_to_set, tags_to_set):
  ret = ''

  if len(prop_to_set):
      ret += 'current.styles[' + current_pseudo_element + '] = ' +\
          'current.styles[' + current_pseudo_element + '] || ' +\
          pg.format(prop_to_set) + ';\n'
      prop_to_set.clear()

  if len(tags_to_set):
      ret += 'current.tags = current.tags || ' +\
          pg.format(tags_to_set) + ';\n'
      tags_to_set.clear()

  return ret

def compile_statement(statement, stat):
    ret = ''
    object_selector = statement['selectors']

    ret += 'if (' + compile_selector_part(object_selector, stat) + ')\nthen\n'
# TODO: link

    # set current.pseudo_element_ind
    if object_selector['pseudo_element'] == '*':
        current_pseudo_element = 'i'
        ret += 'for i in 1..array_upper(current.pseudo_elements, 1) loop\n'
    else:
        current_pseudo_element = str(stat['pseudo_elements'].index(object_selector['pseudo_element']) + 1)
    ret += 'current.pseudo_element_ind = ' + current_pseudo_element + ';\n'

    prop_to_set = {}
    tags_to_set = {}

# TODO: prop_type
    for prop in statement['properties']:
        if prop['assignment_type'] == 'P':
            if prop['value_type'] == 0:
                prop_to_set[prop['key']] = prop['value']

                if not prop['key'] in stat['properties_values']:
                    stat['properties_values'][prop['key']] = set()

                stat['properties_values'][prop['key']].add(prop['value'])

        elif prop['assignment_type'] == 'T':
            if prop['value_type'] == 0:
                tags_to_set[prop['key']] = prop['value']

    ret += print_props_and_tags(current_pseudo_element, prop_to_set, tags_to_set)

    if object_selector['pseudo_element'] == '*':
        ret += 'end loop;\n'

# create_pseudo_element
    if not 'create_pseudo_element' in object_selector or \
        object_selector['create_pseudo_element']:
{'fraction_non_alphanumeric': 0.1453136352627755, 'fraction_numerical': 0.002421893921046258, 'mean_word_length': 3.150753768844221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4013241', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1330, 'n_words': 235}