Coverage Report - com.quiotix.html.parser.ParseException
 
Classes in this File Line Coverage Branch Coverage Complexity
ParseException
0%
0/70
0%
0/34
5.4
 
 1  
 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
 2  
 package com.quiotix.html.parser;
 3  
 
 4  
 /**
 5  
  * This exception is thrown when parse errors are encountered.
 6  
  * You can explicitly create objects of this exception type by
 7  
  * calling the method generateParseException in the generated
 8  
  * parser.
 9  
  *
 10  
  * You can modify this class to customize your error reporting
 11  
  * mechanisms so long as you retain the public fields.
 12  
  */
 13  
 public class ParseException extends Exception {
 14  
   private static final long serialVersionUID = -3135142198035716513L;
 15  
 
 16  
   /**
 17  
    * This constructor is used by the method "generateParseException"
 18  
    * in the generated parser.  Calling this constructor generates
 19  
    * a new object of this type with the fields "currentToken",
 20  
    * "expectedTokenSequences", and "tokenImage" set.  The boolean
 21  
    * flag "specialConstructor" is also set to true to indicate that
 22  
    * this constructor was used to create this object.
 23  
    * This constructor calls its super class with the empty string
 24  
    * to force the "toString" method of parent class "Throwable" to
 25  
    * print the error message in the form:
 26  
    *     ParseException: <result of getMessage>
 27  
    */
 28  
   public ParseException(Token currentTokenVal,
 29  
                         int[][] expectedTokenSequencesVal,
 30  
                         String[] tokenImageVal
 31  
                        )
 32  
   {
 33  0
     super("");
 34  0
     specialConstructor = true;
 35  0
     currentToken = currentTokenVal;
 36  0
     expectedTokenSequences = expectedTokenSequencesVal;
 37  0
     tokenImage = tokenImageVal;
 38  0
   }
 39  
 
 40  
   /**
 41  
    * The following constructors are for use by you for whatever
 42  
    * purpose you can think of.  Constructing the exception in this
 43  
    * manner makes the exception behave in the normal way - i.e., as
 44  
    * documented in the class "Throwable".  The fields "errorToken",
 45  
    * "expectedTokenSequences", and "tokenImage" do not contain
 46  
    * relevant information.  The JavaCC generated code does not use
 47  
    * these constructors.
 48  
    */
 49  
 
 50  
   public ParseException() {
 51  0
     super();
 52  0
     specialConstructor = false;
 53  0
   }
 54  
 
 55  
   /** Constructor with message. */
 56  
   public ParseException(String message) {
 57  0
     super(message);
 58  0
     specialConstructor = false;
 59  0
   }
 60  
 
 61  
   /**
 62  
    * This variable determines which constructor was used to create
 63  
    * this object and thereby affects the semantics of the
 64  
    * "getMessage" method (see below).
 65  
    */
 66  
   protected boolean specialConstructor;
 67  
 
 68  
   /**
 69  
    * This is the last token that has been consumed successfully.  If
 70  
    * this object has been created due to a parse error, the token
 71  
    * followng this token will (therefore) be the first error token.
 72  
    */
 73  
   public Token currentToken;
 74  
 
 75  
   /**
 76  
    * Each entry in this array is an array of integers.  Each array
 77  
    * of integers represents a sequence of tokens (by their ordinal
 78  
    * values) that is expected at this point of the parse.
 79  
    */
 80  
   public int[][] expectedTokenSequences;
 81  
 
 82  
   /**
 83  
    * This is a reference to the "tokenImage" array of the generated
 84  
    * parser within which the parse error occurred.  This array is
 85  
    * defined in the generated ...Constants interface.
 86  
    */
 87  
   public String[] tokenImage;
 88  
 
 89  
   /**
 90  
    * This method has the standard behavior when this object has been
 91  
    * created using the standard constructors.  Otherwise, it uses
 92  
    * "currentToken" and "expectedTokenSequences" to generate a parse
 93  
    * error message and returns it.  If this object has been created
 94  
    * due to a parse error, and you do not catch it (it gets thrown
 95  
    * from the parser), then this method is called during the printing
 96  
    * of the final stack trace, and hence the correct error message
 97  
    * gets displayed.
 98  
    */
 99  
   public String getMessage() {
 100  0
     if (!specialConstructor) {
 101  0
       return super.getMessage();
 102  
     }
 103  0
     StringBuffer expected = new StringBuffer();
 104  0
     int maxSize = 0;
 105  0
     for (int i = 0; i < expectedTokenSequences.length; i++) {
 106  0
       if (maxSize < expectedTokenSequences[i].length) {
 107  0
         maxSize = expectedTokenSequences[i].length;
 108  
       }
 109  0
       for (int j = 0; j < expectedTokenSequences[i].length; j++) {
 110  0
         expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
 111  
       }
 112  0
       if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
 113  0
         expected.append("...");
 114  
       }
 115  0
       expected.append(eol).append("    ");
 116  
     }
 117  0
     String retval = "Encountered \"";
 118  0
     Token tok = currentToken.next;
 119  0
     for (int i = 0; i < maxSize; i++) {
 120  0
       if (i != 0) retval += " ";
 121  0
       if (tok.kind == 0) {
 122  0
         retval += tokenImage[0];
 123  0
         break;
 124  
       }
 125  0
       retval += " " + tokenImage[tok.kind];
 126  0
       retval += " \"";
 127  0
       retval += add_escapes(tok.image);
 128  0
       retval += " \"";
 129  0
       tok = tok.next; 
 130  
     }
 131  0
     retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
 132  0
     retval += "." + eol;
 133  0
     if (expectedTokenSequences.length == 1) {
 134  0
       retval += "Was expecting:" + eol + "    ";
 135  
     } else {
 136  0
       retval += "Was expecting one of:" + eol + "    ";
 137  
     }
 138  0
     retval += expected.toString();
 139  0
     return retval;
 140  
   }
 141  
 
 142  
   /**
 143  
    * The end of line string for this machine.
 144  
    */
 145  0
   protected String eol = System.getProperty("line.separator", "\n");
 146  
  
 147  
   /**
 148  
    * Used to convert raw characters to their escaped version
 149  
    * when these raw version cannot be used as part of an ASCII
 150  
    * string literal.
 151  
    */
 152  
   protected String add_escapes(String str) {
 153  0
       StringBuffer retval = new StringBuffer();
 154  
       char ch;
 155  0
       for (int i = 0; i < str.length(); i++) {
 156  0
         switch (str.charAt(i))
 157  
         {
 158  
            case 0 :
 159  0
               continue;
 160  
            case '\b':
 161  0
               retval.append("\\b");
 162  0
               continue;
 163  
            case '\t':
 164  0
               retval.append("\\t");
 165  0
               continue;
 166  
            case '\n':
 167  0
               retval.append("\\n");
 168  0
               continue;
 169  
            case '\f':
 170  0
               retval.append("\\f");
 171  0
               continue;
 172  
            case '\r':
 173  0
               retval.append("\\r");
 174  0
               continue;
 175  
            case '\"':
 176  0
               retval.append("\\\"");
 177  0
               continue;
 178  
            case '\'':
 179  0
               retval.append("\\\'");
 180  0
               continue;
 181  
            case '\\':
 182  0
               retval.append("\\\\");
 183  0
               continue;
 184  
            default:
 185  0
               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
 186  0
                  String s = "0000" + Integer.toString(ch, 16);
 187  0
                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
 188  0
               } else {
 189  0
                  retval.append(ch);
 190  
               }
 191  
               continue;
 192  
         }
 193  
       }
 194  0
       return retval.toString();
 195  
    }
 196  
 
 197  
 }