views:

83

answers:

1

I was wondering how could it be possible to format in a human-readable format a ParseException thrown by JavaCC: in fact it includes fields such asbeginLine, beginColumn, endColumn, endLine in the token reference of the exception, but not the reference to the source parsed.

Thanks! :)

A: 

The problem is that, by default, JavaCC doesn't retain the raw source data. So unless you keep a reference to the tokens somehow, they're not held in memory. And even if you did hang onto all the regular tokens, you'd need to add special handling for any SKIP tokens that you'd defined - e.g., for discarding whitespace and comments. The reason JavaCC doesn't retain all this stuff is that it would use a lot more memory.

Keeping all the token images is definitely doable... just takes some semi-manual intervention.

tomcopeland
Tom! It's a long time we haven't chatted! :D (we're also friends on FB and we don't even speak about these things there... :D )Anyway, imagine that I put a StringBuffer that retains all the valid tokens parsed, the problem then would be to get the right column and line to start: imagine I was to build the error string by providing some characters before and some after the point of the error... have you got any solution for that? :)