core: add single space where it is due

This commit is contained in:
2020-04-26 18:13:47 +02:00
parent 21272b290f
commit a13a8cfa8c
3 changed files with 16 additions and 6 deletions

View File

@@ -13,11 +13,11 @@ Youre not alone: I also wish the code were documented.
`cfg` has no comments, but lets pretend we had `#` comments.
```
# lists start with a name, then an indent, then a hyphen,
# lists start with a name, then an indent, then a hyphen, a space,
# and then a value
my_list
-"value"
-12
- "value"
- 12
# strings are quoted
my_string "this is a string"
@@ -31,7 +31,7 @@ my_section
my_second_numer 23.0
```
Keys cannot contain spaces. Indents are always two spaces. There is no space
Keys cannot contain spaces. Indents are always two spaces. There is one space
between the hyphen and the value and an array. This is all.
It is a simple format, some might think it is too simple. It is, however,

8
cfg.h
View File

@@ -425,9 +425,9 @@ string config_value_str(config_value* c, size_t indent) {
for (i = 0; i < c->l->len; i++) {
string_cappend(&res, "\n");
for (j = 0; j < indent; j++) string_cappend(&res, " ");
string_cappend(&res, " -");
string_cappend(&res, " - ");
val = list_nth_config_value(c->l, i);
sub = config_value_str(&val, 0);
sub = config_value_str(&val, indent+2);
string_append(&res, &sub);
free_string(sub);
}
@@ -571,6 +571,9 @@ parsed_value config_parse_list(string* s, size_t* line, size_t* col, size_t inde
*l =new_list_config_value();
while(true) {
if (s->str[0] != ' ') return config_value_parse_error("expected space to start list element", *line, *col);
s->str++;
consumed += 1;
elem = config_parse_value(s, line, col, indent);
if (!elem.ok) return elem;
@@ -579,6 +582,7 @@ parsed_value config_parse_list(string* s, size_t* line, size_t* col, size_t inde
consumed += elem.consumed;
s->str += elem.consumed;
if (s->str[0] == '\0') break;
if (!config_parse_line(s, line, col)) return config_value_parse_error("expected newline", *line, *col);
ind = config_parse_indent(s, col);

View File

@@ -3,3 +3,9 @@ x 1.0
hi
name 1
val "hi"
list
- "value"
- -1
-
- "this"
- "obj"