File: parsetime.l

package info (click to toggle)
at 3.1.23-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 660 kB
  • sloc: sh: 3,096; ansic: 2,487; yacc: 575; makefile: 203; lex: 91; perl: 62
file content (91 lines) | stat: -rw-r--r-- 2,512 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
%{

#include <string.h>
#include <time.h>
#include "y.tab.h"
#include "parsetime.h"

char *last_token = NULL;
char **my_argv;

#define COPY_TOK do { last_token = strdup(yytext); } while(0)

#define COPY_VAL do { yylval.charval = strdup(yytext); } while(0)

#define YY_INPUT(buf,result,max_size) \
    do { \
	if (*my_argv == NULL) { \
	    result = YY_NULL ;\
	    buf[0] = 0; \
	} \
	else { \
	    if (**my_argv == '\0') { \
		buf[0] = ' ' ; \
		my_argv ++; \
	    } \
	    else { \
		buf[0] = **my_argv; \
		(*my_argv) ++; \
	    } \
	result = 1; \
	} \
    } while(0)
%}

%%

now		{ COPY_TOK ; return NOW; }
am		{ COPY_TOK ; return AM; }
pm		{ COPY_TOK ; return PM; }
noon		{ COPY_TOK ; return NOON; }
midnight	{ COPY_TOK ; return MIDNIGHT; }
teatime		{ COPY_TOK ; return TEATIME; }
sun(day)?	{ COPY_TOK ; return SUN; }
mon(day)?	{ COPY_TOK ; return MON; }
tue(sday)?	{ COPY_TOK ; return TUE; }
wed(nesday)?	{ COPY_TOK ; return WED; }
thu(rsday)?	{ COPY_TOK ; return THU; }
fri(day)?	{ COPY_TOK ; return FRI; }
sat(urday)?	{ COPY_TOK ; return SAT; }
today		{ COPY_TOK ; return TODAY; }
tomorrow	{ COPY_TOK ; return TOMORROW; }
next		{ COPY_TOK ; return NEXT; }
min		{ COPY_TOK ; return MINUTE; }
minute(s)?	{ COPY_TOK ; return MINUTE; }
hour(s)?	{ COPY_TOK ; return HOUR; }
day(s)?		{ COPY_TOK ; return DAY; }
week(s)?	{ COPY_TOK ; return WEEK; }
month(s)?	{ COPY_TOK ; return MONTH; }
year(s)?	{ COPY_TOK ; return YEAR; }
jan(uary)?	{ COPY_TOK ; return JAN; }
feb(ruary)?	{ COPY_TOK ; return FEB; }
mar(ch)?	{ COPY_TOK ; return MAR; }
apr(il)?	{ COPY_TOK ; return APR; }
may		{ COPY_TOK ; return MAY; }
jun(e)?		{ COPY_TOK ; return JUN; }
jul(y)?		{ COPY_TOK ; return JUL; }
aug(ust)?	{ COPY_TOK ; return AUG; }
sep(tember)?	{ COPY_TOK ; return SEP; }
oct(ober)?	{ COPY_TOK ; return OCT; }
nov(ember)?	{ COPY_TOK ; return NOV; }
dec(ember)?	{ COPY_TOK ; return DEC; }
utc		{ COPY_TOK ; return UTC; }
[0-9]{1}	{ COPY_TOK ; COPY_VAL; return INT1DIGIT; }
[0-9]{2}	{ COPY_TOK ; COPY_VAL; return INT2DIGIT; }
[0-9]{4}	{ COPY_TOK ; COPY_VAL; return INT4DIGIT; }
[0-9]{5,8}	{ COPY_TOK ; COPY_VAL; return INT5_8DIGIT; }
[0-9]+		{ COPY_TOK ; COPY_VAL; return INT; }
[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{2}([0-9]{2})?	{ COPY_TOK ; COPY_VAL; return DOTTEDDATE; }
[0-9]{2}([0-9]{2})?-[0-9]{1,2}-[0-9]{1,2}	{ COPY_TOK ; COPY_VAL; return HYPHENDATE; }
[012]?[0-9][:'h,.][0-9]{2}	{ COPY_TOK ; COPY_VAL; return HOURMIN; }
[ \t\n]		;
.		{ COPY_TOK ; return yytext[0]; }

%%

#ifdef NEED_YYWRAP
int yywrap()
{
    return 1;
}
#endif