Skip to content

Commit

Permalink
Improve lexical error message
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMazas committed Jun 12, 2021
1 parent 8c7c4c6 commit 31ba95d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/main/resources/templates/TokenMgrError.template
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ${SUPPORT_CLASS_VISIBILITY_PUBLIC?public :}class ${LEGACY_EXCEPTION_HANDLING?Tok
* token manager to indicate a lexical error.
* Parameters :
* EOFSeen : indicates if EOF caused the lexical error
* curLexState : lexical state in which this error occurred
* lexState : lexical state in which this error occurred
* errorLine : line number when the error occurred
* errorColumn : column number when the error occurred
* errorAfter : prefix that was seen before this error occurred
Expand All @@ -100,11 +100,12 @@ ${SUPPORT_CLASS_VISIBILITY_PUBLIC?public :}class ${LEGACY_EXCEPTION_HANDLING?Tok
*/
protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) {
char curChar1 = (char)curChar;
return("Lexical error at line " +
errorLine + ", column " +
errorColumn + ". Encountered: " +
(EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") +
"after : \"" + addEscapes(errorAfter) + "\"");
return("Lexical error at line " + //
errorLine + ", column " + //
errorColumn + ". Encountered: " + //
(EOFSeen ? "<EOF>" : ("'" + addEscapes(String.valueOf(curChar)) + "' (" + (int)curChar + "),")) + //
(errorAfter == null || errorAfter.length() == 0 ? "" : " after prefix \"" + addEscapes(errorAfter) + "\"")) + //
(lexState == 0 ? "" : " (in lexical state " + lexState + ")");
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/templates/cpp/TokenMgrError.cc.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ${NAMESPACE_OPEN}
* token manager to indicate a lexical error.
* Parameters :
* EOFSeen : indicates if EOF caused the lexical error
* curLexState : lexical state in which this error occurred
* lexState : lexical state in which this error occurred
* errorLine : line number when the error occurred
* errorColumn : column number when the error occurred
* errorAfter : prefix that was seen before this error occurred
Expand All @@ -21,8 +21,8 @@ namespace ${NAMESPACE_OPEN}
JJString s;
stringstream<JJString> ss;
ss << "Lexical error at line " << errorLine << " column " << errorColumn
<< ". Encountered: " << curChar << "(" << (int)curChar
<< ") after : \"" << errorAfter.c_str() << "\"";
<< ". Encountered: '" << curChar << "' (" << (int)curChar
<< ") after : \"" << errorAfter.c_str() << "\" (in lexical state " << lexState << ")";
return (JJString)ss.rdbuf()->str();
\#endif
return EMPTY;
Expand Down

0 comments on commit 31ba95d

Please sign in to comment.