blob: 4e04003b175c698126d3795f8024b55fab574e56 [file] [log] [blame]
Doug Zongker37bee622009-06-08 17:35:39 -07001%{
2/*
3 * Copyright (C) 2009 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Doug Zongker583fc122010-02-19 16:07:57 -080018#include <string.h>
Yabin Cui12f499e2016-01-27 12:26:18 -080019#include <string>
Doug Zongker583fc122010-02-19 16:07:57 -080020
Tao Baoe6f7f952017-10-04 09:33:01 -070021#include "edify/expr.h"
Doug Zongkerd9c9d102009-06-12 12:24:39 -070022#include "yydefs.h"
Doug Zongker37bee622009-06-08 17:35:39 -070023#include "parser.h"
24
25int gLine = 1;
26int gColumn = 1;
Doug Zongkerd9c9d102009-06-12 12:24:39 -070027int gPos = 0;
Doug Zongker37bee622009-06-08 17:35:39 -070028
Yabin Cui12f499e2016-01-27 12:26:18 -080029std::string string_buffer;
Doug Zongkerd9c9d102009-06-12 12:24:39 -070030
31#define ADVANCE do {yylloc.start=gPos; yylloc.end=gPos+yyleng; \
32 gColumn+=yyleng; gPos+=yyleng;} while(0)
33
Doug Zongker37bee622009-06-08 17:35:39 -070034%}
35
36%x STR
37
Tianjie Xuc7cd9182017-08-29 12:06:02 -070038%option noinput
39%option nounput
Doug Zongker37bee622009-06-08 17:35:39 -070040%option noyywrap
41
42%%
43
44
45\" {
Doug Zongker37bee622009-06-08 17:35:39 -070046 BEGIN(STR);
Yabin Cui12f499e2016-01-27 12:26:18 -080047 string_buffer.clear();
Doug Zongkerd9c9d102009-06-12 12:24:39 -070048 yylloc.start = gPos;
49 ++gColumn;
50 ++gPos;
Doug Zongker37bee622009-06-08 17:35:39 -070051}
52
53<STR>{
54 \" {
55 ++gColumn;
Doug Zongkerd9c9d102009-06-12 12:24:39 -070056 ++gPos;
Doug Zongker37bee622009-06-08 17:35:39 -070057 BEGIN(INITIAL);
Yabin Cui12f499e2016-01-27 12:26:18 -080058 yylval.str = strdup(string_buffer.c_str());
Doug Zongkerd9c9d102009-06-12 12:24:39 -070059 yylloc.end = gPos;
Doug Zongker37bee622009-06-08 17:35:39 -070060 return STRING;
61 }
62
Yabin Cui12f499e2016-01-27 12:26:18 -080063 \\n { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\n'); }
64 \\t { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\t'); }
65 \\\" { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\"'); }
66 \\\\ { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\\'); }
Doug Zongker37bee622009-06-08 17:35:39 -070067
68 \\x[0-9a-fA-F]{2} {
69 gColumn += yyleng;
Doug Zongkerd9c9d102009-06-12 12:24:39 -070070 gPos += yyleng;
Doug Zongker37bee622009-06-08 17:35:39 -070071 int val;
72 sscanf(yytext+2, "%x", &val);
Yabin Cui12f499e2016-01-27 12:26:18 -080073 string_buffer.push_back(static_cast<char>(val));
Doug Zongker37bee622009-06-08 17:35:39 -070074 }
75
76 \n {
77 ++gLine;
Doug Zongkerd9c9d102009-06-12 12:24:39 -070078 ++gPos;
Doug Zongker37bee622009-06-08 17:35:39 -070079 gColumn = 1;
Yabin Cui12f499e2016-01-27 12:26:18 -080080 string_buffer.push_back(yytext[0]);
Doug Zongker37bee622009-06-08 17:35:39 -070081 }
82
83 . {
84 ++gColumn;
Doug Zongkerd9c9d102009-06-12 12:24:39 -070085 ++gPos;
Yabin Cui12f499e2016-01-27 12:26:18 -080086 string_buffer.push_back(yytext[0]);
Doug Zongker37bee622009-06-08 17:35:39 -070087 }
88}
89
Doug Zongkerd9c9d102009-06-12 12:24:39 -070090if ADVANCE; return IF;
91then ADVANCE; return THEN;
92else ADVANCE; return ELSE;
93endif ADVANCE; return ENDIF;
Doug Zongker37bee622009-06-08 17:35:39 -070094
Doug Zongker9931f7f2009-06-10 14:11:53 -070095[a-zA-Z0-9_:/.]+ {
Doug Zongkerd9c9d102009-06-12 12:24:39 -070096 ADVANCE;
Doug Zongker37bee622009-06-08 17:35:39 -070097 yylval.str = strdup(yytext);
98 return STRING;
99}
100
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700101\&\& ADVANCE; return AND;
102\|\| ADVANCE; return OR;
103== ADVANCE; return EQ;
104!= ADVANCE; return NE;
Doug Zongker37bee622009-06-08 17:35:39 -0700105
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700106[+(),!;] ADVANCE; return yytext[0];
Doug Zongker37bee622009-06-08 17:35:39 -0700107
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700108[ \t]+ ADVANCE;
Doug Zongker37bee622009-06-08 17:35:39 -0700109
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700110(#.*)?\n gPos += yyleng; ++gLine; gColumn = 1;
Doug Zongker37bee622009-06-08 17:35:39 -0700111
112. return BAD;