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.
21 #include <babeltrace/babeltrace-internal.h>
22 #include "ctf-scanner.h"
23 #include "ctf-parser.h"
27 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
29 static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
30 __attribute__((unused));
31 static int input (yyscan_t yyscanner) __attribute__((unused));
34 const char *rem_(const char *str)
44 %x comment_ml comment_sl string_lit char_const
45 %option reentrant yylineno noyywrap bison-bridge
46 %option extra-type="struct ctf_scanner *"
48 INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
53 UCHARLOWERCASE \\u{HEXDIGIT}{4}
54 UCHARUPPERCASE \\U{HEXDIGIT}{8}
55 ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
56 IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
57 ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+)
61 * Using start conditions to deal with comments
65 "/*" BEGIN(comment_ml);
66 <comment_ml>[^*\n]* /* eat anything that's not a '*' */
67 <comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
68 <comment_ml>\n ++yylineno;
69 <comment_ml>"*"+"/" BEGIN(INITIAL);
71 "//" BEGIN(comment_sl);
72 <comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL);
74 L\' BEGIN(char_const); return CHARACTER_CONSTANT_START;
75 \' BEGIN(char_const); return CHARACTER_CONSTANT_START;
76 <char_const>\' BEGIN(INITIAL); return SQUOTE;
78 L\" BEGIN(string_lit); return STRING_LITERAL_START;
79 \" BEGIN(string_lit); return STRING_LITERAL_START;
80 <string_lit>\" BEGIN(INITIAL); return DQUOTE;
82 <char_const,string_lit>ESCSEQ return ESCSEQ;
83 <char_const,string_lit>\n ; /* ignore */
84 <char_const,string_lit>. setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN;
101 "..." return DOTDOTDOT;
105 align setstring(yyextra, yylval, yytext); return TOK_ALIGN;
106 const setstring(yyextra, yylval, yytext); return CONST;
107 char setstring(yyextra, yylval, yytext); return CHAR;
108 clock setstring(yyextra, yylval, yytext); return CLOCK;
109 double setstring(yyextra, yylval, yytext); return DOUBLE;
110 enum setstring(yyextra, yylval, yytext); return ENUM;
111 event setstring(yyextra, yylval, yytext); return EVENT;
112 floating_point setstring(yyextra, yylval, yytext); return FLOATING_POINT;
113 float setstring(yyextra, yylval, yytext); return FLOAT;
114 integer setstring(yyextra, yylval, yytext); return INTEGER;
115 int setstring(yyextra, yylval, yytext); return INT;
116 long setstring(yyextra, yylval, yytext); return LONG;
117 short setstring(yyextra, yylval, yytext); return SHORT;
118 signed setstring(yyextra, yylval, yytext); return SIGNED;
119 stream setstring(yyextra, yylval, yytext); return STREAM;
120 string setstring(yyextra, yylval, yytext); return STRING;
121 struct setstring(yyextra, yylval, yytext); return STRUCT;
122 trace setstring(yyextra, yylval, yytext); return TRACE;
123 typealias setstring(yyextra, yylval, yytext); return TYPEALIAS;
124 typedef setstring(yyextra, yylval, yytext); return TYPEDEF;
125 unsigned setstring(yyextra, yylval, yytext); return UNSIGNED;
126 variant setstring(yyextra, yylval, yytext); return VARIANT;
127 void setstring(yyextra, yylval, yytext); return VOID;
128 _Bool setstring(yyextra, yylval, yytext); return _BOOL;
129 _Complex setstring(yyextra, yylval, yytext); return _COMPLEX;
130 _Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY;
131 [1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT;
132 0{OCTALDIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT;
133 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT;
134 {IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, rem_(yytext)); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
135 [ \t\n]+ ; /* ignore */