]> jfr.im git - irc/quakenet/newserv.git/blame - newsearch/newsearch.l
LUA: port luadb to dbapi2 to drop postgres dependency
[irc/quakenet/newserv.git] / newsearch / newsearch.l
CommitLineData
ffc11f03
CP
1%option noyywrap
2
3%{
946729bd 4
9b276ca6
CP
5#include <stdlib.h>
6#include <string.h>
06b41527
CP
7#ifndef __POSIX_VISIBLE
8#define fileno(x) 0
9#endif
9b276ca6 10
e828314e 11#include "../lib/sstring.h"
ffc11f03 12
e828314e 13#define YYSTYPE sstring *
ffc11f03
CP
14extern YYSTYPE yylval;
15
e828314e 16#include "y.tab.h"
ffc11f03
CP
17#include "../lib/stringbuf.h"
18
19#define MAX_STR_CONST 512
e828314e 20
9b276ca6
CP
21int lexpos, lexerror;
22
23#define addpos(x) lexpos+=x;
24#define incpos() addpos(1);
25
26void lexreset(void) {
27 lexerror = 0;
28 lexpos = -1;
29}
30
ffc11f03
CP
31%}
32
33digit [0-9]
34letter [a-zA-Z]
35
4324be96 36%x str pascalstr
ffc11f03
CP
37%%
38
39 char bufdata[MAX_STR_CONST];
40 StringBuf buf;
41
9b276ca6 42\" { incpos();
ffc11f03
CP
43 sbinit(&buf, bufdata, sizeof(bufdata));
44 BEGIN(str);
45 }
46
47<str>{
9b276ca6 48 \" { incpos();
ffc11f03
CP
49 BEGIN(INITIAL);
50 sbterminate(&buf);
e828314e 51 yylval = getsstring(bufdata, 512);
ffc11f03
CP
52 return STRING;
53 }
9b276ca6
CP
54 \\\\ { addpos(2);
55 sbaddchar(&buf, '\\');
56 }
57 \\\" { addpos(2);
58 sbaddchar(&buf, '"');
59 }
60 [^\\] { incpos();
61 sbaddchar(&buf, *yytext);
62 }
ffc11f03
CP
63}
64
9b276ca6 65\' { incpos();
4324be96
CP
66 sbinit(&buf, bufdata, sizeof(bufdata));
67 BEGIN(pascalstr);
68 }
69
70<pascalstr>{
9b276ca6
CP
71 \'\' { addpos(2);
72 sbaddchar(&buf, '\'');
73 }
74 \' { incpos();
4324be96
CP
75 BEGIN(INITIAL);
76 sbterminate(&buf);
77 yylval = getsstring(bufdata, 512);
78 return STRING;
79 }
9b276ca6
CP
80 . { incpos();
81 sbaddchar(&buf, *yytext);
82 }
4324be96
CP
83}
84
9b276ca6
CP
85"(" { incpos();
86 return LPAREN;
87 }
88")" { incpos();
89 return RPAREN;
90 }
91[ \t]+ { addpos(strlen(yytext));
92 return WHITESPACE;
93 }
dd7fb4db 94({letter}|{digit}|[#\-\+\.\*])+ { addpos(strlen(yytext));
e828314e 95 yylval = getsstring(yytext, 512);
ffc11f03
CP
96 return IDENTIFIER;
97 }
98
9b276ca6
CP
99[\n\r] { incpos();
100 /* ignore */;
101 }
102
103. {
104 incpos();
105 lexerror = 1;
106 yyterminate();
107 }
ffc11f03
CP
108
109<<EOF>> {
110 BEGIN(INITIAL);
111 yyterminate();
112 }
113%%
946729bd
CP
114
115void ydummyfn(void) {
116 yyunput(0, NULL);
117}