blob: cb5eb318a01b99d2f1c0b1449bcddcef96a2a11f [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
18#include "expr.h"
19#include "parser.h"
20
21int gLine = 1;
22int gColumn = 1;
23
24// TODO: enforce MAX_STRING_LEN during lexing
25char string_buffer[MAX_STRING_LEN];
26char* string_pos;
27%}
28
29%x STR
30
31%option noyywrap
32
33%%
34
35
36\" {
37 ++gColumn;
38 BEGIN(STR);
39 string_pos = string_buffer;
40}
41
42<STR>{
43 \" {
44 ++gColumn;
45 BEGIN(INITIAL);
46 *string_pos = '\0';
47 yylval.str = strdup(string_buffer);
48 return STRING;
49 }
50
51 \\n { gColumn += yyleng; *string_pos++ = '\n'; }
52 \\t { gColumn += yyleng; *string_pos++ = '\t'; }
53 \\\" { gColumn += yyleng; *string_pos++ = '\"'; }
54 \\\\ { gColumn += yyleng; *string_pos++ = '\\'; }
55
56 \\x[0-9a-fA-F]{2} {
57 gColumn += yyleng;
58 int val;
59 sscanf(yytext+2, "%x", &val);
60 *string_pos++ = val;
61 }
62
63 \n {
64 ++gLine;
65 gColumn = 1;
66 *string_pos++ = yytext[0];
67 }
68
69 . {
70 ++gColumn;
71 *string_pos++ = yytext[0];
72 }
73}
74
75if { gColumn += yyleng; return IF; }
76then { gColumn += yyleng; return THEN; }
77else { gColumn += yyleng; return ELSE; }
78endif { gColumn += yyleng; return ENDIF; }
79
Doug Zongker9931f7f2009-06-10 14:11:53 -070080[a-zA-Z0-9_:/.]+ {
Doug Zongker37bee622009-06-08 17:35:39 -070081 gColumn += yyleng;
82 yylval.str = strdup(yytext);
83 return STRING;
84}
85
86\&\& { gColumn += yyleng; return AND; }
87\|\| { gColumn += yyleng; return OR; }
88== { gColumn += yyleng; return EQ; }
89!= { gColumn += yyleng; return NE; }
90
91[+(),!;] { gColumn += yyleng; return yytext[0]; }
92
93[ \t]+ gColumn += yyleng;
94
95(#.*)?\n { ++gLine; gColumn = 1; }
96
97. return BAD;