e11fcf49aa2398712e878a2036e44c371c3c8f2e
[awesomized/libmemcached] / libmemcached / options / scanner.l
1
2 %top{
3
4 #pragma GCC diagnostic ignored "-Wold-style-cast"
5 #pragma GCC diagnostic ignored "-Wunused-parameter"
6 #pragma GCC diagnostic ignored "-fpermissive"
7
8 #include <libmemcached/options/parser.h>
9 #include <libmemcached/options/string.h>
10 #include <libmemcached/options/symbol.h>
11 #include <libmemcached/options/type.h>
12
13 }
14
15
16 %{
17 #include <cstdlib>
18 #include <cstring>
19
20 #define PARAM yyget_extra(yyscanner)
21
22 static void get_lex_chars(char* buffer, int& result, int max_size, struct type_st *parser)
23 {
24 if (parser->pos >= parser->length)
25 {
26 result = YY_NULL;
27 }
28 else
29 {
30 result = parser->length - parser->pos;
31 result > (int)max_size ? result = max_size : 0;
32 memcpy(buffer, parser->buf + parser->pos, result);
33 parser->pos += result;
34 }
35 }
36
37
38 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
39
40 %}
41
42 %option bison-locations
43 %option bison-bridge
44 %option case-insensitive
45 %option debug
46 %option nounput
47 %option noyywrap
48 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
49 %option perf-report
50 %option prefix="libmemcached_"
51 %option reentrant
52
53 %%
54
55 [=] { return EQ; }
56 [,] { return COMMA; }
57
58 [0-9]+ { yylval->number = atoi(yytext); return (NUMBER); }
59
60 ([0-9]*.[0-9]+) { yylval->double_number = atof(yytext); return (FLOAT); }
61
62 [ \t\r\n] ; /* skip whitespace */
63
64 "--SERVER" { return SERVER; }
65 "--SERVERS" { return SERVERS; }
66 "--TCP_NODELAY" { return TCPNODELAY; }
67 "--TCP-NODELAY" { return TCPNODELAY; }
68 "--VERIFY_KEY" { return VERIFY_KEY; }
69 "--VERIFY-KEY" { return VERIFY_KEY; }
70
71 [A-Za-z][A-Za-z0-9_]*[:] {
72 yylval->string.c_str = yytext;
73 yylval->string.length = yyleng;
74 return SERVER_WITH_PORT;
75 }
76
77 [A-Za-z][A-Za-z0-9_]* {
78 yylval->string.c_str = yytext;
79 yylval->string.length = yyleng;
80 return IDENTIFIER;
81 }
82 [-] ;
83
84 . {
85 std::cerr << "Near " << yytext << std::endl;
86 return UNKNOWN;
87 }
88
89 %%