001package Torello.CSS; 002 003import java.util.Vector; 004 005/** 006 * This class may be instantiated by <B STYLE='color: red;'><I>both</I></B> the Tokenizer 007 * <B STYLE='color: red;'><I>and </I></B> the individual Static-Build Methods offered by each of 008 * the individual Token-Classes. This class is used to relay that a Parse-Error has occred during 009 * part of the Tokenization Process. 010 */ 011public class TokenizeError 012{ 013 /** 014 * The last known location within the input Code-Point {@code int[]}-Array where a valid 015 * {@link CSSToken} instance was generated before the Parse-Error Occured. 016 */ 017 public final int sPos; 018 019 /** 020 * The exact location of the input Code-Point {@code int[]}-Array that was being analyzed when 021 * it was ultimately decided that a Parse-Error had unequivocally occured. 022 */ 023 public final int ePos; 024 025 /** 026 * The {@link CSSToken} class whose {@code 'consume'} method was being executed which uncovered 027 * this {@code TokenizeError}. Specifically, if the Class {@link Str} Method 028 * {@link Str#consume 'consume'} was running when the error was found then this {@code public} 029 * constant field would be assigned {@code Str.class}. 030 */ 031 public final Class<? extends CSSToken> parsingClass; 032 033 /** The CSS where the error occured. {@code subStr = new String(css, sPos, ePos-sPos); } */ 034 public final String subStr; 035 036 /** 037 * The Tokenizer's various {@code 'cosnume'} methods will attempt to provide a thoughtfully 038 * worded Error-Message depicting what has gone wrong. Those message's {@code String}-text 039 * content will be saved to this {@code public} field. 040 */ 041 public final String message; 042 043 <T extends CSSToken> TokenizeError( 044 final int[] css, 045 final int sPos, 046 final int ePos, 047 final Class<? extends CSSToken> parsingClass, 048 final String message 049 ) 050 { 051 this.sPos = sPos; 052 this.ePos = ePos; 053 this.subStr = new String(css, sPos, ePos-sPos); 054 this.parsingClass = parsingClass; 055 this.message = message; 056 } 057 058 void throwException() 059 { throw new TokenizeException(toString()); } 060 061 public String toString() 062 { 063 return 064 "Class: [" + parsingClass.getSimpleName() + "] Build/Parse\n" + 065 "Input CSS-Text: [" + subStr + "]\n" + 066 "Message:\n\t" + message; 067 } 068}