Lexer cleanup
[babeltrace.git] / formats / ctf / metadata / ctf-lexer.l
1 %{
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.
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.
26 */
27
28 #include <stdio.h>
29 #include <ctype.h>
30 #include <babeltrace/babeltrace-internal.h>
31 #include "ctf-scanner.h"
32 #include "ctf-parser.h"
33 #include "ctf-ast.h"
34
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
45 BT_HIDDEN
46 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
47
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));
51
52 BT_HIDDEN
53 int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
54
55 %}
56
57 %x comment_ml comment_sl string_lit char_const
58 %option reentrant yylineno noyywrap bison-bridge
59 %option extra-type="struct ctf_scanner *"
60 /* bison-locations */
61 INTEGER_SUFFIX (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
62 DIGIT [0-9]
63 NONDIGIT [a-zA-Z_]
64 HEXDIGIT [0-9A-Fa-f]
65 OCTALDIGIT [0-7]
66 UCHARLOWERCASE \\u{HEXDIGIT}{4}
67 UCHARUPPERCASE \\U{HEXDIGIT}{8}
68 ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
69 IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
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 */
80 <comment_ml>\n
81 <comment_ml>"*"+"/" BEGIN(INITIAL);
82
83 "//"[^\n]*\n /* skip comment */
84
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; }
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;
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;
138
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;
142 %%
This page took 0.033435 seconds and 4 git commands to generate.