summaryrefslogtreecommitdiff
path: root/src/parser/parse_ini.lex
blob: f452f4038ca48fce311e6137c6daad795d534c30 (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
%{
#include <SDL_stdinc.h>

#include "y.tab.h"

#define MAX_STR_LEN 255

int lexstring(int tok) {
	size_t len = SDL_strlen(yytext);
	if ( len > MAX_STR_LEN ) {
		return LEXERROR;
	} else {
		yylval.str = malloc(sizeof(char)*(len+1));
		SDL_strlcpy(yylval.str, yytext,len);
		return tok;
	}
}
%}

%option noinput
%option nounput
%option noyywrap
%option case-insensitive

BLANK [ \t]
NOT_BLANK [^ \t]
	/* IDENT [a-z][a-z0-9_-]* */
STRCSV [a-z][a-z0-9._-]*
INTEGER "-"?[0-9]+
INTHEX 0x[0-9a-f]+
COMMENT "#"[^\n]*

	/*
		%s : inclusive start condition (includes also rules starting without <sc>)
		%x : exclusive start condition
	*/
%x TYPE_STR
%x TYPE_OTHER
%x VAL_STR
%x VAL_OTHER
%%

	/* Wilcard state. Following rules are common to all states */
<*>\n		{ yylineno++; BEGIN(INITIAL); return EOL; }
<*>\r		/* Ignore - http://fr.wikipedia.org/wiki/Fin_de_ligne : CRLF*/

	/* Other rules for almost states (but VAL_STR) to ignore blanks and comments */
<INITIAL,TYPE_STR,TYPE_OTHER,VAL_OTHER>"#"[^\n]*	/* Ignore Single line Comment*/
<INITIAL,TYPE_STR,TYPE_OTHER,VAL_OTHER>{BLANK}*		/* Ignore blanks */

	/* Initial state, start condition is 'INITIAL' (implicit), we catch only identifiers here */
"style"			{ BEGIN(TYPE_STR); return STYLE; }
"name"			{ BEGIN(TYPE_STR); return NAME; }

"superlemming"		{ BEGIN(TYPE_OTHER); return SLEM; }

"tiles"			{ BEGIN(TYPE_OTHER); return TILES; }
"frames_"		{ BEGIN(TYPE_OTHER); return FRAMES; }
"anim_"			{ BEGIN(TYPE_OTHER); return ANIM; }
"type_"			{ BEGIN(TYPE_OTHER); return TYPE; }
"sound_"		{ BEGIN(TYPE_OTHER); return SOUND; }

"bgcolor"		{ BEGIN(TYPE_OTHER); return BGCOLOR; }
"debriscolor"		{ BEGIN(TYPE_OTHER); return DEBRISCOLOR; }
"particlecolor"		{ BEGIN(TYPE_OTHER); return PARTICLECOLOR; }

"releaserate"		{ BEGIN(TYPE_OTHER); return RELEASERATE; }
"numlemmings"		{ BEGIN(TYPE_OTHER); return NUMLEMMINGS; }
"numtorescue"		{ BEGIN(TYPE_OTHER); return NUMTORESCUE; }
"timelimit"		{ BEGIN(TYPE_OTHER); return TIMELIMIT; }
"numclimbers"		{ BEGIN(TYPE_OTHER); return NUMCLIMBERS; }
"numfloaters"		{ BEGIN(TYPE_OTHER); return NUMFLOATERS; }
"numbombers"		{ BEGIN(TYPE_OTHER); return NUMBOMBERS; }
"numblockers"		{ BEGIN(TYPE_OTHER); return NUMBLOCKERS; }
"numbuilders"		{ BEGIN(TYPE_OTHER); return NUMBUILDERS; }
"numbashers"		{ BEGIN(TYPE_OTHER); return NUMBASHERS; }
"numminers"		{ BEGIN(TYPE_OTHER); return NUMMINERS; }
"numdiggers"		{ BEGIN(TYPE_OTHER); return NUMDIGGERS; }
"xpos"			{ BEGIN(TYPE_OTHER); return XPOS; }
"object_"		{ BEGIN(TYPE_OTHER); return OBJECT; }
"terrain_"		{ BEGIN(TYPE_OTHER); return TERRAIN; }
"steel_"		{ BEGIN(TYPE_OTHER); return STEEL; }

"maxFallDistance"	{ BEGIN(TYPE_OTHER); return MAXFALLDISTANCE; }
"codeSeed"		{ BEGIN(TYPE_OTHER); return CODESEED; }
"music_"		{ BEGIN(TYPE_STR); return MUSIC; }
"level_"		{ BEGIN(TYPE_OTHER); return LEVEL; }

"lemm_"			{ BEGIN(TYPE_OTHER); return LEMM; }
"pos_"			{ BEGIN(TYPE_OTHER); return POS; }
"mask_"			{ BEGIN(TYPE_OTHER); return MASK; }
"imask_"		{ BEGIN(TYPE_OTHER); return IMASK; }


"fun_"			{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"tricky_"		{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"taxing_"		{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"mayhem_"		{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"tame_"			{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"wild_"			{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"crazy_"		{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"wicked_"		{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"havoc_"		{ BEGIN(TYPE_OTHER); return DIFFICULTY; }
"pixels_"		{ BEGIN(TYPE_OTHER); return DIFFICULTY; }


	/* TYPE_* states for catching the '=' token and go in the right state machine for catching values */
<TYPE_STR>"="{BLANK}*	{ BEGIN(VAL_STR); return AFF; }
<TYPE_OTHER>"="		{ BEGIN(VAL_OTHER); return AFF; }

<TYPE_STR,TYPE_OTHER,VAL_OTHER>{INTEGER}	{ yylval.num = SDL_atoi(yytext); return INT; }
<VAL_OTHER>{INTHEX}	{ int res=SDL_sscanf(yytext, "0x%x", &yylval.uint32); if(res) return INTHEX; else return LEXERROR; }
<VAL_OTHER>{STRCSV}	{ return lexstring(STR); }
<VAL_OTHER>","		{ return VIR; }
<VAL_STR>[^\r\n]+	{ return lexstring(STR); }