forked from hiking90/aidl-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaidl_language_l.ll
106 lines (87 loc) · 3.78 KB
/
aidl_language_l.ll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
%{
#include <string.h>
#include <stdlib.h>
#include "aidl_language.h"
#include "aidl_language_y.hpp"
#define YY_USER_ACTION yylloc->columns(yyleng);
%}
%option yylineno
%option noyywrap
%option reentrant
%option bison-bridge
%option bison-locations
%x COPYING LONG_COMMENT
identifier [_a-zA-Z][_a-zA-Z0-9]*
whitespace ([ \t\r]+)
intvalue [-+]?(0|[1-9][0-9]*)
hexvalue 0[x|X][0-9a-fA-F]+
%%
%{
/* This happens at every call to yylex (every time we receive one token) */
std::string extra_text;
yylloc->step();
%}
\%\%\{ { extra_text += "/**"; BEGIN(COPYING); }
<COPYING>\}\%\% { extra_text += "**/"; yylloc->step(); BEGIN(INITIAL); }
<COPYING>.* { extra_text += yytext; }
<COPYING>\n+ { extra_text += yytext; yylloc->lines(yyleng); }
\/\* { extra_text += yytext; BEGIN(LONG_COMMENT); }
<LONG_COMMENT>\*+\/ { extra_text += yytext; yylloc->step(); BEGIN(INITIAL); }
<LONG_COMMENT>\*+ { extra_text += yytext; }
<LONG_COMMENT>\n+ { extra_text += yytext; yylloc->lines(yyleng); }
<LONG_COMMENT>[^*\n]+ { extra_text += yytext; }
\"[^\"]*\" { yylval->token = new AidlToken(yytext, extra_text);
return yy::parser::token::C_STR; }
\/\/.*\n { extra_text += yytext; yylloc->lines(1); yylloc->step(); }
\n+ { yylloc->lines(yyleng); yylloc->step(); }
{whitespace} {}
<<EOF>> { yyterminate(); }
/* symbols */
; { return ';'; }
\{ { return '{'; }
\} { return '}'; }
= { return '='; }
, { return ','; }
\. { return '.'; }
\( { return '('; }
\) { return ')'; }
\[ { return '['; }
\] { return ']'; }
\< { return '<'; }
\> { return '>'; }
/* keywords */
parcelable { return yy::parser::token::PARCELABLE; }
import { return yy::parser::token::IMPORT; }
package { return yy::parser::token::PACKAGE; }
int { return yy::parser::token::INT; }
String { return yy::parser::token::STRING; }
in { return yy::parser::token::IN; }
out { return yy::parser::token::OUT; }
inout { return yy::parser::token::INOUT; }
cpp_header { return yy::parser::token::CPP_HEADER; }
const { return yy::parser::token::CONST; }
@nullable { return yy::parser::token::ANNOTATION_NULLABLE; }
@utf8 { return yy::parser::token::ANNOTATION_UTF8; }
@utf8InCpp { return yy::parser::token::ANNOTATION_UTF8_CPP; }
interface { yylval->token = new AidlToken("interface", extra_text);
return yy::parser::token::INTERFACE;
}
oneway { yylval->token = new AidlToken("oneway", extra_text);
return yy::parser::token::ONEWAY;
}
/* scalars */
{identifier} { yylval->token = new AidlToken(yytext, extra_text);
return yy::parser::token::IDENTIFIER;
}
{intvalue} { yylval->integer = std::stoi(yytext);
return yy::parser::token::INTVALUE; }
{hexvalue} { yylval->token = new AidlToken(yytext, extra_text);
return yy::parser::token::HEXVALUE; }
/* syntax error! */
. { printf("UNKNOWN(%s)", yytext);
yylval->token = new AidlToken(yytext, extra_text);
return yy::parser::token::IDENTIFIER;
}
%%
// comment and whitespace handling
// ================================================