class TimeToken extends Object
This class represents individual tokens produced by the lexical scanner during time specification parsing. Each token contains both the original text value and a token type identifier that categorizes the token's meaning in the time specification grammar.
Token categories include:
- Time markers: Specific times like midnight, noon, teatime
- Relative references: yesterday, today, tomorrow, now
- Time units: seconds, minutes, hours, days, weeks, months, years
- Calendar units: Month names (JAN-DEC) and day names (SUN-SAT)
- Operators: Plus, minus, dot, colon, slash
- Special tokens: Numbers, identifiers, end-of-file marker
The token system supports both abbreviated and full forms where applicable, providing flexibility in time specification syntax. For example, both "January" and "Jan" map to the same JAN token type.
Tokens are immutable objects created by the TimeScanner and consumed by the TimeParser during the parsing process.
| Modifier and Type | Field and Description |
|---|---|
static int | AMToken for "am" - morning times for 0-12 hour clock |
static int | APRToken for "apr", "april" - fourth month |
static int | AUGToken for "aug", "august" - eighth month |
static int | COLONToken for ":" - time separator |
static int | DAYSToken for "day", "days", "d" - days multiplier |
static int | DECToken for "dec", "december" - twelfth month |
static int | DOTToken for "." - decimal point or date separator |
static int | ENDToken for "end" or "e" - end of time range |
static int | EOFToken for end of input - no more tokens available |
static int | FEBToken for "feb", "february" - second month |
static int | FRIToken for "fri", "friday" - sixth day of week |
static int | HOURSToken for "hour", "hours", "hr", "h" - hours multiplier |
static int | IDToken for unrecognized identifiers - unknown words |
static int | JANToken for "jan", "january" - first month |
static int | JULToken for "jul", "july" - seventh month |
static int | JUNToken for "jun", "june" - sixth month |
static int | JUNKToken for invalid/unparseable input |
static int | MARToken for "mar", "march" - third month |
static int | MAYToken for "may" - fifth month |
static int | MIDNIGHTToken for "midnight" - represents 00:00:00 of today or tomorrow |
static int | MINUSToken for "-" - subtraction operator |
static int | MINUTESToken for "minute", "minutes", "min" - minutes multiplier |
static int | MONToken for "mon", "monday" - second day of week |
static int | MONTHSToken for "month", "months", "mon" - months multiplier |
static int | MONTHS_MINUTESToken for ambiguous "m" - requires context resolution to months or minutes |
static int | NOONToken for "noon" - represents 12:00:00 of today or tomorrow |
static int | NOVToken for "nov", "november" - eleventh month |
static int | NOWToken for "now" or "n" - current timestamp |
static int | NUMBERToken for numeric values - sequences of digits |
static int | OCTToken for "oct", "october" - tenth month |
static int | PLUSToken for "+" - addition operator |
static int | PMToken for "pm" - evening times for 0-12 hour clock |
static int | SATToken for "sat", "saturday" - seventh day of week |
static int | SECONDSToken for "second", "seconds", "sec", "s" - seconds multiplier |
static int | SEPToken for "sep", "september" - ninth month |
static int | SLASHToken for "/" - date separator |
static int | STARTToken for "start" or "s" - beginning of time range |
static int | SUNToken for "sun", "sunday" - first day of week |
static int | TEATIMEToken for "teatime" - represents 16:00:00 of today or tomorrow |
static int | THUToken for "thu", "thursday" - fifth day of week |
static int | TODAYToken for "today" - current date |
(package private) int | token_idThe token type identifier |
static int | TOMORROWToken for "tomorrow" - one day after current date |
static int | TUEToken for "tue", "tuesday" - third day of week |
(package private) String | valueThe original text value of this token |
static int | WEDToken for "wed", "wednesday" - fourth day of week |
static int | WEEKSToken for "week", "weeks", "wk", "w" - weeks multiplier |
static int | YEARSToken for "year", "years", "yr", "y" - years multiplier |
static int | YESTERDAYToken for "yesterday" - one day before current date |
| Constructor and Description |
|---|
TimeToken(String value,
int token_id)Creates a new TimeToken with the specified value and type. |
| Modifier and Type | Method and Description |
|---|---|
String | toString()Returns a string representation of this token for debugging. |
public static final int AM
public static final int APR
public static final int AUG
public static final int COLON
public static final int DAYS
public static final int DEC
public static final int DOT
public static final int END
public static final int EOF
public static final int FEB
public static final int FRI
public static final int HOURS
public static final int ID
public static final int JAN
public static final int JUL
public static final int JUN
public static final int JUNK
public static final int MAR
public static final int MAY
public static final int MIDNIGHT
public static final int MINUS
public static final int MINUTES
public static final int MON
public static final int MONTHS
public static final int MONTHS_MINUTES
public static final int NOON
public static final int NOV
public static final int NOW
public static final int NUMBER
public static final int OCT
public static final int PLUS
public static final int PM
public static final int SAT
public static final int SECONDS
public static final int SEP
public static final int SLASH
public static final int START
public static final int SUN
public static final int TEATIME
public static final int THU
public static final int TODAY
final int token_id
public static final int TOMORROW
public static final int TUE
final String value
public static final int WED
public static final int WEEKS
public static final int YEARS
public static final int YESTERDAY
public TimeToken(String value, int token_id)
value - the original text value of the token (may be null for EOF)token_id - the token type identifier from the constant definitionspublic String toString()
The format is "value [token_id]" which makes it easy to see both the original text and the token type during parsing and debugging.