Program <- Move (S* Move)*;
Move <- "R"/"U"/"F"/"L"/"D"/"B";
S <- " "/"\n";
I expected, that this grammar would be able to fully parse the following input String:
input = "R\nB";
However the returned MemoTable only contained matches for "R" and "B", but not for the entire sequence "R\nB".
I noticed that MetaGrammar instantiates a CharSeq object with the following argument for parameter str:
"\nn";
Notice, that there is an extra 'n' character after '\n'.
I suspect, that there is a problem in method unescapeString of class MetaGrammar.
It looks like, method unescapeString only consumes the backslash, but not the character that follows after the backslash.
I was able to get the desired result, by adding the line "i++; // consume escaped character" to method unescapeString.
private static String unescapeString(String str) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == '\\') {
if (i == str.length() - 1) {
// Should not happen
throw new IllegalArgumentException("Got backslash at end of quoted string");
}
buf.append(unescapeChar(str.substring(i, i + 2)));
i++; // consume escaped character
} else {
buf.append(c);
}
}
return buf.toString();
}
I have made the following grammar description:
I expected, that this grammar would be able to fully parse the following input String:
However the returned MemoTable only contained matches for "R" and "B", but not for the entire sequence "R\nB".
I noticed that MetaGrammar instantiates a CharSeq object with the following argument for parameter str:
Notice, that there is an extra 'n' character after '\n'.
I suspect, that there is a problem in method unescapeString of class MetaGrammar. It looks like, method unescapeString only consumes the backslash, but not the character that follows after the backslash.
I was able to get the desired result, by adding the line "i++; // consume escaped character" to method unescapeString.