Skip to content
This repository was archived by the owner on Feb 29, 2020. It is now read-only.

asottile-archive/dumbconf

Repository files navigation

DEPRECATED

This never really got finished, but was a fun little project for me to learn about tokenizing / parsing. I think a better solution now would be to implement a json5 parser instead.


Build Status Azure DevOps coverage

dumbconf - A WIP spec

Goal: define a "simple" configuration language (yet another) which is easy to write but does not give too much freedom. The configuration language must support a json-like syntax but also be able to load "prettier" structures similar to yaml. The language will be strict in its indentation and form to encourage uniformity.

The python implementation intends to provide the following things:

  • A load, loads, dump, dumps interface similar to json
  • The ability to retrieve a mutable ast representation which can be used for automatic refactoring of dumbconf files

Encoding

dumbconf files are invariantly UTF-8 encoded.

Comments

  • Empty lines are ignored
  • Comments start with a # character followed by a space and a comment
  • Inline comments must have a whitespace character before and after the #
  • (Suggested) It is suggested to put two space characters before the # as in PEP8
# A comment
true  # an inline comment

Primitives

Quoted strings

  • Both single and quoted strings are appropriate
  • Escape sequences in quoted strings will be interpreted according to python rules.
['foo', "foo", 'foo\'bar', "foo\"bar"]

Bare word keys

  • Maps may contain bare words keys
  • Keys which would otherwise be interpreted as another value must be quoted
{
    im_a_bare_word_key: 'value',
    'true': 'indeed, my key needed quoting',
}

Boolean

  • There are 2 tokens interpreted as booleans
[true, false]

Integers

There are four supported forms of integers:

[
    # hexadecimal
    0xdeadBEEF,
    # binary
    0b10101010,
    # octal
    0o755,
    # decimal
    -1234,
]

Floats

[
    # integers with exponents
    0e5, 1e-10,
    # numbers with a decimal point
    0., .5, 1.5,
    # numbers with a decimal point and exponent
    6.02E23,
]

null

  • There is one toke interpreted as null
[null]

Lists

Inline list

[]
['value']
['value', 'value', 'value']

Multiline list

  • Trailing commas are required
[
    'value',
    'value',
    'value',
]
  • Closing bracket matches starting indentation
  • For instance in a mapping type:
{
    key: [
        'value',
        'value',
        'value',
    ],
}

Hybrid multiline list

  • Values may appear inline (to improve readability)
[
    'value', 'value', 'value',
    'value', 'value',
]

Maps

  • Keys may be any of the primitive types

Inline map

{}
{key: 'value'}
{key: 'value', other_key: 'other value'}

Multiline map

  • Trailing commas are required
{
    key1: 'value1',
    key2: 'value2',
    key3: 'value3',
}
  • Closing bracket matches starting indentation
  • For instance in a mapping type:
{
    key: {
        key1: 'value1',
        key2: 'value2',
        key3: 'value3',
    },
}

Hybrid multiline map

  • Pairs may appear inline (to improve readability)
{
    key1: 'value1', key2: 'value2',
    key3: 'value3', key4: 'value4',
}

Top level maps

  • A top level map may omit brackets and commas
True: ['I', 'am', 'a', 'map']
False: ['I', 'have', 'brackets']

Complete syntax example:

# A comment followed by a blank line

scalars: {
    bool_values: [true, false],  # An inline comment
    null_value: [null],
    strings: ["double quoted", 'single quoted', 'unicode: \u2603'],
    ints: [0xDEADBEEF, 0b101010, 0o755, 0, 1234],
    floats: [1., 1e5, .142857, 6.02e23],
}

'a json style map': {"key": "value", "other key": "other value"}
'a json style list': ["i", "am", "a", "list"]

'a python style map': {'key': 'value', 'other key': 'other value'}
'a python style list': ['i', 'am', 'a', 'list']

'a bare words map': {key: 'value', other_key: 'other value'}

About

A dumb configuration language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages