blob: 4baa01c1d1a08814abe9b1f456adab71842c0a3d [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"
Jiyong Parke5c45292020-05-26 19:06:24 +090022#include "parser.h"
Dan Willemsen609ba6d2019-12-30 10:44:00 -080023#include "aidl_language_y-module.h"
Adam Lesinskiffa16862014-01-23 18:17:42 -080024
Casey Dahlin1aa158e2015-09-14 15:26:57 -070025#define YY_USER_ACTION yylloc->columns(yyleng);
Adam Lesinskiffa16862014-01-23 18:17:42 -080026%}
27
28%option yylineno
29%option noyywrap
Steven Moreland1cee9db2018-06-28 10:37:24 -070030%option nounput
31%option noinput
Casey Dahlindd691812015-09-09 17:59:06 -070032%option reentrant
33%option bison-bridge
Casey Dahlinfd2e08a2015-09-10 18:29:09 -070034%option bison-locations
Adam Lesinskiffa16862014-01-23 18:17:42 -080035
Steven Moreland7e176e92019-11-10 21:00:14 -080036%x LONG_COMMENT
Adam Lesinskiffa16862014-01-23 18:17:42 -080037
Casey Dahlin2b2879b2015-10-13 16:59:44 -070038identifier [_a-zA-Z][_a-zA-Z0-9]*
Casey Dahlin1aa158e2015-09-14 15:26:57 -070039whitespace ([ \t\r]+)
Will McVickerd7d18df2019-09-12 13:40:50 -070040intvalue [0-9]+[lL]?
Steven Morelandcef22662020-07-08 20:54:28 +000041hexvalue 0[x|X][0-9a-fA-F]+[lL]?
Will McVickerd7d18df2019-09-12 13:40:50 -070042floatvalue [0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?
Adam Lesinskiffa16862014-01-23 18:17:42 -080043
44%%
Casey Dahlin1aa158e2015-09-14 15:26:57 -070045%{
46 /* This happens at every call to yylex (every time we receive one token) */
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070047 std::string extra_text;
Casey Dahlin1aa158e2015-09-14 15:26:57 -070048 yylloc->step();
49%}
Adam Lesinskiffa16862014-01-23 18:17:42 -080050
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070051\/\* { extra_text += yytext; BEGIN(LONG_COMMENT); }
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070052<LONG_COMMENT>\*+\/ { extra_text += yytext; yylloc->step(); BEGIN(INITIAL); }
Casey Dahlin88d07842016-01-05 11:54:40 -080053<LONG_COMMENT>\*+ { extra_text += yytext; }
54<LONG_COMMENT>\n+ { extra_text += yytext; yylloc->lines(yyleng); }
55<LONG_COMMENT>[^*\n]+ { extra_text += yytext; }
Adam Lesinskiffa16862014-01-23 18:17:42 -080056
Casey Dahlinbed1e872015-10-22 17:03:34 -070057\"[^\"]*\" { yylval->token = new AidlToken(yytext, extra_text);
58 return yy::parser::token::C_STR; }
59
Steven Moreland9c2988f2019-07-17 17:49:10 -070060\/\/.* { extra_text += yytext; extra_text += "\n"; }
Casey Dahlin1aa158e2015-09-14 15:26:57 -070061
Casey Dahlin3c6df362015-10-06 15:48:35 -070062\n+ { yylloc->lines(yyleng); yylloc->step(); }
63{whitespace} {}
64<<EOF>> { yyterminate(); }
Adam Lesinskiffa16862014-01-23 18:17:42 -080065
Casey Dahlin3c6df362015-10-06 15:48:35 -070066 /* symbols */
Will McVickerd7d18df2019-09-12 13:40:50 -070067"(" { 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('^'); }
88"<<" { return(yy::parser::token::LSHIFT); }
89">>" { return(yy::parser::token::RSHIFT); }
90"&&" { return(yy::parser::token::LOGICAL_AND); }
91"||" { return(yy::parser::token::LOGICAL_OR); }
92"!" { return('!'); }
93"~" { return('~'); }
94"<=" { return(yy::parser::token::LEQ); }
95">=" { return(yy::parser::token::GEQ); }
96"==" { return(yy::parser::token::EQUALITY); }
97"!=" { return(yy::parser::token::NEQ); }
Casey Dahlin5c69deb2015-10-01 14:44:12 -070098
Steven Morelanded906872018-07-10 11:36:37 -070099 /* annotations */
Jiyong Parka6605ab2018-11-11 14:30:21 +0900100@{identifier} { yylval->token = new AidlToken(yytext + 1, extra_text);
Steven Morelanded906872018-07-10 11:36:37 -0700101 return yy::parser::token::ANNOTATION;
102 }
103
Adam Lesinskiffa16862014-01-23 18:17:42 -0800104 /* keywords */
Jiyong Parka6605ab2018-11-11 14:30:21 +0900105parcelable { yylval->token = new AidlToken("parcelable", extra_text);
106 return yy::parser::token::PARCELABLE;
107 }
Casey Dahlin3c6df362015-10-06 15:48:35 -0700108import { return yy::parser::token::IMPORT; }
109package { return yy::parser::token::PACKAGE; }
110in { return yy::parser::token::IN; }
111out { return yy::parser::token::OUT; }
112inout { return yy::parser::token::INOUT; }
Casey Dahlincd639212015-12-15 12:51:04 -0800113cpp_header { return yy::parser::token::CPP_HEADER; }
Jeongik Cha997281d2020-01-16 15:23:59 +0900114const { yylval->token = new AidlToken("const", extra_text);
115 return yy::parser::token::CONST; }
Steven Moreland25294322018-08-07 18:13:55 -0700116true { return yy::parser::token::TRUE_LITERAL; }
117false { return yy::parser::token::FALSE_LITERAL; }
Casey Dahlinfd6fb482015-09-30 14:48:18 -0700118
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700119interface { yylval->token = new AidlToken("interface", extra_text);
120 return yy::parser::token::INTERFACE;
121 }
122oneway { yylval->token = new AidlToken("oneway", extra_text);
123 return yy::parser::token::ONEWAY;
124 }
Daniel Norman85aed542019-08-21 12:01:14 -0700125enum { yylval->token = new AidlToken("enum", extra_text);
126 return yy::parser::token::ENUM;
127 }
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700128
Casey Dahlin3c6df362015-10-06 15:48:35 -0700129 /* scalars */
Casey Dahlincdbbc8c2015-10-14 15:31:04 -0700130{identifier} { yylval->token = new AidlToken(yytext, extra_text);
131 return yy::parser::token::IDENTIFIER;
132 }
Steven Moreland25294322018-08-07 18:13:55 -0700133'.' { yylval->character = yytext[1];
134 return yy::parser::token::CHARVALUE;
135 }
136{intvalue} { yylval->token = new AidlToken(yytext, extra_text);
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800137 return yy::parser::token::INTVALUE; }
Steven Moreland1c4ba202018-08-09 10:49:54 -0700138{floatvalue} { yylval->token = new AidlToken(yytext, extra_text);
139 return yy::parser::token::FLOATVALUE; }
Roshan Pius3b2203d2016-07-22 16:13:20 -0700140{hexvalue} { yylval->token = new AidlToken(yytext, extra_text);
141 return yy::parser::token::HEXVALUE; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800142
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700143 /* lexical error! */
144. { return yy::parser::token::UNKNOWN; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800145
146%%
147
148// comment and whitespace handling
149// ================================================