def _do_table(table_element): elements = table_element.sub_elements # Our iterator index i = float('-inf') def next_key(): return t.find_following(elements, t.predicates.non_metadata, i) def next_assignment(): return t.find_following(elements, t.predicates.op_assignment, next_key()) def next_value(): return t.find_following(elements, t.predicates.non_metadata, next_assignment()) while next_key() >= 0: del elements[next_key() + 1:next_assignment()] del elements[next_assignment() + 1:next_value()] elements.insert(next_assignment(), element_factory.create_whitespace_element(1)) elements.insert(next_value(), element_factory.create_whitespace_element(1)) i = t.find_following(elements, t.predicates.newline, i)
def _do_table(table_element): elements = table_element.sub_elements # Our iterator index i = float('-inf') def next_key(): return t.find_following(elements, t.predicates.non_metadata, i) def next_assignment(): return t.find_following(elements, t.predicates.op_assignment, next_key()) def next_value(): return t.find_following(elements, t.predicates.non_metadata, next_assignment()) while next_key() >= 0: del elements[next_key()+1:next_assignment()] del elements[next_assignment()+1:next_value()] elements.insert(next_assignment(), element_factory.create_whitespace_element(1)) elements.insert(next_value(), element_factory.create_whitespace_element(1)) i = t.find_following(elements, t.predicates.newline, i)
def table_entries_should_be_uniformly_indented(toml_file_elements): """ Rule: Nth-level table sections should be indented by (N-1)*2 spaces """ elements = toml_file_elements[:] for (i, e) in enumerate(elements): if t.predicates.table_header(e): table = elements[t.find_following(elements, t.predicates.table, i)] _do_table_header(e) _do_table(table, len(e.names)) return elements
def next_non_metadata(): return t.find_following(elements, t.predicates.non_metadata, i)
def first_indent(): return t.find_following(elements, t.predicates.whitespace, i)
def line_value_index(): # Returns index of value element in the line key_index = t.find_following(line_elements, t.predicates.non_metadata) return t.find_following(line_elements, t.predicates.non_metadata, key_index)
def next_comment(): return t.find_following(table_elements, t.predicates.comment, i)
def next_newline(): return t.find_following(table_elements, t.predicates.newline, i)
def next_assignment(): return t.find_following(elements, t.predicates.op_assignment, next_key())
def next_value(): return t.find_following(elements, t.predicates.non_metadata, next_assignment())
def next_newline(): return t.find_following(elements, t.predicates.newline, next_non_metadata())