Merge in new scanner/parser suite with updated test cases.
[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
56 =|, { return yytext[0];}
57
58
59 [[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
60
61 ([[:digit:]]*.[:digit:]+) { yylval->double_number = atof(yytext); return (FLOAT); }
62
63 [ \t\r\n] ; /* skip whitespace */
64
65 "--SERVER" { return SERVER; }
66 "--SERVERS" { return SERVERS; }
67 "--TCP_NODELAY" { return TCPNODELAY; }
68 "--TCP-NODELAY" { return TCPNODELAY; }
69 "--VERIFY_KEY" { return VERIFY_KEY; }
70 "--VERIFY-KEY" { return VERIFY_KEY; }
71
72 [[:alnum:]][[:alnum:].]*[[:alpha:]]: {
73 yylval->string.c_str = yytext;
74 yylval->string.length = yyleng;
75 return SERVER_WITH_PORT;
76 }
77
78 [[:alnum:]][[:alnum:].]*[[:alpha:]] {
79 yylval->string.c_str = yytext;
80 yylval->string.length = yyleng;
81 return IDENTIFIER;
82 }
83 [[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}: {
84 yylval->string.c_str = yytext;
85 yylval->string.length = yyleng;
86 return IPADDRESS_WITH_PORT;
87 }
88
89 [[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3} {
90 yylval->string.c_str = yytext;
91 yylval->string.length = yyleng;
92 return IPADDRESS;
93 }
94
95 . {
96 std::cerr << "Near " << yytext << std::endl;
97 return UNKNOWN;
98 }
99
100 %%