Exemplo n.º 1
0
def parse_mappings(src):
    for _, src in parse_empty_mappings(src):
        yield {}, src
        return
    for (_, items, _), src in sequence(parse_left_curly_brace,
                                       parse_comma_separated_mappings,
                                       parse_right_curly_brace)(src):
        yield items, src
Exemplo n.º 2
0
def parse_comma_separated_sequence(src):
    for _, src in parse_empty_comma_separated_sequence(src):
        yield [], src
        return
    for (_, items, _), src in sequence(parse_left_square_brace,
                                       parse_comma_separated_list_elements,
                                       parse_right_square_brace)(src):
        yield items, src
Exemplo n.º 3
0
def parse_comma_separated_list_elements(src):
    for (element, _,
         elements), src in sequence(parse_list_element, parse_comma,
                                    parse_comma_separated_list_elements)(src):
        yield [element] + elements, src
        return
    for element, src in parse_list_element(src):
        yield [element], src
Exemplo n.º 4
0
def parse_comma_separated_mappings(src):
    for (mapping, _,
         mappings), src in sequence(parse_mapping, parse_comma,
                                    parse_comma_separated_mappings)(src):
        mapping.update(mappings)
        yield mapping, src
        return
    for mapping, src in parse_mapping(src):
        yield mapping, src
Exemplo n.º 5
0
def parse_dash_separated_sequence(src):
    for (_, element, _,
         elements), src in sequence(parse_spaced_dash, parse_list_element,
                                    parse_newline,
                                    parse_dash_separated_sequence)(src):
        yield [element] + elements, src
        return
    for element, src in parse_list_element(src):
        yield [element], src
Exemplo n.º 6
0
def parse_mapping(src):
    for (key, _, value), src in sequence(parse_key, parse_spaced_colon,
                                         parse_value)(src):
        yield {key: value}, src
Exemplo n.º 7
0
from utils_parser import parse_word, sequence, parse_key, parse_value

parse_left_curly_brace = parse_word("{")
parse_right_curly_brace = parse_word("}")
parse_empty_mappings = sequence(parse_left_curly_brace,
                                parse_right_curly_brace)


def parse_mappings(src):
    for _, src in parse_empty_mappings(src):
        yield {}, src
        return
    for (_, items, _), src in sequence(parse_left_curly_brace,
                                       parse_comma_separated_mappings,
                                       parse_right_curly_brace)(src):
        yield items, src


parse_spaced_colon = parse_word(": ")


def parse_mapping(src):
    for (key, _, value), src in sequence(parse_key, parse_spaced_colon,
                                         parse_value)(src):
        yield {key: value}, src


def parse_comma_separated_mappings(src):
    for (mapping, _,
         mappings), src in sequence(parse_mapping, parse_comma,
                                    parse_comma_separated_mappings)(src):
Exemplo n.º 8
0
        return
    for element, src in parse_list_element(src):
        yield [element], src


def parse_comma_separated_list_elements(src):
    for (element, _,
         elements), src in sequence(parse_list_element, parse_comma,
                                    parse_comma_separated_list_elements)(src):
        yield [element] + elements, src
        return
    for element, src in parse_list_element(src):
        yield [element], src


parse_empty_comma_separated_sequence = sequence(parse_left_square_brace,
                                                parse_right_square_brace)


def parse_comma_separated_sequence(src):
    for _, src in parse_empty_comma_separated_sequence(src):
        yield [], src
        return
    for (_, items, _), src in sequence(parse_left_square_brace,
                                       parse_comma_separated_list_elements,
                                       parse_right_square_brace)(src):
        yield items, src


def parse_sequence(src):
    for match in chain(parse_dash_separated_sequence(src),
                       parse_comma_separated_sequence(src)):