automatic whitespace for keyval

This commit is contained in:
Arpad Ryszka 2017-10-29 00:21:32 +02:00
parent 304f11f224
commit 89a5e3ae0d
3 changed files with 32 additions and 39 deletions

View File

@ -74,6 +74,7 @@ func (d *choiceDefinition) init(r *registry) error {
}
for _, e := range d.elements {
// TODO: handle undefined reference
d.cbuilder.elements = append(d.cbuilder.elements, r.definitions[e].builder())
}

View File

@ -1,27 +1,21 @@
ws:alias = [ \b\f\r\t\v];
wsnl:alias = ws | "\n";
whitespace:ws = [ \b\f\r\t\v];
comment-line:alias = "#" [^\n]*;
comment = comment-line (ws* "\n" ws* comment-line)*;
comment = comment-line ("\n" comment-line)*;
wsc:alias = ws | comment-line;
wsnlc:alias = wsnl | comment-line;
quoted:alias:nows = "\"" ([^\\"] | "\\" .)* "\"";
word:alias:nows = ([^\\"\n=#.\[\] \b\f\r\t\v] | "\\" .)+;
symbol = word+ | quoted;
quoted:alias = "\"" ([^\\"] | "\\" .)* "\"";
symbol-non-ws:alias = ([^\\"\n=#.\[\] \b\f\r\t\v] | "\\" .)+;
symbol = symbol-non-ws (ws* symbol-non-ws)* | quoted;
key-form:alias = symbol (ws* "." ws* symbol)*;
key-form:alias = symbol | symbol ("." symbol)+;
key = key-form;
group-key = (comment "\n" ws*)? "[" ws* key-form ws* "]";
value-chars:alias = ([^\\"\n=# \b\f\r\t\v] | "\\" .)+;
value = value-chars (ws* value-chars)* | quoted;
key-val = (comment "\n" ws*)? (key | key? ws* "=" ws* value?);
group-key-form:alias = "[" key-form "]";
group-key = (comment "\n")? group-key-form | group-key-form;
value-chars:alias:nows = ([^\\"\n=# \b\f\r\t\v] | "\\" .)+;
value = value-chars+ | quoted;
key-val = (comment "\n")? (key | key? "=" value?) comment-line?;
entry:alias = group-key | key-val;
doc:root = (entry (ws* comment-line)? | wsnlc)*;
single-entry = (entry (ws* comment-line)?
| wsnlc* entry (ws* comment-line)?)
[];
doc:root = (entry | comment-line | "\n")*;

View File

@ -84,45 +84,43 @@ func TestKeyVal(t *testing.T) {
}},
}, {
title: "key value pairs with a comment at the end of line",
text: `
a key = a value # a comment
another key = another value # another comment
`,
text: "a key = a value # a comment\n" +
"another key = another value # another comment",
nodes: []*Node{{
Name: "key-val",
From: 11,
To: 32,
From: 0,
To: 39,
Nodes: []*Node{{
Name: "key",
From: 11,
To: 16,
From: 0,
To: 5,
Nodes: []*Node{{
Name: "symbol",
From: 11,
To: 16,
From: 0,
To: 5,
}},
}, {
Name: "value",
From: 25,
To: 32,
From: 14,
To: 21,
}},
}, {
Name: "key-val",
From: 61,
To: 88,
From: 40,
To: 85,
Nodes: []*Node{{
Name: "key",
From: 61,
To: 72,
From: 40,
To: 51,
Nodes: []*Node{{
Name: "symbol",
From: 61,
To: 72,
From: 40,
To: 51,
}},
}, {
Name: "value",
From: 75,
To: 88,
From: 54,
To: 67,
}},
}},
}, {