summaryrefslogtreecommitdiff
path: root/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.lex
blob: 48a913a34435ed1acaf4f97bbe5836241fcb5c7a (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
%{
	#include "y.tab.h"
	#include <string.h>
	#define MAX_STR_LEN 255

int string(int tok) {
	int lg = strlen(yytext);
	if ( lg > MAX_STR_LEN ) {
		return LEXERROR;
	} else {
		yylval.str = malloc(sizeof(char)*(lg+1));
		strcpy(yylval.str, yytext);
		return tok;
	}
}
%}

%option nounput
%option noyywrap

BLANK [ \t]
NOT_BLANK [^ \t]
IDENT [a-zA-Z][a-zA-Z0-9_-]*
NUMBER "-"?[0-9]+
COMMENT "#"[^\n]*


%x INI_VALUE 
%x STR_M
%x STR_MM
	/*	%s : inclusive start condition (inclus aussi les règles sans <cond>)
		%x : exclusive start condition (règles sans <cond> inactives)
		
		<INI_VALUE>[^,\n-][^\n]*			{
																printf("INI_VALUE->STR-> [%s]\n",yytext);
																return string(STR);
															}
	*/
%%

"="														{ 
																	printf("[=]\n");
																	printf("--AUTO INI_VALUE--\n");  
																	BEGIN(INI_VALUE);
																	return AFF;
															}
<INI_VALUE>\n									{	
																	printf("[INI_VALUE->\\n]\n"); 
																	yylineno++;
																	printf("--AUTO INITIAL--\n"); 
																	BEGIN(INITIAL);
																	return EOL; 
															}
<INI_VALUE>{NUMBER}{BLANK}*{COMMENT}?	{ 
																printf("INI_VALUE->INT-> [%d]\n",atoi(yytext));
																yylval.num = atoi(yytext);
																return INT;
															}
<INI_VALUE>","								{
																printf("INI_VALUE->VIR-> [,]\n");
																return VIR;
															}
"style"											  	{ 
																printf("style\n");
																printf("--AUTO STR_M--\n");
																BEGIN(STR_M);
																return STYLE;
															}
"name"											  { 
																printf("name\n");
																printf("--AUTO STR_M--\n");
																BEGIN(STR_M);
																return NAME;
															}
"superlemming"								{ 
																printf("superlemming\n");
																printf("--AUTO STR_M--\n");
																BEGIN(STR_M);
																return SLEM;
															}
"bgColor"											{ 
																printf("bgColor\n");
																printf("--AUTO STR_M--\n");
																BEGIN(STR_M);
																return BGCOLOR;
															}
"debrisColor"									{ 
																printf("debrisColor\n");
																printf("--AUTO STR_M--\n");
																BEGIN(STR_M);
																return DEBRISCOLOR;
															}
"particleColor"								{ 
																printf("particleColor\n");
																printf("--AUTO STR_M--\n");
																BEGIN(STR_M);
																return PARTICLECOLOR;
															}
													
<STR_M>{BLANK}*"="{BLANK}*		{
																printf("STR_M-> [=]\n");
																printf("--AUTO STR_MM--\n");
																BEGIN(STR_MM);
																return AFF;
															}
<STR_M>{BLANK}*
<STR_MM>{BLANK}*
<STR_MM>{BLANK}*[^\n]*								 {
																printf("STR_MM->STR-> [%s]\n",yytext);
																printf("--AUTO INITIAL--\n");
																BEGIN(INITIAL);
																return string(STR);
															}
<STR_MM>\n											{
																	printf("[STR_MM->\\n]\n"); 
																	yylineno++;
																	printf("--AUTO INITIAL--\n"); 
																	BEGIN(INITIAL);
																	return EOL; 
															}															

{IDENT}												{
																printf("[%s]\n",yytext);
																return string(IDENT);
															}

"#"[^\n]*\n										{
																printf("[COMMENT:%s]\n[\\n]\n",yytext);
																yylineno++;
															} /* Single line Comment*/
\r														/* http://fr.wikipedia.org/wiki/Fin_de_ligne : CRLF*/
\n														{
																printf("[\\n]\n");
																yylineno++;
																return EOL;
															} /* printf("\n"); */

{BLANK}*											/* Ignore */



{NOT_BLANK}		fprintf(stderr, "LEX : ERROR : unknown char '%c'", yytext[0]); return LEXERROR; /* Pour tout ce qu'on a pas encore chopé */