diff options
Diffstat (limited to 'vhdlparser/TokenMgrError.cc')
-rw-r--r-- | vhdlparser/TokenMgrError.cc | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/vhdlparser/TokenMgrError.cc b/vhdlparser/TokenMgrError.cc new file mode 100644 index 0000000..0be1213 --- /dev/null +++ b/vhdlparser/TokenMgrError.cc @@ -0,0 +1,121 @@ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.cc Version 6.0 */ +/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +#include "TokenMgrError.h" + +namespace vhdl { +namespace parser { + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : 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 + * curJAVACC_CHAR_TYPE : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + JAVACC_STRING_TYPE TokenMgrError::LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar) { +#if 0 + JAVACC_STRING_TYPE s; + stringstream<JAVACC_STRING_TYPE> ss; + ss << "Lexical error at line " << errorLine << " column " << errorColumn + << ". Encountered: " << curChar << "(" << (int)curChar + << ") after : \"" << errorAfter.c_str() << "\""; + return (JAVACC_STRING_TYPE)ss.rdbuf()->str(); +#endif + return EMPTY; + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + JAVACC_STRING_TYPE TokenMgrError::getMessage() { + return message; + } + + /* + * Constructors of various flavors follow. + */ + + /** No arg constructor. */ + TokenMgrError::TokenMgrError() { + } + + /** Constructor with message and reason. */ + TokenMgrError::TokenMgrError(JAVACC_STRING_TYPE message, int reason) { + errorCode = reason; + } + + /** Full Constructor. */ + TokenMgrError::TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar, int reason) { + message = LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar); + errorCode = reason; + } + +} +} + +// i < 16 - guaranteed +static char hexChar(int i) { + if (i < 10) { + return i - '0'; + } + return 'a' + (i - 10); +} + +/** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ +JAVACC_SIMPLE_STRING addUnicodeEscapes(JAVACC_STRING_TYPE str) { + JAVACC_SIMPLE_STRING retval; + for (size_t i = 0; i < str.size(); i++) { + JAVACC_CHAR_TYPE ch = str[i]; + switch (ch) + { + case 0 : + retval += EMPTY[0]; + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0xff) { + retval += ch; + continue; + } + retval.append("\\u"); + retval += (hexChar(ch >> 12)); + retval += (hexChar((ch & 0x0f00) >> 8)); + retval += (hexChar((ch & 0x00f0) >> 4)); + retval += (hexChar(ch & 0x000f)); + continue; + } + } + return retval; +} +/* JavaCC - OriginalChecksum=7f80e3c4eac120168f5e81d4ddb72e4b (do not edit this line) */ |