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