]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
HM-5: split dayFirstDate into multiple rules
authorcesarvh <cesarv.h@berkeley.edu>
Tue, 30 Oct 2018 21:25:15 +0000 (14:25 -0700)
committercesarvh <cesarv.h@berkeley.edu>
Tue, 19 Mar 2019 19:40:21 +0000 (12:40 -0700)
services/structureddate/structureddate/src/main/antlr4/org/collectionspace/services/structureddate/antlr/StructuredDate.g4
services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java

index 3afaf9f5f0e25a442ae4dcf0779652afd8cc8fa7..4d181dc07d7186cdaedffb4b57928a9c9c53c88c 100644 (file)
@@ -8,7 +8,8 @@ grammar StructuredDate;
 /*
  * Parser rules
  */
-oneDisplayDate:        displayDate ( DOT | QUESTION )? EOF;
+
+oneDisplayDate:        displayDate ( DOT | QUESTION )? EOF ; 
 
 displayDate:           uncertainDate
 |                      certainDate
@@ -91,21 +92,26 @@ century:               ( strCentury | numCentury ) era? ;
 
 millennium:            nth MILLENNIUM era? ;
 
-strDate:               strMonth ( numDayOfMonth | nth ) COMMA? numYear era;
+strDate:               strMonth ( numDayOfMonth | nth ) COMMA? numYear era?;
 invStrDate:            era num COMMA? strMonth num
-|                      ( num | nth ) strMonth COMMA? num era ;
-strDayInMonthRange:    strMonth numDayOfMonth ( HYPHEN | DASH ) numDayOfMonth COMMA? numYear era ;
-monthInYearRange:      strMonth ( HYPHEN | DASH ) strMonth COMMA? numYear era ;
-nthQuarterInYearRange: nthQuarter ( HYPHEN | DASH ) nthQuarter COMMA? numYear era ;
-strSeasonInYearRange:  strSeason ( HYPHEN | DASH ) strSeason COMMA? numYear era ;
-numDayInMonthRange:    numMonth SLASH num ( HYPHEN | DASH ) num SLASH numYear era ;
-numDate:               num SLASH num SLASH num era
-|                      num HYPHEN num HYPHEN num era ;
-monthYear:             strMonth COMMA? numYear era ;
-invMonthYear:          era numYear COMMA? strMonth ;
-seasonYear:            strSeason COMMA? numYear era ;
-invSeasonYear:         era numYear COMMA? strSeason ;
-nthQuarterYear:        nthQuarter numYear era ;
+|                      era? num COMMA strMonth num ;
+dayFirstDate:          num strMonth COMMA? num era
+|                      num strMonth COMMA num era?
+|                      nth strMonth COMMA? num era? ;
+dayOrYearFirstDate:    num strMonth num ;
+invStrDateEraLastDate: num COMMA strMonth num era? ;
+strDayInMonthRange:    strMonth numDayOfMonth ( HYPHEN | DASH ) numDayOfMonth COMMA? numYear era? ;
+monthInYearRange:      strMonth ( HYPHEN | DASH ) strMonth COMMA? numYear era? ;
+nthQuarterInYearRange: nthQuarter ( HYPHEN | DASH ) nthQuarter COMMA? numYear era? ;
+strSeasonInYearRange:  strSeason ( HYPHEN | DASH ) strSeason COMMA? numYear era? ;
+numDayInMonthRange:    numMonth SLASH num ( HYPHEN | DASH ) num SLASH numYear era? ;
+numDate:               num SLASH num SLASH num era?
+|                      num HYPHEN num HYPHEN num era? ;
+monthYear:             strMonth COMMA? numYear era? ;
+invMonthYear:          era? numYear COMMA? strMonth ;
+seasonYear:            strSeason COMMA? numYear era? ;
+invSeasonYear:         era? numYear COMMA? strSeason ;
+nthQuarterYear:        nthQuarter numYear era? ;
 nthQuarter:            ( nth | LAST ) QUARTER ;
 nthHalf:               ( nth | LAST ) HALF ;
 numDecade:             TENS ;
@@ -124,6 +130,7 @@ numDayOfMonth:         NUMBER ;
 num:                   NUMBER ;
 unknownDate:           UNKNOWN ;
 
+
 /*
  * Lexer rules
  */
@@ -163,5 +170,5 @@ SLASH:          '/' ;
 DOT:            '.' ;
 QUESTION:       '?' ;
 OTHER:          . ;
-UNKNOWN:        'unknown';
-STRING:         [a-z]+ ;
\ No newline at end of file
+UNKNOWN:               'unknown' | 'UNKNOWN' ;
+STRING:         [a-z]+ ;
index 560fa020b232440da3514e5edcef100b1469b0fd..b9bdc23841580db93538059129e91a8f7cbd3960 100644 (file)
@@ -167,14 +167,6 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp
                result.setEarliestSingleDate(earliestDate);
                result.setLatestDate(latestDate);
        }
-       @Override
-       public void exitUnknownDate(UnknownDateContext ctx) {
-               if (ctx.exception != null) return;
-
-               // Dummy dates
-               stack.push(new Date());
-               stack.push(new Date());
-       }
 
        @Override
        public void exitBeforeOrAfterDate(BeforeOrAfterDateContext ctx) {
@@ -378,7 +370,7 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp
        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 num1 = (Integer) stack.pop();
                Integer num2 = (Integer) stack.pop();
                Integer num3 = (Integer) stack.pop();
@@ -390,7 +382,6 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp
                        dates are valid, we know that it shouldn't be interpreted as 04/01/13 - 19/31/1995 since these arent valid dates!
                */
 
-
                Integer lateYear = num1;
                Integer earlyMonth = num4;
                Integer dayOfMonthEnd = num2;
@@ -495,7 +486,7 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp
        @Override
        public void exitInvStrDate(InvStrDateContext ctx) {
                if (ctx.exception != null) return;
-       
+
                // Reorder the stack into a canonical ordering,
                // year-month-day-era.
 
@@ -548,6 +539,7 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp
                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) + "'");
@@ -1191,6 +1183,15 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp
                stack.push(num);
        }
 
+       @Override
+       public void exitUnknownDate(UnknownDateContext ctx) {
+               if (ctx.exception != null) return;
+
+               // Dummy dates
+               stack.push(new Date());
+               stack.push(new Date());
+       }
+
        protected String getErrorMessage(RecognitionException re) {
                String message = "";