Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
 def next_non_metadata():
     return t.find_following(elements, t.predicates.non_metadata, i)
Esempio n. 6
0
 def first_indent():
     return t.find_following(elements, t.predicates.whitespace, i)
Esempio n. 7
0
 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)
Esempio n. 8
0
 def next_comment():
     return t.find_following(table_elements, t.predicates.comment, i)
Esempio n. 9
0
 def next_newline():
     return t.find_following(table_elements, t.predicates.newline, i)
Esempio n. 10
0
 def next_assignment():
     return t.find_following(elements, t.predicates.op_assignment, next_key())
Esempio n. 11
0
 def next_assignment():
     return t.find_following(elements, t.predicates.op_assignment,
                             next_key())
Esempio n. 12
0
 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)
Esempio n. 13
0
 def first_indent():
     return t.find_following(elements, t.predicates.whitespace, i)
Esempio n. 14
0
 def next_comment():
     return t.find_following(table_elements, t.predicates.comment, i)
Esempio n. 15
0
 def next_newline():
     return t.find_following(table_elements, t.predicates.newline, i)
Esempio n. 16
0
 def next_value():
     return t.find_following(elements, t.predicates.non_metadata,
                             next_assignment())
Esempio n. 17
0
 def next_newline():
     return t.find_following(elements, t.predicates.newline, next_non_metadata())
Esempio n. 18
0
 def next_newline():
     return t.find_following(elements, t.predicates.newline,
                             next_non_metadata())
Esempio n. 19
0
 def next_non_metadata():
     return t.find_following(elements, t.predicates.non_metadata, i)
Esempio n. 20
0
 def next_value():
     return t.find_following(elements, t.predicates.non_metadata, next_assignment())