322832bedc91ccdcde55af8caba7cdac43d17a2f
[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 extern
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 static inline
34 const char *rem_(const char *str)
35 {
36 if (str[0] == '_')
37 return &str[1];
38 else
39 return str;
40 }
41
42 %}
43
44 %x comment_ml comment_sl string_lit char_const
45 %option reentrant yylineno noyywrap bison-bridge
46 %option extra-type="struct ctf_scanner *"
47 /* bison-locations */
48 INTEGER_SUFFIX [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
49 DIGIT [0-9]
50 NONDIGIT [a-zA-Z_]
51 HEXDIGIT [0-9A-Fa-f]
52 OCTALDIGIT [0-7]
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}+)
58 %%
59
60 /*
61 * Using start conditions to deal with comments
62 * and strings.
63 */
64
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);
70
71 "//" BEGIN(comment_sl);
72 <comment_sl>[^\n]*\n ++yylineno; BEGIN(INITIAL);
73
74 L\' BEGIN(char_const); return CHARACTER_CONSTANT_START;
75 \' BEGIN(char_const); return CHARACTER_CONSTANT_START;
76 <char_const>\' BEGIN(INITIAL); return SQUOTE;
77
78 L\" BEGIN(string_lit); return STRING_LITERAL_START;
79 \" BEGIN(string_lit); return STRING_LITERAL_START;
80 <string_lit>\" BEGIN(INITIAL); return DQUOTE;
81
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;
85
86 "[" return LSBRAC;
87 "]" return RSBRAC;
88 "(" return LPAREN;
89 ")" return RPAREN;
90 "{" return LBRAC;
91 "}" return RBRAC;
92 "->" return RARROW;
93 "*" return STAR;
94 "+" return PLUS;
95 "-" return MINUS;
96 "<" return LT;
97 ">" return GT;
98 := return TYPEASSIGN;
99 : return COLON;
100 ; return SEMICOLON;
101 "..." return DOTDOTDOT;
102 "." return DOT;
103 = return EQUAL;
104 "," return COMMA;
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 */
136 . return ERROR;
137 %%
This page took 0.036986 seconds and 4 git commands to generate.