Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libutil Reformat grammar part according to my standards ...



details:   https://anonhg.NetBSD.org/src/rev/f90fe4fc86a0
branches:  trunk
changeset: 342599:f90fe4fc86a0
user:      dholland <dholland%NetBSD.org@localhost>
date:      Thu Dec 31 09:12:57 2015 +0000

description:
Reformat grammar part according to my standards for yacc grammars.

diffstat:

 lib/libutil/parsedate.y |  480 ++++++++++++++++++++++-------------------------
 1 files changed, 222 insertions(+), 258 deletions(-)

diffs (truncated from 531 to 300 lines):

diff -r 44984e6b8f5d -r f90fe4fc86a0 lib/libutil/parsedate.y
--- a/lib/libutil/parsedate.y   Thu Dec 31 04:58:43 2015 +0000
+++ b/lib/libutil/parsedate.y   Thu Dec 31 09:12:57 2015 +0000
@@ -14,7 +14,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.24 2015/12/08 12:51:04 christos Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.25 2015/12/31 09:12:57 dholland Exp $");
 #endif
 
 #include <stdio.h>
@@ -103,7 +103,10 @@
 
 %type  <Number>        tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT
 %type  <Number>        tSEC_UNIT tSNUMBER tUNUMBER tZONE tTIME
-%type  <Meridian>      tMERIDIAN o_merid
+%type  <Meridian>      tMERIDIAN
+
+%type  <Number>        at_number
+%type  <Meridian>      o_merid
 
 %parse-param   { struct dateinfo *param }
 %parse-param   { const char **yyInput }
@@ -112,289 +115,250 @@
 
 %%
 
-spec   : /* NULL */
+spec:
+         /* empty */
        | spec item
-       ;
+;
 
-item   : time {
-           param->yyHaveTime++;
-       }
-       | time_numericzone {
-           param->yyHaveTime++;
-           param->yyHaveZone++;
-       }
-       | zone {
-           param->yyHaveZone++;
-       }
-       | date {
-           param->yyHaveDate++;
-       }
-       | day {
-           param->yyHaveDay++;
-       }
-       | rel {
-           param->yyHaveRel++;
-       }
-       | cvsstamp {
-           param->yyHaveTime++;
-           param->yyHaveDate++;
-           param->yyHaveZone++;
-       }
-       | epochdate {
-           param->yyHaveTime++;
-           param->yyHaveDate++;
-           param->yyHaveZone++;
-       }
+item:
+         time                  { param->yyHaveTime++; }
+       | time_numericzone      { param->yyHaveTime++; param->yyHaveZone++; }
+       | zone                  { param->yyHaveZone++; }
+       | date                  { param->yyHaveDate++; }
+       | day                   { param->yyHaveDay++; }
+       | rel                   { param->yyHaveRel++; }
+       | cvsstamp              { param->yyHaveTime++; param->yyHaveDate++;
+                                 param->yyHaveZone++; }
+       | epochdate             { param->yyHaveTime++; param->yyHaveDate++; 
+                                 param->yyHaveZone++; }
        | number
-       ;
+;
 
-cvsstamp: tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER {
-           param->yyYear = $1;
-           if (param->yyYear < 100) param->yyYear += 1900;
-           param->yyHaveFullYear = 1;
-           param->yyMonth = $3;
-           param->yyDay = $5;
-           param->yyHour = $7;
-           param->yyMinutes = $9;
-           param->yySeconds = $11;
-           param->yyDSTmode = DSToff;
-           param->yyTimezone = 0;
+cvsstamp:
+       tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' 
+                               tUNUMBER '.' tUNUMBER '.' tUNUMBER {
+               param->yyYear = $1;
+               if (param->yyYear < 100) {
+                       param->yyYear += 1900;
+               }
+               param->yyHaveFullYear = 1;
+               param->yyMonth = $3;
+               param->yyDay = $5;
+               param->yyHour = $7;
+               param->yyMinutes = $9;
+               param->yySeconds = $11;
+               param->yyDSTmode = DSToff;
+               param->yyTimezone = 0;
        }
-       ;
+;
+
+epochdate:
+       AT_SIGN at_number {
+               time_t  when = $2;
+               struct tm tmbuf;
+
+               if (gmtime_r(&when, &tmbuf) != NULL) {
+                       param->yyYear = tmbuf.tm_year + 1900;
+                       param->yyMonth = tmbuf.tm_mon + 1;
+                       param->yyDay = tmbuf.tm_mday;
+
+                       param->yyHour = tmbuf.tm_hour;
+                       param->yyMinutes = tmbuf.tm_min;
+                       param->yySeconds = tmbuf.tm_sec;
+               } else {
+                       param->yyYear = EPOCH;
+                       param->yyMonth = 1;
+                       param->yyDay = 1;
 
-epochdate: AT_SIGN at_number {
-            time_t    when = $<Number>2;
-            struct tm tmbuf;
-            if (gmtime_r(&when, &tmbuf) != NULL) {
-               param->yyYear = tmbuf.tm_year + 1900;
-               param->yyMonth = tmbuf.tm_mon + 1;
-               param->yyDay = tmbuf.tm_mday;
+                       param->yyHour = 0;
+                       param->yyMinutes = 0;
+                       param->yySeconds = 0;
+               }
+               param->yyHaveFullYear = 1;
+               param->yyDSTmode = DSToff;
+               param->yyTimezone = 0;
+       }
+;
+
+at_number:
+         tUNUMBER
+       | tSNUMBER
+;
 
-               param->yyHour = tmbuf.tm_hour;
-               param->yyMinutes = tmbuf.tm_min;
-               param->yySeconds = tmbuf.tm_sec;
-           } else {
-               param->yyYear = EPOCH;
-               param->yyMonth = 1;
-               param->yyDay = 1;
-
-               param->yyHour = 0;
+time:
+         tUNUMBER tMERIDIAN {
+               param->yyHour = $1;
+               param->yyMinutes = 0;
+               param->yySeconds = 0;
+               param->yyMeridian = $2;
+         }
+       | tUNUMBER ':' tUNUMBER o_merid {
+               param->yyHour = $1;
+               param->yyMinutes = $3;
+               param->yySeconds = 0;
+               param->yyMeridian = $4;
+         }
+       | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
+               param->yyHour = $1;
+               param->yyMinutes = $3;
+               param->yySeconds = $5;
+               param->yyMeridian = $6;
+         }
+       | tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
+               param->yyHour = $1;
+               param->yyMinutes = $3;
+               param->yySeconds = $5;
+               param->yyMeridian = MER24;
+               /* XXX: Do nothing with millis */
+         }
+       | tTIME {
+               param->yyHour = $1;
                param->yyMinutes = 0;
                param->yySeconds = 0;
-           }
-           param->yyHaveFullYear = 1;
-           param->yyDSTmode = DSToff;
-           param->yyTimezone = 0;
-       }
-       ;
-
-at_number : tUNUMBER | tSNUMBER ;
-
-time   : tUNUMBER tMERIDIAN {
-           param->yyHour = $1;
-           param->yyMinutes = 0;
-           param->yySeconds = 0;
-           param->yyMeridian = $2;
-       }
-       | tUNUMBER ':' tUNUMBER o_merid {
-           param->yyHour = $1;
-           param->yyMinutes = $3;
-           param->yySeconds = 0;
-           param->yyMeridian = $4;
+               param->yyMeridian = MER24;
+               /* Tues midnight --> Weds 00:00, midnight Tues -> Tues 00:00 */
+               if ($1 == 0 && param->yyHaveDay)
+                       param->yyDayNumber++;
        }
-       | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
-           param->yyHour = $1;
-           param->yyMinutes = $3;
-           param->yySeconds = $5;
-           param->yyMeridian = $6;
-       }
-       | tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
-           param->yyHour = $1;
-           param->yyMinutes = $3;
-           param->yySeconds = $5;
-           param->yyMeridian = MER24;
-/* XXX: Do nothing with millis */
-       }
-       | tTIME {
-           param->yyHour = $1;
-           param->yyMinutes = 0;
-           param->yySeconds = 0;
-           param->yyMeridian = MER24;
-           /* Tues midnight --> Weds 00:00, midnight Tues -> Tues 00:00 */
-           if ($1 == 0 && param->yyHaveDay)
-               param->yyDayNumber++;
-       }
-       ;
+;
 
-time_numericzone : tUNUMBER ':' tUNUMBER tSNUMBER {
-           param->yyHour = $1;
-           param->yyMinutes = $3;
-           param->yyMeridian = MER24;
-           param->yyDSTmode = DSToff;
-           param->yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
-       }
+time_numericzone:
+         tUNUMBER ':' tUNUMBER tSNUMBER {
+               param->yyHour = $1;
+               param->yyMinutes = $3;
+               param->yyMeridian = MER24;
+               param->yyDSTmode = DSToff;
+               param->yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
+         }
        | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
-           param->yyHour = $1;
-           param->yyMinutes = $3;
-           param->yySeconds = $5;
-           param->yyMeridian = MER24;
-           param->yyDSTmode = DSToff;
-           param->yyTimezone = - ($6 % 100 + ($6 / 100) * 60);
-       }
-       ;
-
-zone   : tZONE {
-           param->yyTimezone = $1;
-           param->yyDSTmode = DSToff;
-       }
-       | tDAYZONE {
-           param->yyTimezone = $1;
-           param->yyDSTmode = DSTon;
+               param->yyHour = $1;
+               param->yyMinutes = $3;
+               param->yySeconds = $5;
+               param->yyMeridian = MER24;
+               param->yyDSTmode = DSToff;
+               param->yyTimezone = - ($6 % 100 + ($6 / 100) * 60);
        }
-       |
-         tZONE tDST {
-           param->yyTimezone = $1;
-           param->yyDSTmode = DSTon;
-       }
-       ;
+;
+
+zone:
+         tZONE         { param->yyTimezone = $1; param->yyDSTmode = DSToff; }
+       | tDAYZONE      { param->yyTimezone = $1; param->yyDSTmode = DSTon; }
+       | tZONE tDST    { param->yyTimezone = $1; param->yyDSTmode = DSTon; }
+;
 
-day    : tDAY {
-           param->yyDayOrdinal = 1;
-           param->yyDayNumber = $1;
-       }
-       | tDAY ',' {
-           param->yyDayOrdinal = 1;
-           param->yyDayNumber = $1;
-       }
-       | tUNUMBER tDAY {



Home | Main Index | Thread Index | Old Index