-
Notifications
You must be signed in to change notification settings - Fork 13
/
query-parser.lex
48 lines (35 loc) · 1.08 KB
/
query-parser.lex
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
%{
#include <string.h>
#include "whistlepig.h"
#include "query-parser.h"
#include "query-parser.tab.h"
#define YY_EXTRA_TYPE query_parse_context*
#define YY_USER_ACTION yylloc->first_line = yylineno;
#define YY_INPUT(buf,result,max_size) \
{ \
if(yyextra->input[0] == 0) \
result = YY_NULL; \
else { \
buf[0] = yyextra->input[0]; \
yyextra->input++; \
result = 1; \
} \
}
%}
%option 8bit reentrant fast noyywrap yylineno
%option outfile="query-parser.lex.c" header-file="query-parser.lex.h"
%option prefix="query_parser_"
%option bison-bridge bison-locations
/* for the first char, everything is allowed except ()"-~:* */
FIRSTWORDCHAR [^\n[:blank:]()"~:\*-]
/* inside a word, everything is allowed except ()": */
INNERWORDCHAR [^\n[:blank:]()":]
%%
OR return OR;
{FIRSTWORDCHAR}{INNERWORDCHAR}* {
yylval->string = strdup(yytext);
return WORD;
}
[\n[:blank:]] ; // nothing
. return yytext[0];
%%