core: add single space where it is due
This commit is contained in:
@@ -13,7 +13,7 @@ You’re not alone: I also wish the code were documented.
|
|||||||
`cfg` has no comments, but let’s pretend we had `#` comments.
|
`cfg` has no comments, but let’s 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
|
# and then a value
|
||||||
my_list
|
my_list
|
||||||
- "value"
|
- "value"
|
||||||
@@ -31,7 +31,7 @@ my_section
|
|||||||
my_second_numer 23.0
|
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.
|
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,
|
It is a simple format, some might think it is too simple. It is, however,
|
||||||
|
6
cfg.h
6
cfg.h
@@ -427,7 +427,7 @@ string config_value_str(config_value* c, size_t indent) {
|
|||||||
for (j = 0; j < indent; j++) string_cappend(&res, " ");
|
for (j = 0; j < indent; j++) string_cappend(&res, " ");
|
||||||
string_cappend(&res, " - ");
|
string_cappend(&res, " - ");
|
||||||
val = list_nth_config_value(c->l, i);
|
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);
|
string_append(&res, &sub);
|
||||||
free_string(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();
|
*l =new_list_config_value();
|
||||||
|
|
||||||
while(true) {
|
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);
|
elem = config_parse_value(s, line, col, indent);
|
||||||
|
|
||||||
if (!elem.ok) return elem;
|
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;
|
consumed += elem.consumed;
|
||||||
s->str += 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);
|
if (!config_parse_line(s, line, col)) return config_value_parse_error("expected newline", *line, *col);
|
||||||
|
|
||||||
ind = config_parse_indent(s, col);
|
ind = config_parse_indent(s, col);
|
||||||
|
@@ -3,3 +3,9 @@ x 1.0
|
|||||||
hi
|
hi
|
||||||
name 1
|
name 1
|
||||||
val "hi"
|
val "hi"
|
||||||
|
list
|
||||||
|
- "value"
|
||||||
|
- -1
|
||||||
|
-
|
||||||
|
- "this"
|
||||||
|
- "obj"
|
||||||
|
Reference in New Issue
Block a user