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