Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thuetter
Copy link
Collaborator

fixed parser; removed parser validation function; added exceptions for parser; adjusted tests accordingly

@thuetter thuetter linked an issue May 17, 2023 that may be closed by this pull request
@thuetter thuetter requested a review from mateuszpawlik May 17, 2023 13:23
Copy link
Collaborator

@mateuszpawlik mateuszpawlik left a 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.");
Copy link
Collaborator

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.
Copy link
Collaborator

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.
Copy link
Collaborator

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.


/// Convert vector of int values to is string representation.
///
/// TODO: Move this method to some util.
Copy link
Collaborator

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 " <<
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::cerr << "Validation test failed: only identified " <<
std::cerr << "Validation test failed: correctly caught " <<

This is less confusing to me.

@thuetter
Copy link
Collaborator Author

Thanks for your comments. They are all addressed in the new commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Endless loop in BracketNotationParser
2 participants