Support escape characters in metadata strings
[babeltrace.git] / formats / ctf / metadata / ctf-lexer.l
CommitLineData
8b9d5b5e 1%{
c59a87f5
MD
2/*
3 * ctf-lexer.l
4 *
5 * Common Trace Formal Lexer
6 *
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
c462e188
MD
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
c59a87f5
MD
26 */
27
8b9d5b5e 28#include <stdio.h>
70bd0a12 29#include <babeltrace/babeltrace-internal.h>
34d3acc4 30#include "ctf-scanner.h"
8b9d5b5e
MD
31#include "ctf-parser.h"
32#include "ctf-ast.h"
33
5d6c80a5 34BT_HIDDEN
609bd1bf
MD
35void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
36
37static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
38 __attribute__((unused));
39static int input (yyscan_t yyscanner) __attribute__((unused));
34d3acc4 40
d876a5ba
EB
41BT_HIDDEN
42int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
43
8b9d5b5e
MD
44%}
45
46%x comment_ml comment_sl string_lit char_const
34d3acc4
MD
47%option reentrant yylineno noyywrap bison-bridge
48%option extra-type="struct ctf_scanner *"
49 /* bison-locations */
8b9d5b5e
MD
50INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
51DIGIT [0-9]
52NONDIGIT [a-zA-Z_]
53HEXDIGIT [0-9A-Fa-f]
54OCTALDIGIT [0-7]
55UCHARLOWERCASE \\u{HEXDIGIT}{4}
56UCHARUPPERCASE \\U{HEXDIGIT}{8}
57ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
58IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
8b9d5b5e
MD
59%%
60
61 /*
62 * Using start conditions to deal with comments
63 * and strings.
64 */
65
66"/*" BEGIN(comment_ml);
67<comment_ml>[^*\n]* /* eat anything that's not a '*' */
68<comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
8c834e5a 69<comment_ml>\n
8b9d5b5e
MD
70<comment_ml>"*"+"/" BEGIN(INITIAL);
71
72"//" BEGIN(comment_sl);
8c834e5a 73<comment_sl>[^\n]*\n BEGIN(INITIAL);
8b9d5b5e 74
d876a5ba
EB
75L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return ERROR; else return STRING_LITERAL; }
76L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return ERROR; else return CHARACTER_LITERAL; }
8b9d5b5e
MD
77
78"[" return LSBRAC;
79"]" return RSBRAC;
80"(" return LPAREN;
81")" return RPAREN;
82"{" return LBRAC;
83"}" return RBRAC;
84"->" return RARROW;
85"*" return STAR;
86"+" return PLUS;
87"-" return MINUS;
88"<" return LT;
89">" return GT;
90:= return TYPEASSIGN;
91: return COLON;
92; return SEMICOLON;
93"..." return DOTDOTDOT;
94"." return DOT;
95= return EQUAL;
96"," return COMMA;
b7e35bad 97align setstring(yyextra, yylval, yytext); return TOK_ALIGN;
6dc474b8
MD
98const setstring(yyextra, yylval, yytext); return CONST;
99char setstring(yyextra, yylval, yytext); return CHAR;
73d15916 100clock setstring(yyextra, yylval, yytext); return CLOCK;
6dc474b8
MD
101double setstring(yyextra, yylval, yytext); return DOUBLE;
102enum setstring(yyextra, yylval, yytext); return ENUM;
e2c76a4d 103env setstring(yyextra, yylval, yytext); return ENV;
6dc474b8
MD
104event setstring(yyextra, yylval, yytext); return EVENT;
105floating_point setstring(yyextra, yylval, yytext); return FLOATING_POINT;
106float setstring(yyextra, yylval, yytext); return FLOAT;
107integer setstring(yyextra, yylval, yytext); return INTEGER;
108int setstring(yyextra, yylval, yytext); return INT;
109long setstring(yyextra, yylval, yytext); return LONG;
110short setstring(yyextra, yylval, yytext); return SHORT;
111signed setstring(yyextra, yylval, yytext); return SIGNED;
112stream setstring(yyextra, yylval, yytext); return STREAM;
113string setstring(yyextra, yylval, yytext); return STRING;
114struct setstring(yyextra, yylval, yytext); return STRUCT;
115trace setstring(yyextra, yylval, yytext); return TRACE;
f133896d 116callsite setstring(yyextra, yylval, yytext); return CALLSITE;
6dc474b8
MD
117typealias setstring(yyextra, yylval, yytext); return TYPEALIAS;
118typedef setstring(yyextra, yylval, yytext); return TYPEDEF;
119unsigned setstring(yyextra, yylval, yytext); return UNSIGNED;
120variant setstring(yyextra, yylval, yytext); return VARIANT;
121void setstring(yyextra, yylval, yytext); return VOID;
122_Bool setstring(yyextra, yylval, yytext); return _BOOL;
123_Complex setstring(yyextra, yylval, yytext); return _COMPLEX;
124_Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY;
125[1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT;
1260{OCTALDIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT;
1270[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT;
6743f229 128{IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
d4050a69
EB
129[ \t\r\n] ; /* ignore */
130. printfl_error(yylineno, "invalid character '0x%02X'", yytext[0]); return ERROR;
8b9d5b5e 131%%
This page took 0.033344 seconds and 4 git commands to generate.