001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2011 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * Sonar is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * Sonar is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with Sonar; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019     */
020    
021    /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 4.1 */
022    /* JavaCCOptions: */
023    package net.sourceforge.pmd.cpd.cppast;
024    
025    /** Token Manager Error. */
026    public class TokenMgrError extends Error
027    {
028    
029       /*
030        * Ordinals for various reasons why an Error of this type can be thrown.
031        */
032    
033       /**
034        * Lexical error occurred.
035        */
036       static final int LEXICAL_ERROR = 0;
037    
038       /**
039        * An attempt was made to create a second instance of a static token manager.
040        */
041       static final int STATIC_LEXER_ERROR = 1;
042    
043       /**
044        * Tried to change to an invalid lexical state.
045        */
046       static final int INVALID_LEXICAL_STATE = 2;
047    
048       /**
049        * Detected (and bailed out of) an infinite loop in the token manager.
050        */
051       static final int LOOP_DETECTED = 3;
052    
053       /**
054        * Indicates the reason why the exception is thrown. It will have
055        * one of the above 4 values.
056        */
057       int errorCode;
058    
059       /**
060        * Replaces unprintable characters by their escaped (or unicode escaped)
061        * equivalents in the given string
062        */
063       protected static final String addEscapes(String str) {
064          StringBuffer retval = new StringBuffer();
065          char ch;
066          for (int i = 0; i < str.length(); i++) {
067            switch (str.charAt(i))
068            {
069               case 0 :
070                  continue;
071               case '\b':
072                  retval.append("\\b");
073                  continue;
074               case '\t':
075                  retval.append("\\t");
076                  continue;
077               case '\n':
078                  retval.append("\\n");
079                  continue;
080               case '\f':
081                  retval.append("\\f");
082                  continue;
083               case '\r':
084                  retval.append("\\r");
085                  continue;
086               case '\"':
087                  retval.append("\\\"");
088                  continue;
089               case '\'':
090                  retval.append("\\\'");
091                  continue;
092               case '\\':
093                  retval.append("\\\\");
094                  continue;
095               default:
096                  if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
097                     String s = "0000" + Integer.toString(ch, 16);
098                     retval.append("\\u" + s.substring(s.length() - 4, s.length()));
099                  } else {
100                     retval.append(ch);
101                  }
102                  continue;
103            }
104          }
105          return retval.toString();
106       }
107    
108       /**
109        * Returns a detailed message for the Error when it is thrown by the
110        * token manager to indicate a lexical error.
111        * Parameters :
112        *    EOFSeen     : indicates if EOF caused the lexical error
113        *    curLexState : lexical state in which this error occurred
114        *    errorLine   : line number when the error occurred
115        *    errorColumn : column number when the error occurred
116        *    errorAfter  : prefix that was seen before this error occurred
117        *    curchar     : the offending character
118        * Note: You can customize the lexical error message by modifying this method.
119        */
120       protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
121          return("Lexical error in file " + CPPParserTokenManager.getFileName() + " at line " +
122               errorLine + ", column " +
123               errorColumn + ".  Encountered: " +
124               (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
125               "after : \"" + addEscapes(errorAfter) + "\"");
126       }
127    
128       /**
129        * You can also modify the body of this method to customize your error messages.
130        * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
131        * of end-users concern, so you can return something like :
132        *
133        *     "Internal Error : Please file a bug report .... "
134        *
135        * from this method for such cases in the release version of your parser.
136        */
137       public String getMessage() {
138          return super.getMessage();
139       }
140    
141       /*
142        * Constructors of various flavors follow.
143        */
144    
145       /** No arg constructor. */
146       public TokenMgrError() {
147       }
148    
149       /** Constructor with message and reason. */
150       public TokenMgrError(String message, int reason) {
151          super(message);
152          errorCode = reason;
153       }
154    
155       /** Full Constructor. */
156       public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
157          this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
158       }
159    }
160    /* JavaCC - OriginalChecksum=7925b33c412b4bfa3a7147ae3e790276 (do not edit this line) */