Exemplo n.º 1
0
def parse_statement(source: Source) -> StatementType:
    if source.seek('#'):
        return parse_line_comment(source)

    if source.seek('['):
        return parse_table(source)

    kv_entry = parse_kv_entry(source)
    return kv_entry
Exemplo n.º 2
0
def parse_keyword(source: Source) -> str:
    if source.seek('"'):
        return _parse_basic_string(source)

    if source.seek('\''):
        return _parse_literal_string(source)

    match = source.consume_regex(KEYWORD_REGEX)
    if not match:
        raise DoesNotMatch()

    return source.last_consumed
Exemplo n.º 3
0
def parse_value(source: Source) -> ValueType:
    boolean_match = source.consume_regex(re.compile(r'(?P<res>(true)|(false))'))
    if boolean_match:
        return source.last_consumed == 'true'

    if source.seek('"""'):
        return _parse_multiline_string(source)

    if source.seek('"'):
        return _parse_basic_string(source)

    if source.seek('\'\'\''):
        return _parse_multiline_literal_string(source)

    if source.seek('\''):
        return _parse_literal_string(source)

    # datetime_match = source.consume_regex(DATETIME_REGEX)
    # if datetime_match:
    #     return _parse_datetime(source.last_consumed)

    number_match = source.consume_regex(NUMBER_REGEX)
    if number_match:
        return _parse_number(source.last_consumed)

    if source.seek('['):
        return _parse_array(source)

    if source.seek('{'):
        return _parse_inline_table(source)

    raise DoesNotMatch('Cannot find valid TOML value in string {text}'
                       .format(text=source._text[:100]))