import org.collectionspace.services.structureddate.antlr.StructuredDateParser.MillenniumContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.MonthContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.MonthInYearRangeContext;
+import org.collectionspace.services.structureddate.antlr.StructuredDateParser.MonthYearContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NthCenturyRangeContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NthContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NthHalfContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NthQuarterContext;
+import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NthQuarterInYearRangeContext;
+import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NthQuarterYearContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NumCenturyContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NumContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.NumDateContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.StrDayInMonthRangeContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.StrMonthContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.StrSeasonContext;
+import org.collectionspace.services.structureddate.antlr.StructuredDateParser.StrSeasonInYearRangeContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.UncertainDateContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.YearContext;
import org.collectionspace.services.structureddate.antlr.StructuredDateParser.YearSpanningWinterContext;
+import org.collectionspace.services.structureddate.antlr.StructuredDateParser.SeasonYearContext;
+
/**
* A StructuredDateEvaluator that uses an ANTLR parser to parse the display date,
public void exitNthCenturyRange(NthCenturyRangeContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer endN = (Integer) stack.pop();
Part endPart = (Part) stack.pop();
Integer startN = (Integer) stack.pop();
public void exitMonthInYearRange(MonthInYearRangeContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Integer numMonthEnd = (Integer) stack.pop();
Integer numMonthStart = (Integer) stack.pop();
public void exitStrDayInMonthRange(StrDayInMonthRangeContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Integer dayOfMonthEnd = (Integer) stack.pop();
Integer dayOfMonthStart = (Integer) stack.pop();
public void exitNumDayInMonthRange(NumDayInMonthRangeContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Integer dayOfMonthEnd = (Integer) stack.pop();
Integer dayOfMonthStart = (Integer) stack.pop();
stack.push(new Date(year, numMonth, dayOfMonth, era));
}
-
@Override
public void exitNumDate(NumDateContext ctx) {
if (ctx.exception != null) return;
// and reorder the stack into the canonical
// year-month-day-era ordering.
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer num3 = (Integer) stack.pop();
Integer num2 = (Integer) stack.pop();
Integer num1 = (Integer) stack.pop();
// Reorder the stack into a canonical ordering,
// year-month-day-era.
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Integer dayOfMonth = (Integer) stack.pop();
Integer numMonth = (Integer) stack.pop();
// Reorder the stack into a canonical ordering,
// year-month-day-era.
- Era era = null;
- boolean eraLast = stack.peek() instanceof Integer;
+ Integer dayOfMonth = (Integer) stack.pop();
+ Integer numMonth = (Integer) stack.pop();
+ Integer year = (Integer) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
- // Declare nums
- Integer num1;
- Integer num2;
- Integer num3;
+ stack.push(year);
+ stack.push(numMonth);
+ stack.push(dayOfMonth);
+ stack.push(era);
+ }
- if (!eraLast) {
- era = (Era) stack.pop(); // damn eras
- }
+ // @Override
+ // public void exitInvStrDate(InvStrDateContext ctx) {
+ // if (ctx.exception != null) return;
- num1 = (Integer) stack.pop(); // year or day
- num2 = (Integer) stack.pop(); // month
- num3 = (Integer) stack.pop(); // day
-
- if (eraLast) {
- era = (Era) stack.pop();
- }
+ // // Reorder the stack into a canonical ordering,
+ // // year-month-day-era.
+ // Era era = null;
- Integer dayOfMonth = num1;
- Integer numMonth = num2;
- Integer year = num3;
-
- if (DateUtils.isValidDate(num3, num2, num1, era)) {
- // Do nothing, already in the right format (Era Year Month Day)
- } else if (DateUtils.isValidDate(num1, num2, num3, era)) {
- // Use other format: Day Month Year Era
- dayOfMonth = num3;
- year = num1;
- }
+ // boolean eraLast = stack.peek() instanceof Integer;
+ // // Declare nums
+ // Integer num1;
+ // Integer num2;
+ // Integer num3;
- stack.push(year);
- stack.push(numMonth);
- stack.push(dayOfMonth);
- stack.push(era);
+ // if (!eraLast) {
+ // era = (Era) stack.pop(); // damn eras
+ // }
- if (dayOfMonth > 31 || dayOfMonth <= 0) {
- throw new StructuredDateFormatException("unexpected day of month '" + Integer.toString(dayOfMonth) + "'");
- }
- if (year == 0) {
- throw new StructuredDateFormatException("unexpected year '" + Integer.toString(year) + "'");
- }
- }
+ // num1 = (Integer) stack.pop(); // year or day
+ // num2 = (Integer) stack.pop(); // month
+ // num3 = (Integer) stack.pop(); // day
+
+ // if (eraLast) {
+ // era = (Era) stack.pop();
+ // }
+
+ // Integer dayOfMonth = num1;
+ // Integer numMonth = num2;
+ // Integer year = num3;
+
+ // if (DateUtils.isValidDate(num3, num2, num1, era)) {
+ // // Do nothing, already in the right format (Era Year Month Day)
+ // } else if (DateUtils.isValidDate(num1, num2, num3, era)) {
+ // // Use other format: Day Month Year Era
+ // dayOfMonth = num3;
+ // year = num1;
+ // }
+
+
+ // stack.push(year);
+ // stack.push(numMonth);
+ // stack.push(dayOfMonth);
+ // stack.push(era);
+
+ // if (dayOfMonth > 31 || dayOfMonth <= 0) {
+ // throw new StructuredDateFormatException("unexpected day of month '" + Integer.toString(dayOfMonth) + "'");
+ // }
+ // if (year == 0) {
+ // throw new StructuredDateFormatException("unexpected year '" + Integer.toString(year) + "'");
+ // }
+ // }
@Override
public void exitMonth(MonthContext ctx) {
stack.push(new Date(year, numMonth, DateUtils.getDaysInMonth(numMonth, year, era), era));
}
+ @Override
+ public void exitMonthYear(MonthYearContext ctx) {
+ if (ctx.exception != null) return;
+
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
+
+ stack.push(era);
+ }
+
@Override
public void exitInvMonthYear(InvMonthYearContext ctx) {
if (ctx.exception != null) return;
Integer numMonth = (Integer) stack.pop();
Integer year = (Integer) stack.pop();
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
stack.push(numMonth);
stack.push(year);
public void exitYearSpanningWinter(YearSpanningWinterContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer endYear = (Integer) stack.pop();
Integer startYear = (Integer) stack.pop();
public void exitPartialYear(PartialYearContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Part part = (Part) stack.pop();
public void exitHalfYear(HalfYearContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Integer half = (Integer) stack.pop();
Integer quarter = (Integer) stack.pop();
Integer year = (Integer) stack.pop();
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
stack.push(quarter);
stack.push(year);
stack.push(era);
}
+ @Override
+ public void exitSeasonYear(SeasonYearContext ctx) {
+ if (ctx.exception != null) return;
+
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
+ stack.push(era);
+
+ }
+
@Override
public void exitYear(YearContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
stack.push(new Date(year, 1, 1, era));
public void exitPartialDecade(PartialDecadeContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Part part = (Part) stack.pop();
public void exitDecade(DecadeContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
// Calculate the start and end year of the decade, which depends on the era.
public void exitPartialCentury(PartialCenturyContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Part part = (Part) stack.pop();
public void exitQuarterCentury(QuarterCenturyContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Integer quarter = (Integer) stack.pop();
public void exitHalfCentury(HalfCenturyContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
Integer half = (Integer) stack.pop();
public void exitCentury(CenturyContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer year = (Integer) stack.pop();
if (era != null) {
public void exitMillennium(MillenniumContext ctx) {
if (ctx.exception != null) return;
- Era era = (Era) stack.pop();
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
Integer n = (Integer) stack.pop();
if (era != null) {
throw new StructuredDateFormatException("unexpected half '" + n + "'");
}
}
+
+
+ @Override
+ public void exitNthQuarterInYearRange(NthQuarterInYearRangeContext ctx) {
+ if (ctx.exception != null) return;
+
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
+
+ stack.push(era);
+ }
+
+ @Override
+ public void exitStrSeasonInYearRange(StrSeasonInYearRangeContext ctx) {
+ if (ctx.exception != null) return;
+
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
+
+ stack.push(era);
+
+ }
+
+ @Override
+ public void exitNthQuarterYear(NthQuarterYearContext ctx) {
+
+ Era era = (ctx.era() == null) ? null : (Era) stack.pop();
+
+ stack.push(era);
+ }
@Override
public void exitNthQuarter(NthQuarterContext ctx) {