You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TokenMgrError.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
  17. /* JavaCCOptions: */
  18. package com.vaadin.sass.internal.parser;
  19. /** Token Manager Error. */
  20. public class TokenMgrError extends Error
  21. {
  22. /**
  23. * The version identifier for this Serializable class.
  24. * Increment only if the <i>serialized</i> form of the
  25. * class changes.
  26. */
  27. private static final long serialVersionUID = 1L;
  28. /*
  29. * Ordinals for various reasons why an Error of this type can be thrown.
  30. */
  31. /**
  32. * Lexical error occurred.
  33. */
  34. static final int LEXICAL_ERROR = 0;
  35. /**
  36. * An attempt was made to create a second instance of a static token manager.
  37. */
  38. static final int STATIC_LEXER_ERROR = 1;
  39. /**
  40. * Tried to change to an invalid lexical state.
  41. */
  42. static final int INVALID_LEXICAL_STATE = 2;
  43. /**
  44. * Detected (and bailed out of) an infinite loop in the token manager.
  45. */
  46. static final int LOOP_DETECTED = 3;
  47. /**
  48. * Indicates the reason why the exception is thrown. It will have
  49. * one of the above 4 values.
  50. */
  51. int errorCode;
  52. /**
  53. * Replaces unprintable characters by their escaped (or unicode escaped)
  54. * equivalents in the given string
  55. */
  56. protected static final String addEscapes(String str) {
  57. StringBuffer retval = new StringBuffer();
  58. char ch;
  59. for (int i = 0; i < str.length(); i++) {
  60. switch (str.charAt(i))
  61. {
  62. case 0 :
  63. continue;
  64. case '\b':
  65. retval.append("\\b");
  66. continue;
  67. case '\t':
  68. retval.append("\\t");
  69. continue;
  70. case '\n':
  71. retval.append("\\n");
  72. continue;
  73. case '\f':
  74. retval.append("\\f");
  75. continue;
  76. case '\r':
  77. retval.append("\\r");
  78. continue;
  79. case '\"':
  80. retval.append("\\\"");
  81. continue;
  82. case '\'':
  83. retval.append("\\\'");
  84. continue;
  85. case '\\':
  86. retval.append("\\\\");
  87. continue;
  88. default:
  89. if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
  90. String s = "0000" + Integer.toString(ch, 16);
  91. retval.append("\\u" + s.substring(s.length() - 4, s.length()));
  92. } else {
  93. retval.append(ch);
  94. }
  95. continue;
  96. }
  97. }
  98. return retval.toString();
  99. }
  100. /**
  101. * Returns a detailed message for the Error when it is thrown by the
  102. * token manager to indicate a lexical error.
  103. * Parameters :
  104. * EOFSeen : indicates if EOF caused the lexical error
  105. * curLexState : lexical state in which this error occurred
  106. * errorLine : line number when the error occurred
  107. * errorColumn : column number when the error occurred
  108. * errorAfter : prefix that was seen before this error occurred
  109. * curchar : the offending character
  110. * Note: You can customize the lexical error message by modifying this method.
  111. */
  112. protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
  113. return("Lexical error at line " +
  114. errorLine + ", column " +
  115. errorColumn + ". Encountered: " +
  116. (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
  117. "after : \"" + addEscapes(errorAfter) + "\"");
  118. }
  119. /**
  120. * You can also modify the body of this method to customize your error messages.
  121. * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
  122. * of end-users concern, so you can return something like :
  123. *
  124. * "Internal Error : Please file a bug report .... "
  125. *
  126. * from this method for such cases in the release version of your parser.
  127. */
  128. public String getMessage() {
  129. return super.getMessage();
  130. }
  131. /*
  132. * Constructors of various flavors follow.
  133. */
  134. /** No arg constructor. */
  135. public TokenMgrError() {
  136. }
  137. /** Constructor with message and reason. */
  138. public TokenMgrError(String message, int reason) {
  139. super(message);
  140. errorCode = reason;
  141. }
  142. /** Full Constructor. */
  143. public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
  144. this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
  145. }
  146. }
  147. /* JavaCC - OriginalChecksum=525946b34c715198d7c29f668b049f5d (do not edit this line) */