5 * Common Trace Formal Lexer
7 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
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
30 #include <babeltrace/babeltrace-internal.h>
31 #include "ctf-scanner.h"
32 #include "ctf-parser.h"
35 #define PARSE_INTEGER_LITERAL(base) \
38 yylval->ull = strtoull(yytext, NULL, base); \
40 printfl_perror(yylineno, "Integer literal"); \
46 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
48 static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
49 __attribute__((unused));
50 static int input (yyscan_t yyscanner) __attribute__((unused));
53 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
57 %x comment_ml comment_sl string_lit char_const
58 %option reentrant yylineno noyywrap bison-bridge
59 %option extra-type="struct ctf_scanner *"
61 INTEGER_SUFFIX [ \r\n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
66 UCHARLOWERCASE \\u{HEXDIGIT}{4}
67 UCHARUPPERCASE \\U{HEXDIGIT}{8}
68 ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
69 IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
73 * Using start conditions to deal with comments
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 */
81 <comment_ml>"*"+"/" BEGIN(INITIAL);
83 "//" BEGIN(comment_sl);
84 <comment_sl>[^\n]*\n BEGIN(INITIAL);
86 L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return ERROR; else return STRING_LITERAL; }
87 L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return ERROR; else return CHARACTER_LITERAL; }
101 := return TYPEASSIGN;
104 "..." return DOTDOTDOT;
108 align setstring(yyextra, yylval, yytext); return TOK_ALIGN;
109 const setstring(yyextra, yylval, yytext); return CONST;
110 char setstring(yyextra, yylval, yytext); return CHAR;
111 clock setstring(yyextra, yylval, yytext); return CLOCK;
112 double setstring(yyextra, yylval, yytext); return DOUBLE;
113 enum setstring(yyextra, yylval, yytext); return ENUM;
114 env setstring(yyextra, yylval, yytext); return ENV;
115 event setstring(yyextra, yylval, yytext); return EVENT;
116 floating_point setstring(yyextra, yylval, yytext); return FLOATING_POINT;
117 float setstring(yyextra, yylval, yytext); return FLOAT;
118 integer setstring(yyextra, yylval, yytext); return INTEGER;
119 int setstring(yyextra, yylval, yytext); return INT;
120 long setstring(yyextra, yylval, yytext); return LONG;
121 short setstring(yyextra, yylval, yytext); return SHORT;
122 signed setstring(yyextra, yylval, yytext); return SIGNED;
123 stream setstring(yyextra, yylval, yytext); return STREAM;
124 string setstring(yyextra, yylval, yytext); return STRING;
125 struct setstring(yyextra, yylval, yytext); return STRUCT;
126 trace setstring(yyextra, yylval, yytext); return TRACE;
127 callsite setstring(yyextra, yylval, yytext); return CALLSITE;
128 typealias setstring(yyextra, yylval, yytext); return TYPEALIAS;
129 typedef setstring(yyextra, yylval, yytext); return TYPEDEF;
130 unsigned setstring(yyextra, yylval, yytext); return UNSIGNED;
131 variant setstring(yyextra, yylval, yytext); return VARIANT;
132 void setstring(yyextra, yylval, yytext); return VOID;
133 _Bool setstring(yyextra, yylval, yytext); return _BOOL;
134 _Complex setstring(yyextra, yylval, yytext); return _COMPLEX;
135 _Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY;
136 [1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return INTEGER_LITERAL;
137 0{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return INTEGER_LITERAL;
138 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return INTEGER_LITERAL;
140 {IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
141 [ \t\r\n] ; /* ignore */
142 . printfl_error(yylineno, "invalid character '0x%02X'", yytext[0]); return ERROR;