blob: b35d6bd26d2b7cc24ba4f4bf967f55005323279f (
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
|
%option prefix="flb_ra_"
%option caseless
%{
#include <stdio.h>
#include <stdbool.h>
#include <fluent-bit/flb_str.h>
#include <fluent-bit/flb_log.h>
#include <fluent-bit/record_accessor/flb_ra_parser.h>
#include "ra_parser.h"
static inline char *remove_dup_quotes(const char *s, size_t n)
{
char *str;
int dups;
int i, j;
dups = 0;
for (i = 0; i < n; i++) {
if (s[i] == '\'') {
dups++;
i++;
}
}
str = (char *) flb_malloc(n - dups + 1);
if (!str) {
return NULL;
}
j = 0;
for (i = 0; i < n; i++, j++) {
if (s[i] == '\'') {
str[j] = '\'';
i++;
} else {
str[j] = s[i];
}
}
str[j] = '\0';
return str;
}
%}
%option 8bit reentrant bison-bridge
%option warn noyywrap nodefault
%option nounput
%option noinput
%%
[1-9][0-9]*|0 { yylval->integer = atoi(yytext); return INTEGER; }
\'([^']|'{2})*\' { yylval->string = remove_dup_quotes(yytext + 1, yyleng - 2); return STRING; }
[_A-Za-z][A-Za-z0-9_.\-/]* { yylval->string = flb_strdup(yytext); return IDENTIFIER; }
"$" |
"[" |
"]" |
"." |
"," |
";" { return yytext[0]; }
\n
[ \t]+ /* ignore whitespace */;
. flb_error("[record accessor] bad input character '%s' at line %d", yytext, yylineno);
%%
|