This is a multi-part message in MIME format.
--------------020406070703070401060005
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
One way to get ParseException messages to identify keyword tokens with
a <...> string:
1. Change the token expression to be something other than a simple
string, such as changing from:
<IF: "if">
to:
<IF: "i" "f">
or to:
<IF: "if" | "if">
The result of this should be that after javacc is run,
PARSERNAMEConstants.tokenImage contains "<IF>" (instead of "\"if\"").
2. Change ParseException.java to combine the
PARSERNAMEConstants.tokenImage[tok.kind] for the token with the
add_escapes(tok.image) (instead of just add_escapes(tok.image)).
For example, attached changes produce <"if"=IF> (instead of "if").
Hope this helps!
Cesare Zecca wrote:
> Exception in thread "main"
> ParseException: Encountered "if" at line 1, column 5.
> Was expecting one of:
> <PAR_OPEN> ...
> <NUMBER_LITERAL> ...
> "-" ...
> <GROUP_ID> ...
>
> Anyway, the diagnostic does not mention at all that... "if" is a
> reserved keyword.
--------------020406070703070401060005
Content-Type: text/plain;
name="ParseException.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ParseException.patch"
--- old/ParseException.java
+++ new/ParseException.java
@[EMAIL PROTECTED]
-110,7 +110,7 @[EMAIL PROTECTED]
}
expected.append(eol).append(" ");
}
- String retval = "Encountered \"";
+ String retval = "Encountered ";
Token tok = currentToken.next;
for (int i = 0; i < maxSize; i++) {
if (i != 0) retval += " ";
@[EMAIL PROTECTED]
-118,10 +118,15 @[EMAIL PROTECTED]
retval += tokenImage[0];
break;
}
- retval += add_escapes(tok.image);
+ String kindImage = tokenImage[tok.kind];
+ if (!kindImage.startsWith("<")) {
+ retval += kindImage;
+ } else {
+ retval +=
"<\""+add_escapes(tok.image)+"\"="+kindImage.substring(1);
+ }
tok = tok.next;
}
- retval += "\" at line " + currentToken.next.beginLine + ", column " +
currentToken.next.beginColumn;
+ retval += " at line " + currentToken.next.beginLine + ", column " +
currentToken.next.beginColumn;
retval += "." + eol;
if (expectedTokenSequences.length == 1) {
retval += "Was expecting:" + eol + " ";
--------------020406070703070401060005--


|