a689d4cea5f6c6399ad065b88978f953f736e6c4
[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
20 #include <stdio.h>
21 #include <babeltrace/babeltrace-internal.h>
22 #include "ctf-scanner.h"
23 #include "ctf-parser.h"
24 #include "ctf-ast.h"
25
26 __attribute__((visibility("hidden")))
27 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
28
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));
32
33 %}
34
35 %x comment_ml comment_sl string_lit char_const
36 %option reentrant yylineno noyywrap bison-bridge
37 %option extra-type="struct ctf_scanner *"
38 /* bison-locations */
39 INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
40 DIGIT [0-9]
41 NONDIGIT [a-zA-Z_]
42 HEXDIGIT [0-9A-Fa-f]
43 OCTALDIGIT [0-7]
44 UCHARLOWERCASE \\u{HEXDIGIT}{4}
45 UCHARUPPERCASE \\U{HEXDIGIT}{8}
46 ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
47 IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
48 ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+)
49 %%
50
51 /*
52 * Using start conditions to deal with comments
53 * and strings.
54 */
55
56 "/*" BEGIN(comment_ml);
57 <comment_ml>[^*\n]* /* eat anything that's not a '*' */
58 <comment_ml>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
59 <comment_ml>\n ++yylineno;
60 <comment_ml>"*"+"/" BEGIN(INITIAL);
61
62 "//" BEGIN(comment_sl);
63 <comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL);
64
65 L\' BEGIN(char_const); return CHARACTER_CONSTANT_START;
66 \' BEGIN(char_const); return CHARACTER_CONSTANT_START;
67 <char_const>\' BEGIN(INITIAL); return SQUOTE;
68
69 L\" BEGIN(string_lit); return STRING_LITERAL_START;
70 \" BEGIN(string_lit); return STRING_LITERAL_START;
71 <string_lit>\" BEGIN(INITIAL); return DQUOTE;
72
73 <char_const,string_lit>ESCSEQ return ESCSEQ;
74 <char_const,string_lit>\n ; /* ignore */
75 <char_const,string_lit>. setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN;
76
77 "[" return LSBRAC;
78 "]" return RSBRAC;
79 "(" return LPAREN;
80 ")" return RPAREN;
81 "{" return LBRAC;
82 "}" return RBRAC;
83 "->" return RARROW;
84 "*" return STAR;
85 "+" return PLUS;
86 "-" return MINUS;
87 "<" return LT;
88 ">" return GT;
89 := return TYPEASSIGN;
90 : return COLON;
91 ; return SEMICOLON;
92 "..." return DOTDOTDOT;
93 "." return DOT;
94 = return EQUAL;
95 "," return COMMA;
96 align setstring(yyextra, yylval, yytext); return TOK_ALIGN;
97 const setstring(yyextra, yylval, yytext); return CONST;
98 char setstring(yyextra, yylval, yytext); return CHAR;
99 clock setstring(yyextra, yylval, yytext); return CLOCK;
100 double setstring(yyextra, yylval, yytext); return DOUBLE;
101 enum setstring(yyextra, yylval, yytext); return ENUM;
102 env setstring(yyextra, yylval, yytext); return ENV;
103 event setstring(yyextra, yylval, yytext); return EVENT;
104 floating_point setstring(yyextra, yylval, yytext); return FLOATING_POINT;
105 float setstring(yyextra, yylval, yytext); return FLOAT;
106 integer setstring(yyextra, yylval, yytext); return INTEGER;
107 int setstring(yyextra, yylval, yytext); return INT;
108 long setstring(yyextra, yylval, yytext); return LONG;
109 short setstring(yyextra, yylval, yytext); return SHORT;
110 signed setstring(yyextra, yylval, yytext); return SIGNED;
111 stream setstring(yyextra, yylval, yytext); return STREAM;
112 string setstring(yyextra, yylval, yytext); return STRING;
113 struct setstring(yyextra, yylval, yytext); return STRUCT;
114 trace setstring(yyextra, yylval, yytext); return TRACE;
115 callsite setstring(yyextra, yylval, yytext); return CALLSITE;
116 typealias setstring(yyextra, yylval, yytext); return TYPEALIAS;
117 typedef setstring(yyextra, yylval, yytext); return TYPEDEF;
118 unsigned setstring(yyextra, yylval, yytext); return UNSIGNED;
119 variant setstring(yyextra, yylval, yytext); return VARIANT;
120 void setstring(yyextra, yylval, yytext); return VOID;
121 _Bool setstring(yyextra, yylval, yytext); return _BOOL;
122 _Complex setstring(yyextra, yylval, yytext); return _COMPLEX;
123 _Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY;
124 [1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT;
125 0{OCTALDIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT;
126 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT;
127 {IDENTIFIER} printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
128 [ \t\n]+ ; /* ignore */
129 . return ERROR;
130 %%
This page took 0.045886 seconds and 3 git commands to generate.