1. /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 *
  2. *
  3. * !!!MODIFIED BY DMITRI PLOTNIKOV - DO NOT REGENERATE!!!
  4. */
  5. package org.apache.commons.jxpath.ri.parser;
  6. public class TokenMgrError extends Error
  7. {
  8. /*
  9. * Ordinals for various reasons why an Error of this type can be thrown.
  10. */
  11. /**
  12. * Lexical error occured.
  13. */
  14. static final int LEXICAL_ERROR = 0;
  15. /**
  16. * An attempt wass made to create a second instance of a static token manager.
  17. */
  18. static final int STATIC_LEXER_ERROR = 1;
  19. /**
  20. * Tried to change to an invalid lexical state.
  21. */
  22. static final int INVALID_LEXICAL_STATE = 2;
  23. /**
  24. * Detected (and bailed out of) an infinite loop in the token manager.
  25. */
  26. static final int LOOP_DETECTED = 3;
  27. /**
  28. * Indicates the reason why the exception is thrown. It will have
  29. * one of the above 4 values.
  30. */
  31. int errorCode;
  32. /**
  33. * Replaces unprintable characters by their espaced (or unicode escaped)
  34. * equivalents in the given string
  35. */
  36. public static final String addEscapes(String str) {
  37. StringBuffer retval = new StringBuffer();
  38. char ch;
  39. for (int i = 0; i < str.length(); i++) {
  40. switch (str.charAt(i))
  41. {
  42. case 0 :
  43. continue;
  44. case '\b':
  45. retval.append("\\b");
  46. continue;
  47. case '\t':
  48. retval.append("\\t");
  49. continue;
  50. case '\n':
  51. retval.append("\\n");
  52. continue;
  53. case '\f':
  54. retval.append("\\f");
  55. continue;
  56. case '\r':
  57. retval.append("\\r");
  58. continue;
  59. case '\"':
  60. retval.append("\\\"");
  61. continue;
  62. case '\'':
  63. retval.append("\\\'");
  64. continue;
  65. case '\\':
  66. retval.append("\\\\");
  67. continue;
  68. default:
  69. if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
  70. String s = "0000" + Integer.toString(ch, 16);
  71. retval.append("\\u" + s.substring(s.length() - 4, s.length()));
  72. } else {
  73. retval.append(ch);
  74. }
  75. continue;
  76. }
  77. }
  78. return retval.toString();
  79. }
  80. /**
  81. * Returns a detailed message for the Error when it is thrown by the
  82. * token manager to indicate a lexical error.
  83. * Parameters :
  84. * EOFSeen : indicates if EOF caused the lexicl error
  85. * curLexState : lexical state in which this error occured
  86. * errorLine : line number when the error occured
  87. * errorColumn : column number when the error occured
  88. * errorAfter : prefix that was seen before this error occured
  89. * curchar : the offending character
  90. * Note: You can customize the lexical error message by modifying this method.
  91. */
  92. protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
  93. return("Lexical error at line " +
  94. errorLine + ", column " +
  95. errorColumn + ". Encountered: " +
  96. (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
  97. "after : \"" + addEscapes(errorAfter) + "\"");
  98. }
  99. /**
  100. * You can also modify the body of this method to customize your error messages.
  101. * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
  102. * of end-users concern, so you can return something like :
  103. *
  104. * "Internal Error : Please file a bug report .... "
  105. *
  106. * from this method for such cases in the release version of your parser.
  107. */
  108. public String getMessage() {
  109. return super.getMessage();
  110. }
  111. /*
  112. * Constructors of various flavors follow.
  113. */
  114. public TokenMgrError() {
  115. }
  116. public TokenMgrError(String message, int reason) {
  117. super(message);
  118. errorCode = reason;
  119. }
  120. public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
  121. this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
  122. // ADDED BY ME FROM THIS POINT TO THE EOF - DMITRI PLOTNIKOV
  123. position = errorColumn - 1;
  124. character = curChar;
  125. }
  126. private int position;
  127. private char character;
  128. public int getPosition(){
  129. return position;
  130. }
  131. public char getCharacter(){
  132. return character;
  133. }
  134. }