-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fix for Issue #10: Endless loop in BracketNotationParser bug #28
base: master
Are you sure you want to change the base?
Conversation
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.
Only minor comments from my side. I followed the parsing logic but didn't verify carefully.
@@ -34,40 +34,54 @@ node::Node<Label> BracketNotationParser<Label>::parse_single( | |||
|
|||
std::vector<std::string> tokens = get_tokens(tree_string); | |||
|
|||
if (tree_string.size() < 2) { | |||
throw std::runtime_error("PARSER-ERROR: Tree string needs at least two characters."); |
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.
I would use std::invalid_argument
.
// Tokenize the input string - get iterator over tokens. | ||
auto tokens_begin = tokens.begin(); | ||
auto tokens_end = tokens.end(); | ||
|
||
// Deal with the root node separately. | ||
++tokens_begin; // Advance tokens to label. | ||
std::string match_str = *tokens_begin; | ||
if (match_str == kLeftBracket || match_str == kRightBracket) { // Root has an empty label. | ||
if (match_str == kLeftBracket) { // Root has an empty label. | ||
match_str = ""; | ||
// Do not advance tokens - we're already at kLeftBracket or kRightBracket. |
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.
This comment seems obsolete.
--open_nodes; | ||
match_str = ""; | ||
++tokens_begin; // Advance tokens. | ||
// Do not advance tokens - we're already at kLeftBracket or kRightBracket. |
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.
This comment doesn't fit here.
test/common/to_string_converters.h
Outdated
|
||
/// Convert vector of int values to is string representation. | ||
/// | ||
/// TODO: Move this method to some util. |
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.
It is a string converter so it fits here, no?
} | ||
|
||
if (test_cases != identified_cases) { | ||
std::cerr << "Validation test failed: only identified " << |
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.
std::cerr << "Validation test failed: only identified " << | |
std::cerr << "Validation test failed: correctly caught " << |
This is less confusing to me.
Thanks for your comments. They are all addressed in the new commit. |
fixed parser; removed parser validation function; added exceptions for parser; adjusted tests accordingly