Implement filter expression to bytecode compiler in liblttng-ctl
[lttng-tools.git] / src / lib / lttng-ctl / filter-lexer.l
1 %{
2 /*
3 * filter-lexer.l
4 *
5 * LTTng filter lexer
6 *
7 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License, version 2.1 only,
11 * as published by the Free Software Foundation.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 */
18
19 #include <stdio.h>
20 #include "filter-ast.h"
21 #include "filter-parser.h"
22
23 extern
24 void setstring(struct filter_parser_ctx *parser_ctx, YYSTYPE *lvalp, const char *src);
25
26 static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
27 __attribute__((unused));
28 static int input (yyscan_t yyscanner) __attribute__((unused));
29
30 %}
31
32 %x comment_ml comment_sl string_lit char_const
33 %option reentrant yylineno noyywrap bison-bridge
34 %option extra-type="struct filter_parser_ctx *"
35 /* bison-locations */
36 INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
37 DIGIT [0-9]
38 NONDIGIT [a-zA-Z_]
39 HEXDIGIT [0-9A-Fa-f]
40 OCTALDIGIT [0-7]
41 UCHARLOWERCASE \\u{HEXDIGIT}{4}
42 UCHARUPPERCASE \\U{HEXDIGIT}{8}
43 ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
44 IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
45 ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+)
46 %%
47
48 /*
49 * Using start conditions to deal with comments
50 * and strings.
51 */
52
53 "/*" BEGIN(comment_ml);
54 <comment_ml>[^*\n]* /* eat anything that's not a '*' */
55 <comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
56 <comment_ml>\n ++yylineno;
57 <comment_ml>"*"+"/" BEGIN(INITIAL);
58
59 "//" BEGIN(comment_sl);
60 <comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL);
61
62 L\' BEGIN(char_const); return CHARACTER_CONSTANT_START;
63 \' BEGIN(char_const); return CHARACTER_CONSTANT_START;
64 <char_const>\' BEGIN(INITIAL); return SQUOTE;
65
66 L\" BEGIN(string_lit); return STRING_LITERAL_START;
67 \" BEGIN(string_lit); return STRING_LITERAL_START;
68 <string_lit>\" BEGIN(INITIAL); return DQUOTE;
69
70 <char_const,string_lit>ESCSEQ return ESCSEQ;
71 <char_const,string_lit>\n ; /* ignore */
72 <char_const,string_lit>. setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN;
73
74 "[" return LSBRAC;
75 "]" return RSBRAC;
76 "(" return LPAREN;
77 ")" return RPAREN;
78 "{" return LBRAC;
79 "}" return RBRAC;
80 "->" return RARROW;
81
82 "*" return STAR;
83 "+" return PLUS;
84 "-" return MINUS;
85
86 "%" return MOD_OP;
87 "/" return DIV_OP;
88 ">>" return RIGHT_OP;
89 "<<" return LEFT_OP;
90
91 "==" return EQ_OP;
92 "!=" return NE_OP;
93 "<=" return LE_OP;
94 ">=" return GE_OP;
95 "<" return LT_OP;
96 ">" return GT_OP;
97 "&&" return AND_OP;
98 "||" return OR_OP;
99 "!" return NOT_OP;
100
101 ":=" return ASSIGN;
102 ":" return COLON;
103 ";" return SEMICOLON;
104 "..." return DOTDOTDOT;
105 "." return DOT;
106 "=" return EQUAL;
107 "," return COMMA;
108 "^" return XOR_BIN;
109 "&" return AND_BIN;
110 "|" return OR_BIN;
111 "~" return NOT_BIN;
112 [1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT;
113 0{OCTALDIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT;
114 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT;
115 {IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); return IDENTIFIER;
116 [ \t\n]+ ; /* ignore */
117 . return ERROR;
118 %%
This page took 0.031199 seconds and 4 git commands to generate.