aboutsummaryrefslogtreecommitdiff
path: root/src/build.l
blob: a88f90dc41e6c022344ccf57b0c8e2e4a9e88324 (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
%{
# include <string>
# include "builder.h"
# include "build.tab.h"
# include "stringrep.h"

std::string strbuf;
%}

%x regexp
%x strsq
%x strdq
%x comment
%option noyywrap nounput batch debug

%{
//# define YY_USER_ACTION  yylloc->columns (yyleng);
%}
%%

[,:=]								return yytext[0];
"+="								return TOK_ADDSET;

"default"							return TOK_DEFAULT;
"action"							return TOK_ACTION;
"create"							return TOK_CREATE;
"file"								return TOK_FILE;
"from"								return TOK_FROM;
"files"								return TOK_FILES;
"in"								return TOK_IN;
"using"								return TOK_USING;
"rule"								return TOK_RULE;
"requires"							return TOK_REQUIRES;
"for"								return TOK_FOR;
"set"								return TOK_SET;
"matches"							return TOK_MATCHES;
"all"								return TOK_ALL;
"one"								return TOK_ONE;
"perform"							return TOK_PERFORM;
"produces"							return TOK_PRODUCES;
"command"							return TOK_COMMAND;
"check"								return TOK_CHECK;

"..."\n								/* elipsis line continuation */
\n+									return TOK_EOL;
[ \t\r]*							/* whitespace */

"/"									{
	BEGIN( regexp );
	strbuf = "";
}
<regexp>[^\n/]*						strbuf += yytext;
<regexp>"/"							{
	BEGIN( INITIAL );
	yylval->strval = stringdup( strbuf.c_str() );
	return REGEXP;
}

"#".*								/* single line comment */

[^ \t\r\n\'\":=,/][^ \t\r\n\'\":=,]*						{
	yylval->strval = stringdup( yytext );
	return STRING;
}

\"									{
	BEGIN( strdq );
	strbuf = "";
}
\'									{
	BEGIN( strsq );
	strbuf = "";
}

<strdq>[^\\\n\"]+					{
	strbuf += yytext;
}

<strsq>[^\\\n\']+					{
	strbuf += yytext;
}

<strdq,strsq>\\n					strbuf += "\n";
<strdq,strsq>\\t					strbuf += "\t";
<strdq,strsq>\\r					strbuf += "\r";
<strdq,strsq>\\b					strbuf += "\b";
<strdq,strsq>\\f					strbuf += "\f";

<strdq>\"							{
	BEGIN( INITIAL );
	yylval->strval = stringdup( strbuf.c_str() );
	return STRING;
}

<strsq>\'							{
	BEGIN( INITIAL );
	yylval->strval = stringdup( strbuf.c_str() );
	return STRING;
}

%%

void Builder::scanBegin()
{
	yy_flex_debug = false;
	if( !(yyin = fopen( file.c_str(), "r" )) )
		fprintf( stderr, "cannot open %s\n", file.c_str() );
}

void Builder::scanEnd()
{
	fclose( yyin );
}