Commit | Line | Data |
---|---|---|
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 | 45 | BT_HIDDEN |
609bd1bf MD |
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)); | |
34d3acc4 | 51 | |
d876a5ba EB |
52 | BT_HIDDEN |
53 | int 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 | 61 | INTEGER_SUFFIX (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu) |
8b9d5b5e MD |
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})* | |
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 |
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; } | |
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 | 107 | align setstring(yyextra, yylval, yytext); return TOK_ALIGN; |
6dc474b8 MD |
108 | const setstring(yyextra, yylval, yytext); return CONST; |
109 | char setstring(yyextra, yylval, yytext); return CHAR; | |
73d15916 | 110 | clock setstring(yyextra, yylval, yytext); return CLOCK; |
6dc474b8 MD |
111 | double setstring(yyextra, yylval, yytext); return DOUBLE; |
112 | enum setstring(yyextra, yylval, yytext); return ENUM; | |
e2c76a4d | 113 | env setstring(yyextra, yylval, yytext); return ENV; |
6dc474b8 MD |
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; | |
f133896d | 126 | callsite setstring(yyextra, yylval, yytext); return CALLSITE; |
6dc474b8 MD |
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; | |
80b07bd7 EB |
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 | ||
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 | %% |