com.jstatcom.parser
Class TSDateParser
- java.lang.Object
-
- com.jstatcom.parser.TSDateParser
-
- All Implemented Interfaces:
- TSDateParserConstants
public class TSDateParser extends java.lang.Object implements TSDateParserConstants
Parser that assemblesTSDateobjects from an input string, for example1960
1960.1
1960 I
1960 1/4
1960 Q4
1960 m11
The following rules apply for parsing:
XX x"/"y, for example1960 1/1is recognized for arbitrary sub periodicities with mainPeriod=XX, subPeriod=x, subPeriodicity=yXX ["M","m"]x, for example1960 M1is recognized as mainPeriod=XX, subPeriod=x, subPeriodicity=12 (monthly)XX ["Q","q"]x, for example1960 Q1is recognized as mainPeriod=XX, subPeriod=x, subPeriodicity=4 (quarterly)XX ["I", "II"], for example1960 Iis recognized as mainPeriod=XX, subPeriod=1 or 2, subPeriodicity=2 (half yearly)XX, for example1960is recognized as mainPeriod=XX, subPeriod=1, subPeriodicity=1 (yearly)XX.x, for example1960.1is recognized as mainPeriod=XX, subPeriod=x, subPeriodicity=subPeriodicity (needs to be set as argument)
You can use the parser via the
The parser is completely defined in a javacc grammar definition file and can be regenerated whenever necessary.parseString(input, subPeriodicity)method. Whenever the information about the sub periodicity is contained in the input string, it is used and the explicit argument is ignored. But it is needed for dates coded asXX.x, because there is no way to retrieve the sub periodicity from that format, although it is often used and convenient.- See Also:
TSDate
-
-
Field Summary
Fields Modifier and Type Field and Description Tokenjj_ntbooleanlookingAheadTokentokenTSDateParserTokenManagertoken_source
-
Constructor Summary
Constructors Constructor and Description TSDateParser()Default constructor.TSDateParser(java.io.InputStream stream)TSDateParser(java.io.Reader stream)TSDateParser(TSDateParserTokenManager tm)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voiddisable_tracing()voidenable_tracing()ParseExceptiongenerateParseException()TokengetNextToken()TokengetToken(int index)static voidmain(java.lang.String[] args)TSDateparseString(java.lang.String inputString, int subPeriodicity)Reinitializes this engine and parses an input String.voidReInit(java.io.InputStream stream)voidReInit(java.io.Reader stream)voidReInit(TSDateParserTokenManager tm)inttoeval(int subPeriodicity)voidtsdate(int subPeriodicity)Possible date formats.voidtsdefault()Default 1960 1/4.voidtshalfyearly()Half-Yearly 1960 II.voidtsmonthly()Monthly 1960 M11.voidtsquarterly()Quarterly 1960 Q3.
-
-
-
Field Detail
-
token_source
public TSDateParserTokenManager token_source
-
token
public Token token
-
jj_nt
public Token jj_nt
-
lookingAhead
public boolean lookingAhead
-
-
Constructor Detail
-
TSDateParser
public TSDateParser()
Default constructor.
-
TSDateParser
public TSDateParser(TSDateParserTokenManager tm)
-
TSDateParser
public TSDateParser(java.io.InputStream stream)
-
TSDateParser
public TSDateParser(java.io.Reader stream)
-
-
Method Detail
-
disable_tracing
public final void disable_tracing()
-
enable_tracing
public final void enable_tracing()
-
generateParseException
public final ParseException generateParseException()
-
getNextToken
public final Token getNextToken()
-
getToken
public final Token getToken(int index)
-
main
public static void main(java.lang.String[] args) throws ParseException- Throws:
ParseException
-
parseString
public TSDate parseString(java.lang.String inputString, int subPeriodicity) throws ParseException, TokenMgrError, java.lang.IllegalArgumentException
Reinitializes this engine and parses an input String.- Parameters:
inputString- the String to parsesubPeriodicity- defines number of sub periods for the parser run, the argument is ignored if the inputString contains this information, if set to <1, then the string must contain the sub periodicity- Returns:
- TSDate object if parser and assembly where successful
- Throws:
java.lang.IllegalArgumentException- if TSDate assembly failed due to wrong argumentsParseException- if parsing failed, contains error descriptionTokenMgrError- if tokenizing failed, contains error description
-
ReInit
public void ReInit(TSDateParserTokenManager tm)
-
ReInit
public void ReInit(java.io.InputStream stream)
-
ReInit
public void ReInit(java.io.Reader stream)
-
toeval
public final int toeval(int subPeriodicity) throws ParseException- Throws:
ParseException
-
tsdate
public final void tsdate(int subPeriodicity) throws ParseExceptionPossible date formats.- Throws:
ParseException
-
tsdefault
public final void tsdefault() throws ParseExceptionDefault 1960 1/4.- Throws:
ParseException
-
tshalfyearly
public final void tshalfyearly() throws ParseExceptionHalf-Yearly 1960 II.- Throws:
ParseException
-
tsmonthly
public final void tsmonthly() throws ParseExceptionMonthly 1960 M11.- Throws:
ParseException
-
tsquarterly
public final void tsquarterly() throws ParseExceptionQuarterly 1960 Q3.- Throws:
ParseException
-
-
DMelt 3.0 © DataMelt by jWork.ORG