summaryrefslogtreecommitdiff
path: root/yy/kalmia.l
blob: 6950330946ac186c137c674544dd4c48cd595ed4 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
%option noinput nounput noyywrap 8bit nodefault
%option reentrant bison-bridge bison-locations
%option prefix="kalmia"
%start STRING

%{
#include <string.h>
#define YYLTYPE KALMIALTYPE
#define YYSTYPE KALMIASTYPE
#include "kalmia.tab.h"
#define YY_USER_ACTION \
	yylloc->first_line = yylloc->last_line; \
	yylloc->first_column = yylloc->last_column; \
	if (*yytext == '\n') { \
		yylloc->last_line += 1; \
		yylloc->last_column = 0; \
	} \
	else { \
		yylloc->last_column += yyleng; \
	}
%}

S    \x20\x0a\x0d\x09
DATE  [0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[A-Z]*
ATTR ([\x20\x0a\x0d\x09]*)?"="




%%


<INITIAL>"<?xml".*"?>" {
	/* xml prologue */
	return PROLOG;
}
<INITIAL>[\x20\x0a\x0d\x09] {
	/* ignore whitespace */
}


<INITIAL>"<"                { return S_TAG_OPEN; }
<INITIAL>"</"               { return E_TAG_OPEN; }
<INITIAL>">"                { return TAG_CLOSE; }
<INITIAL>"/>"               { return EMPTY_TAG_CLOSE; }


<INITIAL>"float_array" {
	/* float_array tag */
	return FLOAT_ARRAY;
}
<INITIAL>"param" {
	/* param tag */
	return PARAM;
}


<INITIAL>"id"/{ATTR} {
	/* id attribute */
	return ID_ATTR;
}
<INITIAL>"count"/{ATTR} {
	/* count attribute */
	return COUNT_ATTR;
}
<INITIAL>"name"/{ATTR} {
	/* name attribute */
	return NAME_ATTR;
}
<INITIAL>"type"/{ATTR} {
	/* type attribute */
	return TYPE_ATTR;
}


<INITIAL>[a-zA-Z_:][a-zA-Z0-9\.\-_:]* { 
	/* generic tag name */
	yylval->sval = strdup(yytext); return NAME; 
}
<INITIAL>[a-zA-Z_:][a-zA-Z0-9\.\-_:]*/{ATTR} {
	/* generic attribute key */
	yylval->sval = strdup(yytext);
	return ATTR;
}
<INITIAL>"=" {
	/* attribute "=" */
	return *yytext;
}





<INITIAL>"\"" { 
	/* begin a string */
	BEGIN(STRING);
	return *yytext;
}
<STRING>"\"" {
	/* end a string */
	BEGIN(INITIAL);
	return *yytext;
}
<STRING>[^"]+  {
	/* within a string */
	yylval->sval = strdup(yytext);
	return TEXT;
}


<INITIAL>-?[0-9]+ {
	/* integers */
	yylval->lval = strtol(yytext, NULL, 10);
	return INTEGER;
}
<INITIAL>-?[0-9]+\.?[0-9]* {
	/* doubles */
	yylval->dval = strtod(yytext, NULL);
	return DOUBLE;
}
<INITIAL>{DATE} {
	/* dates */
	return DATE;
}