Lexer cleanup
[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>
80b07bd7 29#include <ctype.h>
70bd0a12 30#include <babeltrace/babeltrace-internal.h>
34d3acc4 31#include "ctf-scanner.h"
8b9d5b5e
MD
32#include "ctf-parser.h"
33#include "ctf-ast.h"
34
80b07bd7
EB
35#define PARSE_INTEGER_LITERAL(base) \
36 do { \
37 errno = 0; \
38 yylval->ull = strtoull(yytext, NULL, base); \
39 if (errno) { \
40 printfl_perror(yylineno, "Integer literal"); \
41 return ERROR; \
42 } \
43 } while (0)
44
5d6c80a5 45BT_HIDDEN
609bd1bf
MD
46void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
47
48static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
49 __attribute__((unused));
50static int input (yyscan_t yyscanner) __attribute__((unused));
34d3acc4 51
d876a5ba
EB
52BT_HIDDEN
53int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
54
8b9d5b5e
MD
55%}
56
57%x comment_ml comment_sl string_lit char_const
34d3acc4
MD
58%option reentrant yylineno noyywrap bison-bridge
59%option extra-type="struct ctf_scanner *"
60 /* bison-locations */
f3e750bc 61INTEGER_SUFFIX (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
8b9d5b5e
MD
62DIGIT [0-9]
63NONDIGIT [a-zA-Z_]
64HEXDIGIT [0-9A-Fa-f]
65OCTALDIGIT [0-7]
66UCHARLOWERCASE \\u{HEXDIGIT}{4}
67UCHARUPPERCASE \\U{HEXDIGIT}{8}
68ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
69IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
8b9d5b5e
MD
70%%
71
72 /*
73 * Using start conditions to deal with comments
74 * and strings.
75 */
76
77"/*" BEGIN(comment_ml);
78<comment_ml>[^*\n]* /* eat anything that's not a '*' */
79<comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
8c834e5a 80<comment_ml>\n
8b9d5b5e
MD
81<comment_ml>"*"+"/" BEGIN(INITIAL);
82
765f2d8c 83"//"[^\n]*\n /* skip comment */
8b9d5b5e 84
d876a5ba
EB
85L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return ERROR; else return STRING_LITERAL; }
86L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return ERROR; else return CHARACTER_LITERAL; }
8b9d5b5e
MD
87
88"[" return LSBRAC;
89"]" return RSBRAC;
90"(" return LPAREN;
91")" return RPAREN;
92"{" return LBRAC;
93"}" return RBRAC;
94"->" return RARROW;
95"*" return STAR;
96"+" return PLUS;
97"-" return MINUS;
98"<" return LT;
99">" return GT;
100:= return TYPEASSIGN;
101: return COLON;
102; return SEMICOLON;
103"..." return DOTDOTDOT;
104"." return DOT;
105= return EQUAL;
106"," return COMMA;
b7e35bad 107align setstring(yyextra, yylval, yytext); return TOK_ALIGN;
6dc474b8
MD
108const setstring(yyextra, yylval, yytext); return CONST;
109char setstring(yyextra, yylval, yytext); return CHAR;
73d15916 110clock setstring(yyextra, yylval, yytext); return CLOCK;
6dc474b8
MD
111double setstring(yyextra, yylval, yytext); return DOUBLE;
112enum setstring(yyextra, yylval, yytext); return ENUM;
e2c76a4d 113env setstring(yyextra, yylval, yytext); return ENV;
6dc474b8
MD
114event setstring(yyextra, yylval, yytext); return EVENT;
115floating_point setstring(yyextra, yylval, yytext); return FLOATING_POINT;
116float setstring(yyextra, yylval, yytext); return FLOAT;
117integer setstring(yyextra, yylval, yytext); return INTEGER;
118int setstring(yyextra, yylval, yytext); return INT;
119long setstring(yyextra, yylval, yytext); return LONG;
120short setstring(yyextra, yylval, yytext); return SHORT;
121signed setstring(yyextra, yylval, yytext); return SIGNED;
122stream setstring(yyextra, yylval, yytext); return STREAM;
123string setstring(yyextra, yylval, yytext); return STRING;
124struct setstring(yyextra, yylval, yytext); return STRUCT;
125trace setstring(yyextra, yylval, yytext); return TRACE;
f133896d 126callsite setstring(yyextra, yylval, yytext); return CALLSITE;
6dc474b8
MD
127typealias setstring(yyextra, yylval, yytext); return TYPEALIAS;
128typedef setstring(yyextra, yylval, yytext); return TYPEDEF;
129unsigned setstring(yyextra, yylval, yytext); return UNSIGNED;
130variant setstring(yyextra, yylval, yytext); return VARIANT;
131void setstring(yyextra, yylval, yytext); return VOID;
132_Bool setstring(yyextra, yylval, yytext); return _BOOL;
133_Complex setstring(yyextra, yylval, yytext); return _COMPLEX;
134_Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY;
80b07bd7
EB
135[1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return INTEGER_LITERAL;
1360{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return INTEGER_LITERAL;
1370[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return INTEGER_LITERAL;
138
6743f229 139{IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
d4050a69
EB
140[ \t\r\n] ; /* ignore */
141. printfl_error(yylineno, "invalid character '0x%02X'", yytext[0]); return ERROR;
8b9d5b5e 142%%
This page took 0.034383 seconds and 4 git commands to generate.