blob: 4813da69e1d3d78807f81c0bf48ad664b1e5f040 [file] [log] [blame]
Will McVickerd7d18df2019-09-12 13:40:50 -07001/*
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
Adam Lesinskiffa16862014-01-23 18:17:42 -080017%{
Adam Lesinskiffa16862014-01-23 18:17:42 -080018#include <string.h>
19#include <stdlib.h>
Christopher Wileyf690be52015-09-14 15:19:10 -070020
21#include "aidl_language.h"
Dan Willemsen609ba6d2019-12-30 10:44:00 -080022#include "aidl_language_y-module.h"
Adam Lesinskiffa16862014-01-23 18:17:42 -080023
Casey Dahlin1aa158e2015-09-14 15:26:57 -070024#define YY_USER_ACTION yylloc->columns(yyleng);
Adam Lesinskiffa16862014-01-23 18:17:42 -080025%}
26
27%option yylineno
28%option noyywrap
Steven Moreland1cee9db2018-06-28 10:37:24 -070029%option nounput
30%option noinput
Casey Dahlindd691812015-09-09 17:59:06 -070031%option reentrant
32%option bison-bridge
Casey Dahlinfd2e08a2015-09-10 18:29:09 -070033%option bison-locations
Adam Lesinskiffa16862014-01-23 18:17:42 -080034
Steven Moreland7e176e92019-11-10 21:00:14 -080035%x LONG_COMMENT
Adam Lesinskiffa16862014-01-23 18:17:42 -080036
Casey Dahlin2b2879b2015-10-13 16:59:44 -070037identifier [_a-zA-Z][_a-zA-Z0-9]*
Casey Dahlin1aa158e2015-09-14 15:26:57 -070038whitespace ([ \t\r]+)
Will McVickerd7d18df2019-09-12 13:40:50 -070039intvalue [0-9]+[lL]?
Roshan Pius3b2203d2016-07-22 16:13:20 -070040hexvalue 0[x|X][0-9a-fA-F]+
Will McVickerd7d18df2019-09-12 13:40:50 -070041floatvalue [0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?
Adam Lesinskiffa16862014-01-23 18:17:42 -080042
43%%
Casey Dahlin1aa158e2015-09-14 15:26:57 -070044%{
45 /* This happens at every call to yylex (every time we receive one token) */
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070046 std::string extra_text;
Casey Dahlin1aa158e2015-09-14 15:26:57 -070047 yylloc->step();
48%}
Adam Lesinskiffa16862014-01-23 18:17:42 -080049
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070050\/\* { extra_text += yytext; BEGIN(LONG_COMMENT); }
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070051<LONG_COMMENT>\*+\/ { extra_text += yytext; yylloc->step(); BEGIN(INITIAL); }
Casey Dahlin88d07842016-01-05 11:54:40 -080052<LONG_COMMENT>\*+ { extra_text += yytext; }
53<LONG_COMMENT>\n+ { extra_text += yytext; yylloc->lines(yyleng); }
54<LONG_COMMENT>[^*\n]+ { extra_text += yytext; }
Adam Lesinskiffa16862014-01-23 18:17:42 -080055
Casey Dahlinbed1e872015-10-22 17:03:34 -070056\"[^\"]*\" { yylval->token = new AidlToken(yytext, extra_text);
57 return yy::parser::token::C_STR; }
58
Steven Moreland9c2988f2019-07-17 17:49:10 -070059\/\/.* { extra_text += yytext; extra_text += "\n"; }
Casey Dahlin1aa158e2015-09-14 15:26:57 -070060
Casey Dahlin3c6df362015-10-06 15:48:35 -070061\n+ { yylloc->lines(yyleng); yylloc->step(); }
62{whitespace} {}
63<<EOF>> { yyterminate(); }
Adam Lesinskiffa16862014-01-23 18:17:42 -080064
Casey Dahlin3c6df362015-10-06 15:48:35 -070065 /* symbols */
Will McVickerd7d18df2019-09-12 13:40:50 -070066"(" { 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); }
Casey Dahlin5c69deb2015-10-01 14:44:12 -070097
Steven Morelanded906872018-07-10 11:36:37 -070098 /* annotations */
Jiyong Parka6605ab2018-11-11 14:30:21 +090099@{identifier} { yylval->token = new AidlToken(yytext + 1, extra_text);
Steven Morelanded906872018-07-10 11:36:37 -0700100 return yy::parser::token::ANNOTATION;
101 }
102
Adam Lesinskiffa16862014-01-23 18:17:42 -0800103 /* keywords */
Jiyong Parka6605ab2018-11-11 14:30:21 +0900104parcelable { yylval->token = new AidlToken("parcelable", extra_text);
105 return yy::parser::token::PARCELABLE;
106 }
Casey Dahlin3c6df362015-10-06 15:48:35 -0700107import { 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; }
Casey Dahlincd639212015-12-15 12:51:04 -0800112cpp_header { return yy::parser::token::CPP_HEADER; }
Jeongik Cha997281d2020-01-16 15:23:59 +0900113const { yylval->token = new AidlToken("const", extra_text);
114 return yy::parser::token::CONST; }
Steven Moreland25294322018-08-07 18:13:55 -0700115true { return yy::parser::token::TRUE_LITERAL; }
116false { return yy::parser::token::FALSE_LITERAL; }
Casey Dahlinfd6fb482015-09-30 14:48:18 -0700117
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700118interface { 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 }
Daniel Norman85aed542019-08-21 12:01:14 -0700124enum { yylval->token = new AidlToken("enum", extra_text);
125 return yy::parser::token::ENUM;
126 }
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700127
Casey Dahlin3c6df362015-10-06 15:48:35 -0700128 /* scalars */
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700129{identifier} { yylval->token = new AidlToken(yytext, extra_text);
130 return yy::parser::token::IDENTIFIER;
131 }
Steven Moreland25294322018-08-07 18:13:55 -0700132'.' { yylval->character = yytext[1];
133 return yy::parser::token::CHARVALUE;
134 }
135{intvalue} { yylval->token = new AidlToken(yytext, extra_text);
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800136 return yy::parser::token::INTVALUE; }
Steven Moreland1c4ba202018-08-09 10:49:54 -0700137{floatvalue} { yylval->token = new AidlToken(yytext, extra_text);
138 return yy::parser::token::FLOATVALUE; }
Roshan Pius3b2203d2016-07-22 16:13:20 -0700139{hexvalue} { yylval->token = new AidlToken(yytext, extra_text);
140 return yy::parser::token::HEXVALUE; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800141
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700142 /* lexical error! */
143. { return yy::parser::token::UNKNOWN; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800144
145%%
146
147// comment and whitespace handling
148// ================================================