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 (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 "//"[^\n]*\n /* skip comment */
85 L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return ERROR; else return STRING_LITERAL; }
86 L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return ERROR; else return CHARACTER_LITERAL; }
100 := return TYPEASSIGN;
103 "..." return DOTDOTDOT;
107 align setstring(yyextra, yylval, yytext); return TOK_ALIGN;
108 const setstring(yyextra, yylval, yytext); return CONST;
109 char setstring(yyextra, yylval, yytext); return CHAR;
110 clock setstring(yyextra, yylval, yytext); return CLOCK;
111 double setstring(yyextra, yylval, yytext); return DOUBLE;
112 enum setstring(yyextra, yylval, yytext); return ENUM;
113 env setstring(yyextra, yylval, yytext); return ENV;
114 event setstring(yyextra, yylval, yytext); return EVENT;
115 floating_point setstring(yyextra, yylval, yytext); return FLOATING_POINT;
116 float setstring(yyextra, yylval, yytext); return FLOAT;
117 integer setstring(yyextra, yylval, yytext); return INTEGER;
118 int setstring(yyextra, yylval, yytext); return INT;
119 long setstring(yyextra, yylval, yytext); return LONG;
120 short setstring(yyextra, yylval, yytext); return SHORT;
121 signed setstring(yyextra, yylval, yytext); return SIGNED;
122 stream setstring(yyextra, yylval, yytext); return STREAM;
123 string setstring(yyextra, yylval, yytext); return STRING;
124 struct setstring(yyextra, yylval, yytext); return STRUCT;
125 trace setstring(yyextra, yylval, yytext); return TRACE;
126 callsite setstring(yyextra, yylval, yytext); return CALLSITE;
127 typealias setstring(yyextra, yylval, yytext); return TYPEALIAS;
128 typedef setstring(yyextra, yylval, yytext); return TYPEDEF;
129 unsigned setstring(yyextra, yylval, yytext); return UNSIGNED;
130 variant setstring(yyextra, yylval, yytext); return VARIANT;
131 void 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;
135 [1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return INTEGER_LITERAL;
136 0{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return INTEGER_LITERAL;
137 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return INTEGER_LITERAL;
139 {IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
140 [ \t\r\n] ; /* ignore */
141 . printfl_error(yylineno, "invalid character '0x%02X'", yytext[0]); return ERROR;