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]*) 22 23%% 24%{ 25 /* This happens at every call to yylex (every time we receive one token) */ 26 std::string extra_text; 27 yylloc->step(); 28%} 29 30 31\%\%\{ { extra_text += "/**"; BEGIN(COPYING); } 32<COPYING>\}\%\% { extra_text += "**/"; yylloc->step(); BEGIN(INITIAL); } 33<COPYING>.* { extra_text += yytext; } 34<COPYING>\n+ { extra_text += yytext; yylloc->lines(yyleng); } 35 36\/\* { extra_text += yytext; BEGIN(LONG_COMMENT); } 37<LONG_COMMENT>\*+\/ { extra_text += yytext; yylloc->step(); BEGIN(INITIAL); } 38<LONG_COMMENT>\*+ { extra_text += yytext; } 39<LONG_COMMENT>\n+ { extra_text += yytext; yylloc->lines(yyleng); } 40<LONG_COMMENT>[^*\n]+ { extra_text += yytext; } 41 42\"[^\"]*\" { yylval->token = new AidlToken(yytext, extra_text); 43 return yy::parser::token::C_STR; } 44 45\/\/.*\n { extra_text += yytext; yylloc->lines(1); yylloc->step(); } 46 47\n+ { yylloc->lines(yyleng); yylloc->step(); } 48{whitespace} {} 49<<EOF>> { yyterminate(); } 50 51 /* symbols */ 52; { return ';'; } 53\{ { return '{'; } 54\} { return '}'; } 55= { return '='; } 56, { return ','; } 57\. { return '.'; } 58\( { return '('; } 59\) { return ')'; } 60\[ { return '['; } 61\] { return ']'; } 62\< { return '<'; } 63\> { return '>'; } 64 65 /* keywords */ 66parcelable { return yy::parser::token::PARCELABLE; } 67import { return yy::parser::token::IMPORT; } 68package { return yy::parser::token::PACKAGE; } 69int { return yy::parser::token::INT; } 70in { return yy::parser::token::IN; } 71out { return yy::parser::token::OUT; } 72inout { return yy::parser::token::INOUT; } 73cpp_header { return yy::parser::token::CPP_HEADER; } 74const { return yy::parser::token::CONST; } 75@nullable { return yy::parser::token::ANNOTATION_NULLABLE; } 76@utf8 { return yy::parser::token::ANNOTATION_UTF8; } 77@utf8InCpp { return yy::parser::token::ANNOTATION_UTF8_CPP; } 78 79interface { yylval->token = new AidlToken("interface", extra_text); 80 return yy::parser::token::INTERFACE; 81 } 82oneway { yylval->token = new AidlToken("oneway", extra_text); 83 return yy::parser::token::ONEWAY; 84 } 85 86 /* scalars */ 87{identifier} { yylval->token = new AidlToken(yytext, extra_text); 88 return yy::parser::token::IDENTIFIER; 89 } 90{intvalue} { yylval->integer = std::stoi(yytext); 91 return yy::parser::token::INTVALUE; } 92 93 /* syntax error! */ 94. { printf("UNKNOWN(%s)", yytext); 95 yylval->token = new AidlToken(yytext, extra_text); 96 return yy::parser::token::IDENTIFIER; 97 } 98 99%% 100 101// comment and whitespace handling 102// ================================================ 103