Change syntax for multi-key list indexing
List instances are now dereferenced by listing each key-value in
separate brackets. Value can be enclosed either in single quotes or in
double quotes.
Change-Id: Iad72b1002d4655249ecd7bfc7109814b45c7b16b
diff --git a/src/grammars.hpp b/src/grammars.hpp
index fddd409..688394e 100644
--- a/src/grammars.hpp
+++ b/src/grammars.hpp
@@ -13,6 +13,7 @@
x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue";
+x3::rule<key_identifier_class, std::string> const key_identifier = "key_identifier";
x3::rule<node_identifier_class, std::string> const node_identifier = "node_identifier";
x3::rule<module_identifier_class, std::string> const module_identifier = "module_identifier";
x3::rule<listPrefix_class, std::string> const listPrefix = "listPrefix";
@@ -49,8 +50,20 @@
#pragma GCC diagnostic ignored "-Woverloaded-shift-op-parentheses"
#endif
+auto const key_identifier_def =
+ lexeme[
+ ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_(".")))
+ ];
+
+auto const quotedValue =
+ ('\'' > +(char_-'\'') > '\'') |
+ ('\"' > +(char_-'\"') > '\"');
+
+auto const number =
+ +x3::digit;
+
auto const keyValue_def =
- lexeme[+alnum > '=' > +alnum];
+ lexeme['[' > key_identifier > '=' > (quotedValue | number) > ']'];
auto const module_identifier_def =
lexeme[
@@ -63,11 +76,11 @@
];
auto const listPrefix_def =
- node_identifier >> '[';
+ node_identifier >> &char_('[');
// even though we don't allow no keys to be supplied, the star allows me to check which keys are missing
auto const listSuffix_def =
- *keyValue > ']';
+ *keyValue;
auto const listElement_def =
listPrefix > listSuffix;
@@ -171,6 +184,7 @@
#endif
BOOST_SPIRIT_DEFINE(keyValue)
+BOOST_SPIRIT_DEFINE(key_identifier)
BOOST_SPIRIT_DEFINE(node_identifier)
BOOST_SPIRIT_DEFINE(module_identifier)
BOOST_SPIRIT_DEFINE(listPrefix)