lib: make public reference count functions have strict types
[babeltrace.git] / plugins / ctf / common / metadata / lexer.l
CommitLineData
e98a2d6e
PP
1%{
2/*
06a626b8 3 * lexer.l
e98a2d6e
PP
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
f73367f8
PP
28#define BT_LOG_TAG "PLUGIN-CTF-METADATA-LEXER"
29#include "logging.h"
30
e98a2d6e
PP
31#include <stdio.h>
32#include <ctype.h>
06a626b8
JG
33#include "scanner.h"
34#include "parser.h"
35#include "ast.h"
e98a2d6e 36
f73367f8
PP
37#define YY_FATAL_ERROR(_msg) BT_LOGF_STR(_msg)
38
e98a2d6e
PP
39#define PARSE_INTEGER_LITERAL(base) \
40 do { \
41 errno = 0; \
42 yylval->ull = strtoull(yytext, NULL, base); \
43 if (errno) { \
f73367f8
PP
44 _BT_LOGE_LINENO(yylineno, \
45 "Cannot parser constant integer: " \
46 "base=%d, text=\"%s\"", base, yytext); \
47 return CTF_ERROR; \
e98a2d6e
PP
48 } \
49 } while (0)
50
51BT_HIDDEN
52void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
53
54static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
55 __attribute__((unused));
56static int input (yyscan_t yyscanner) __attribute__((unused));
57
58BT_HIDDEN
59int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
60
61%}
62
63%x comment_ml comment_sl string_lit char_const
64%option reentrant yylineno noyywrap bison-bridge
65%option extra-type="struct ctf_scanner *"
66 /* bison-locations */
67INTEGER_SUFFIX (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
68DIGIT [0-9]
69NONDIGIT [a-zA-Z_]
70HEXDIGIT [0-9A-Fa-f]
71OCTALDIGIT [0-7]
72UCHARLOWERCASE \\u{HEXDIGIT}{4}
73UCHARUPPERCASE \\U{HEXDIGIT}{8}
74ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
75IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
76%%
77
78 /*
79 * Using start conditions to deal with comments
80 * and strings.
f73367f8 81 */
e98a2d6e
PP
82
83"/*" BEGIN(comment_ml);
84<comment_ml>[^*\n]* /* eat anything that's not a '*' */
85<comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
86<comment_ml>\n
87<comment_ml>"*"+"/" BEGIN(INITIAL);
88
89"//"[^\n]*\n /* skip comment */
90
d4c6eae5
MJ
91L?\"(\\.|[^\\"])*\" { if (import_string(yyextra, yylval, yytext, '\"') < 0) return CTF_ERROR; else return CTF_STRING_LITERAL; }
92L?\'(\\.|[^\\'])*\' { if (import_string(yyextra, yylval, yytext, '\'') < 0) return CTF_ERROR; else return CTF_CHARACTER_LITERAL; }
e98a2d6e 93
d4c6eae5
MJ
94"[" return CTF_LSBRAC;
95"]" return CTF_RSBRAC;
96"(" return CTF_LPAREN;
97")" return CTF_RPAREN;
98"{" return CTF_LBRAC;
99"}" return CTF_RBRAC;
100"->" return CTF_RARROW;
101"*" return CTF_STAR;
102"+" return CTF_PLUS;
103"-" return CTF_MINUS;
104"<" return CTF_LT;
105">" return CTF_GT;
106:= return CTF_TYPEASSIGN;
107: return CTF_COLON;
108; return CTF_SEMICOLON;
109"..." return CTF_DOTDOTDOT;
110"." return CTF_DOT;
111= return CTF_EQUAL;
112"," return CTF_COMMA;
113align setstring(yyextra, yylval, yytext); return CTF_TOK_ALIGN;
114const setstring(yyextra, yylval, yytext); return CTF_CONST;
115char setstring(yyextra, yylval, yytext); return CTF_CHAR;
116clock setstring(yyextra, yylval, yytext); return CTF_CLOCK;
117double setstring(yyextra, yylval, yytext); return CTF_DOUBLE;
118enum setstring(yyextra, yylval, yytext); return CTF_ENUM;
119env setstring(yyextra, yylval, yytext); return CTF_ENV;
120event setstring(yyextra, yylval, yytext); return CTF_EVENT;
121floating_point setstring(yyextra, yylval, yytext); return CTF_FLOATING_POINT;
122float setstring(yyextra, yylval, yytext); return CTF_FLOAT;
123integer setstring(yyextra, yylval, yytext); return CTF_INTEGER;
124int setstring(yyextra, yylval, yytext); return CTF_INT;
125long setstring(yyextra, yylval, yytext); return CTF_LONG;
126short setstring(yyextra, yylval, yytext); return CTF_SHORT;
127signed setstring(yyextra, yylval, yytext); return CTF_SIGNED;
128stream setstring(yyextra, yylval, yytext); return CTF_STREAM;
129string setstring(yyextra, yylval, yytext); return CTF_STRING;
130struct setstring(yyextra, yylval, yytext); return CTF_STRUCT;
131trace setstring(yyextra, yylval, yytext); return CTF_TRACE;
132callsite setstring(yyextra, yylval, yytext); return CTF_CALLSITE;
133typealias setstring(yyextra, yylval, yytext); return CTF_TYPEALIAS;
134typedef setstring(yyextra, yylval, yytext); return CTF_TYPEDEF;
135unsigned setstring(yyextra, yylval, yytext); return CTF_UNSIGNED;
136variant setstring(yyextra, yylval, yytext); return CTF_VARIANT;
137void setstring(yyextra, yylval, yytext); return CTF_VOID;
138_Bool setstring(yyextra, yylval, yytext); return CTF_BOOL;
139_Complex setstring(yyextra, yylval, yytext); return CTF_COMPLEX;
140_Imaginary setstring(yyextra, yylval, yytext); return CTF_IMAGINARY;
141[1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return CTF_INTEGER_LITERAL;
1420{OCTALDIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(8); return CTF_INTEGER_LITERAL;
1430[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(16); return CTF_INTEGER_LITERAL;
e98a2d6e 144
f73367f8 145{IDENTIFIER} BT_LOGV("Got identifier: id=\"%s\"", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
e98a2d6e 146[ \t\r\n] ; /* ignore */
f73367f8 147. _BT_LOGE_LINENO(yylineno, "Invalid character: char=\"%c\", val=0x%02x", isprint(yytext[0]) ? yytext[0] : '\0', yytext[0]); return CTF_ERROR;
e98a2d6e 148%%
This page took 0.041421 seconds and 4 git commands to generate.