Closed wrandelshofer closed 4 years ago
I have made the following grammar description:
Program <- "R"/"U"/"F"/"L"/"D"/"B";
I expected, that this grammar would be able to parse the following input String:
input = "B";
However the returned MemoTable did not match any clause.
The MemoTable did match a clause, when I added an additional character to the String, for example a space character.
input = "B ";
Similarly, the following input only found one matching clause, but I expected two:
input = "RB";
Again, adding another character at the end of the input String helped.
input = "RB ";
I suspect, that there is a problem in method match of class CharSeq.
@Override public Match match(MatchDirection matchDirection, MemoTable memoTable, MemoKey memoKey, String input) { if (memoKey.startPos < input.length() - str.length() && input.regionMatches(ignoreCase, memoKey.startPos, str, 0, str.length())) { // Terminals are not memoized (i.e. don't look in the memo table) return new Match(memoKey, /* firstMatchingSubClauseIdx = */ 0, /* len = */ str.length(), Match.NO_SUBCLAUSE_MATCHES); } return null; }
By changing the if-condition to <= instead of <, I can achieve the desired results.
if (memoKey.startPos <= input.length() - str.length()
Good find! Thank you, fixed.
I have made the following grammar description:
I expected, that this grammar would be able to parse the following input String:
However the returned MemoTable did not match any clause.
The MemoTable did match a clause, when I added an additional character to the String, for example a space character.
Similarly, the following input only found one matching clause, but I expected two:
Again, adding another character at the end of the input String helped.
I suspect, that there is a problem in method match of class CharSeq.
By changing the if-condition to <= instead of <, I can achieve the desired results.