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