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 |
AM
Token for "am" - morning times for 0-12 hour clock
|
static int |
APR
Token for "apr", "april" - fourth month
|
static int |
AUG
Token for "aug", "august" - eighth month
|
static int |
COLON
Token for ":" - time separator
|
static int |
DAYS
Token for "day", "days", "d" - days multiplier
|
static int |
DEC
Token for "dec", "december" - twelfth month
|
static int |
DOT
Token for "." - decimal point or date separator
|
static int |
END
Token for "end" or "e" - end of time range
|
static int |
EOF
Token for end of input - no more tokens available
|
static int |
FEB
Token for "feb", "february" - second month
|
static int |
FRI
Token for "fri", "friday" - sixth day of week
|
static int |
HOURS
Token for "hour", "hours", "hr", "h" - hours multiplier
|
static int |
ID
Token for unrecognized identifiers - unknown words
|
static int |
JAN
Token for "jan", "january" - first month
|
static int |
JUL
Token for "jul", "july" - seventh month
|
static int |
JUN
Token for "jun", "june" - sixth month
|
static int |
JUNK
Token for invalid/unparseable input
|
static int |
MAR
Token for "mar", "march" - third month
|
static int |
MAY
Token for "may" - fifth month
|
static int |
MIDNIGHT
Token for "midnight" - represents 00:00:00 of today or tomorrow
|
static int |
MINUS
Token for "-" - subtraction operator
|
static int |
MINUTES
Token for "minute", "minutes", "min" - minutes multiplier
|
static int |
MON
Token for "mon", "monday" - second day of week
|
static int |
MONTHS
Token for "month", "months", "mon" - months multiplier
|
static int |
MONTHS_MINUTES
Token for ambiguous "m" - requires context resolution to months or minutes
|
static int |
NOON
Token for "noon" - represents 12:00:00 of today or tomorrow
|
static int |
NOV
Token for "nov", "november" - eleventh month
|
static int |
NOW
Token for "now" or "n" - current timestamp
|
static int |
NUMBER
Token for numeric values - sequences of digits
|
static int |
OCT
Token for "oct", "october" - tenth month
|
static int |
PLUS
Token for "+" - addition operator
|
static int |
PM
Token for "pm" - evening times for 0-12 hour clock
|
static int |
SAT
Token for "sat", "saturday" - seventh day of week
|
static int |
SECONDS
Token for "second", "seconds", "sec", "s" - seconds multiplier
|
static int |
SEP
Token for "sep", "september" - ninth month
|
static int |
SLASH
Token for "/" - date separator
|
static int |
START
Token for "start" or "s" - beginning of time range
|
static int |
SUN
Token for "sun", "sunday" - first day of week
|
static int |
TEATIME
Token for "teatime" - represents 16:00:00 of today or tomorrow
|
static int |
THU
Token for "thu", "thursday" - fifth day of week
|
static int |
TODAY
Token for "today" - current date
|
(package private) int |
token_id
The token type identifier
|
static int |
TOMORROW
Token for "tomorrow" - one day after current date
|
static int |
TUE
Token for "tue", "tuesday" - third day of week
|
(package private) String |
value
The original text value of this token
|
static int |
WED
Token for "wed", "wednesday" - fourth day of week
|
static int |
WEEKS
Token for "week", "weeks", "wk", "w" - weeks multiplier
|
static int |
YEARS
Token for "year", "years", "yr", "y" - years multiplier
|
static int |
YESTERDAY
Token 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.