-
-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic support for lists in config.yaml #342
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,40 @@ namespace Configuration { | |
std::vector<const char*> _path; | ||
|
||
public: | ||
void enterSectionList(const char* name, BuilderBase<Configurable>* builder, std::vector<Configurable*>& inst) override { | ||
int entryIndent = _parser.token_.indent_; | ||
// check if list | ||
_parser.Tokenize(); | ||
_parser.token_.state = TokenState::Held; | ||
if (!_parser.token_.is_list_) { | ||
#ifdef DEBUG_CHATTY_YAML_PARSER | ||
log_debug("----------- Entered single item under " << name << " at indent " << _parser.token_.indent_); | ||
#endif | ||
inst.push_back(builder->create()); | ||
this->enterSectionItem(name, inst.back(), entryIndent); | ||
} | ||
|
||
while (_parser.token_.is_list_) { | ||
_parser.token_.is_list_ = false; | ||
entryIndent = _parser.token_.indent_; | ||
_parser.token_.indent_ += 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks a bit fishy. I could introduce another member on Token as well, but it would basically do the same, I assume. |
||
#ifdef DEBUG_CHATTY_YAML_PARSER | ||
log_debug("----------- Entered list item under " << name << " at indent " << _parser.token_.indent_); | ||
#endif | ||
inst.push_back(builder->create()); | ||
this->enterSectionItem(name, inst.back(), entryIndent); | ||
} | ||
} | ||
|
||
void enterSection(const char* name, Configuration::Configurable* section) override { | ||
this->enterSectionItem(name, section, _parser.token_.indent_); | ||
} | ||
|
||
void enterSectionItem(const char* name, Configuration::Configurable* section, int entryIndent) { | ||
_path.push_back(name); // For error handling | ||
|
||
// On entry, the token is for the section that invoked us. | ||
// We will handle following nodes with indents greater than entryIndent | ||
int entryIndent = _parser.token_.indent_; | ||
#ifdef DEBUG_CHATTY_YAML_PARSER | ||
log_debug("Entered section " << name << " at indent " << entryIndent); | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,17 @@ namespace Configuration { | |
goto parseAgain; | ||
|
||
default: | ||
if (IsListItem()) { | ||
token_.is_list_ = true; | ||
Inc(); | ||
// skip expected whitespace. TODO: validate that it's indeed a whitespace | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason: It could also be a plain scalar (e.g. |
||
Inc(); | ||
|
||
#ifdef DEBUG_VERBOSE_YAML_TOKENIZER | ||
log_debug("List token"); | ||
#endif | ||
} | ||
|
||
if (!IsIdentifierChar()) { | ||
ParseError("Invalid character"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to make BuilderBase a non-inner class to be able to forward declare it in HandlerBase.h