Skip to content

Commit

Permalink
Improve exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph-Edwards committed May 17, 2024
1 parent 457f944 commit 9fc040b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/libsemigroups/aho-corasick.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
// any given node is contained within. This could be updated easily when adding
// new rules, but more care would be needed when removing rules.
// TODO(0) change names from set_X and get_X to set(val) and get()
// TODO(2) add something that gets a ranges element to find all terminal nodes.
namespace libsemigroups {

//! \brief For an implementation of the Aho-Corasick algorithm
Expand Down
22 changes: 11 additions & 11 deletions include/libsemigroups/aho-corasick.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ namespace libsemigroups {
AhoCorasick::index_type AhoCorasick::add_word(Iterator first, Iterator last) {
auto last_index = traverse_trie(first, last);
if (last_index != UNDEFINED && _all_nodes[last_index].is_terminal()) {
LIBSEMIGROUPS_EXCEPTION(
"word already exists in trie. Cannot add ({}, {}) since it already "
"corresponds to a terminal node",
*first,
*last);
LIBSEMIGROUPS_EXCEPTION("the word {} given by the arguments [first, "
"last) already belongs to the trie",
word_type(first, last));
// Look in presentations and do one thing for chars and one thing for
// letter type.
}
return add_word_no_checks(first, last);
}
Expand Down Expand Up @@ -56,16 +56,16 @@ namespace libsemigroups {
AhoCorasick::index_type AhoCorasick::rm_word(Iterator first, Iterator last) {
auto last_index = traverse_trie(first, last);
if (last_index == UNDEFINED) {
LIBSEMIGROUPS_EXCEPTION("cannot remove ({}, {}), as it does not "
LIBSEMIGROUPS_EXCEPTION("cannot remove the word {} given by the "
"arguments (first, last], as it does not "
"correspond to a node in the trie",
*first,
*last);
word_type(first, last));
}
if (!_all_nodes[last_index].is_terminal()) {
LIBSEMIGROUPS_EXCEPTION("cannot remove ({}, {}), as it does not "
LIBSEMIGROUPS_EXCEPTION("cannot remove the word {} given by the "
"arguments (first, last], as it does not "
"correspond to a terminal node in the trie",
*first,
*last);
word_type(first, last));
}
return rm_word_no_checks(first, last);
}
Expand Down

0 comments on commit 9fc040b

Please sign in to comment.