1/* 2 * Copyright (C) 2016, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17%{ 18#include <string.h> 19#include <stdlib.h> 20 21#include "aidl_language.h" 22#include "aidl_language_y-module.h" 23 24#define YY_USER_ACTION yylloc->columns(yyleng); 25%} 26 27%option yylineno 28%option noyywrap 29%option nounput 30%option noinput 31%option reentrant 32%option bison-bridge 33%option bison-locations 34 35%x LONG_COMMENT 36 37identifier [_a-zA-Z][_a-zA-Z0-9]* 38whitespace ([ \t\r]+) 39intvalue [0-9]+[lL]? 40hexvalue 0[x|X][0-9a-fA-F]+ 41floatvalue [0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f? 42 43%% 44%{ 45 /* This happens at every call to yylex (every time we receive one token) */ 46 std::string extra_text; 47 yylloc->step(); 48%} 49 50\/\* { extra_text += yytext; BEGIN(LONG_COMMENT); } 51<LONG_COMMENT>\*+\/ { extra_text += yytext; yylloc->step(); BEGIN(INITIAL); } 52<LONG_COMMENT>\*+ { extra_text += yytext; } 53<LONG_COMMENT>\n+ { extra_text += yytext; yylloc->lines(yyleng); } 54<LONG_COMMENT>[^*\n]+ { extra_text += yytext; } 55 56\"[^\"]*\" { yylval->token = new AidlToken(yytext, extra_text); 57 return yy::parser::token::C_STR; } 58 59\/\/.* { extra_text += yytext; extra_text += "\n"; } 60 61\n+ { yylloc->lines(yyleng); yylloc->step(); } 62{whitespace} {} 63<<EOF>> { yyterminate(); } 64 65 /* symbols */ 66"(" { return('('); } 67")" { return(')'); } 68"<" { return('<'); } 69">" { return('>'); } 70"{" { return('{'); } 71"}" { return('}'); } 72"[" { return('['); } 73"]" { return(']'); } 74":" { return(':'); } 75";" { return(';'); } 76"," { return(','); } 77"." { return('.'); } 78"=" { return('='); } 79"+" { return('+'); } 80"-" { return('-'); } 81"*" { return('*'); } 82"/" { return('/'); } 83"%" { return('%'); } 84"&" { return('&'); } 85"|" { return('|'); } 86"^" { return('^'); } 87"<<" { return(yy::parser::token::LSHIFT); } 88">>" { return(yy::parser::token::RSHIFT); } 89"&&" { return(yy::parser::token::LOGICAL_AND); } 90"||" { return(yy::parser::token::LOGICAL_OR); } 91"!" { return('!'); } 92"~" { return('~'); } 93"<=" { return(yy::parser::token::LEQ); } 94">=" { return(yy::parser::token::GEQ); } 95"==" { return(yy::parser::token::EQUALITY); } 96"!=" { return(yy::parser::token::NEQ); } 97 98 /* annotations */ 99@{identifier} { yylval->token = new AidlToken(yytext + 1, extra_text); 100 return yy::parser::token::ANNOTATION; 101 } 102 103 /* keywords */ 104parcelable { yylval->token = new AidlToken("parcelable", extra_text); 105 return yy::parser::token::PARCELABLE; 106 } 107import { return yy::parser::token::IMPORT; } 108package { return yy::parser::token::PACKAGE; } 109in { return yy::parser::token::IN; } 110out { return yy::parser::token::OUT; } 111inout { return yy::parser::token::INOUT; } 112cpp_header { return yy::parser::token::CPP_HEADER; } 113const { yylval->token = new AidlToken("const", extra_text); 114 return yy::parser::token::CONST; } 115true { return yy::parser::token::TRUE_LITERAL; } 116false { return yy::parser::token::FALSE_LITERAL; } 117 118interface { yylval->token = new AidlToken("interface", extra_text); 119 return yy::parser::token::INTERFACE; 120 } 121oneway { yylval->token = new AidlToken("oneway", extra_text); 122 return yy::parser::token::ONEWAY; 123 } 124enum { yylval->token = new AidlToken("enum", extra_text); 125 return yy::parser::token::ENUM; 126 } 127 128 /* scalars */ 129{identifier} { yylval->token = new AidlToken(yytext, extra_text); 130 return yy::parser::token::IDENTIFIER; 131 } 132'.' { yylval->character = yytext[1]; 133 return yy::parser::token::CHARVALUE; 134 } 135{intvalue} { yylval->token = new AidlToken(yytext, extra_text); 136 return yy::parser::token::INTVALUE; } 137{floatvalue} { yylval->token = new AidlToken(yytext, extra_text); 138 return yy::parser::token::FLOATVALUE; } 139{hexvalue} { yylval->token = new AidlToken(yytext, extra_text); 140 return yy::parser::token::HEXVALUE; } 141 142 /* lexical error! */ 143. { return yy::parser::token::UNKNOWN; } 144 145%% 146 147// comment and whitespace handling 148// ================================================ 149