summaryrefslogtreecommitdiffstats
path: root/src/args-flex.l
blob: e00b619a4fb89964fea43c622fe56e31f46f97d7 (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
/*
  Copyright (C) 2008, 2009 Jiri Olsa <olsajiri@gmail.com>

  This file is part of the latrace.

  The latrace is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  The latrace is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with the latrace (file COPYING).  If not, see 
  <http://www.gnu.org/licenses/>.
*/


%{

#include <string.h>

#include "config.h"
#include "args-bison.h"

struct lt_args_include* lt_args_buf_get(void);

%}

alphnum		[-0-9a-zA-Z_]
name		({alphnum})+
filename	([-0-9a-zA-Z\./_])+

%x comment include
%%

"/*"			BEGIN(comment);
<comment>[^*\n]*	/* eat anything that's not a '*' */
<comment>"*"+[^*/\n]*	/* eat up '*'s not followed by '/'s */
<comment>\n		{ lt_args_buf_get()->lineno++; }
<comment>"*"+"/"	BEGIN(INITIAL);

"#include"		{ BEGIN(include); return INCLUDE; }
<include>{filename}	{ yylval.s = strdup(yytext); return FILENAME; } 
<include>"\""		{ return '"'; }
<include>\n		{ BEGIN(INITIAL); }
<include>.		{ ; }

"extern"		{ ; }
"const"			{ ; }
<<EOF>>			{ return END; }
"struct"		{ return STRUCT; }
"enum"			{ return ENUM; }
"typedef"		{ return TYPEDEF; }
{name}			{ yylval.s = strdup(yytext); return NAME; }   
"\*"+			{ return POINTER; }
")"			{ return ')'; }
"("			{ return '('; }
"}"			{ return '}'; }
"{"			{ return '{'; }
";"			{ return ';'; }
","			{ return ','; }
"="			{ return '='; }
\			{ ; }
\n			{ lt_args_buf_get()->lineno++; }
.			{ ; }

%%

#ifndef yywrap
int yywrap()
{
	return 1; 
	/* XXX not to get the compiler 'not used' warning */
	yyunput(0, NULL); 
	input();
}
#endif

void yyerror(const char *m)
{
	printf("latrace config file [%s] line %d: %s\n", 
		lt_args_buf_get()->file, 
		lt_args_buf_get()->lineno, 
		m); 
}