summaryrefslogtreecommitdiffstats
path: root/edify/lexer.l
diff options
context:
space:
mode:
authorDoug Zongker <dougz@android.com>2009-06-15 06:12:26 +0200
committerThe Android Open Source Project <initial-contribution@android.com>2009-06-15 06:12:26 +0200
commit84cbfb6cb4a82824a662137282c689f40057b28b (patch)
tree30b5d33a047b5ae2eb86f53fa16de49d47486b1f /edify/lexer.l
parentam 8edb00c9: edify extensions for OTA package installation, part 2 (diff)
parentfixes to edify and updater script (diff)
downloadandroid_bootable_recovery-84cbfb6cb4a82824a662137282c689f40057b28b.tar
android_bootable_recovery-84cbfb6cb4a82824a662137282c689f40057b28b.tar.gz
android_bootable_recovery-84cbfb6cb4a82824a662137282c689f40057b28b.tar.bz2
android_bootable_recovery-84cbfb6cb4a82824a662137282c689f40057b28b.tar.lz
android_bootable_recovery-84cbfb6cb4a82824a662137282c689f40057b28b.tar.xz
android_bootable_recovery-84cbfb6cb4a82824a662137282c689f40057b28b.tar.zst
android_bootable_recovery-84cbfb6cb4a82824a662137282c689f40057b28b.zip
Diffstat (limited to 'edify/lexer.l')
-rw-r--r--edify/lexer.l47
1 files changed, 30 insertions, 17 deletions
diff --git a/edify/lexer.l b/edify/lexer.l
index cb5eb318a..2c4489cc6 100644
--- a/edify/lexer.l
+++ b/edify/lexer.l
@@ -16,14 +16,20 @@
*/
#include "expr.h"
+#include "yydefs.h"
#include "parser.h"
int gLine = 1;
int gColumn = 1;
+int gPos = 0;
// TODO: enforce MAX_STRING_LEN during lexing
char string_buffer[MAX_STRING_LEN];
char* string_pos;
+
+#define ADVANCE do {yylloc.start=gPos; yylloc.end=gPos+yyleng; \
+ gColumn+=yyleng; gPos+=yyleng;} while(0)
+
%}
%x STR
@@ -34,27 +40,32 @@ char* string_pos;
\" {
- ++gColumn;
BEGIN(STR);
string_pos = string_buffer;
+ yylloc.start = gPos;
+ ++gColumn;
+ ++gPos;
}
<STR>{
\" {
++gColumn;
+ ++gPos;
BEGIN(INITIAL);
*string_pos = '\0';
yylval.str = strdup(string_buffer);
+ yylloc.end = gPos;
return STRING;
}
- \\n { gColumn += yyleng; *string_pos++ = '\n'; }
- \\t { gColumn += yyleng; *string_pos++ = '\t'; }
- \\\" { gColumn += yyleng; *string_pos++ = '\"'; }
- \\\\ { gColumn += yyleng; *string_pos++ = '\\'; }
+ \\n { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\n'; }
+ \\t { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\t'; }
+ \\\" { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\"'; }
+ \\\\ { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\\'; }
\\x[0-9a-fA-F]{2} {
gColumn += yyleng;
+ gPos += yyleng;
int val;
sscanf(yytext+2, "%x", &val);
*string_pos++ = val;
@@ -62,36 +73,38 @@ char* string_pos;
\n {
++gLine;
+ ++gPos;
gColumn = 1;
*string_pos++ = yytext[0];
}
. {
++gColumn;
+ ++gPos;
*string_pos++ = yytext[0];
}
}
-if { gColumn += yyleng; return IF; }
-then { gColumn += yyleng; return THEN; }
-else { gColumn += yyleng; return ELSE; }
-endif { gColumn += yyleng; return ENDIF; }
+if ADVANCE; return IF;
+then ADVANCE; return THEN;
+else ADVANCE; return ELSE;
+endif ADVANCE; return ENDIF;
[a-zA-Z0-9_:/.]+ {
- gColumn += yyleng;
+ ADVANCE;
yylval.str = strdup(yytext);
return STRING;
}
-\&\& { gColumn += yyleng; return AND; }
-\|\| { gColumn += yyleng; return OR; }
-== { gColumn += yyleng; return EQ; }
-!= { gColumn += yyleng; return NE; }
+\&\& ADVANCE; return AND;
+\|\| ADVANCE; return OR;
+== ADVANCE; return EQ;
+!= ADVANCE; return NE;
-[+(),!;] { gColumn += yyleng; return yytext[0]; }
+[+(),!;] ADVANCE; return yytext[0];
-[ \t]+ gColumn += yyleng;
+[ \t]+ ADVANCE;
-(#.*)?\n { ++gLine; gColumn = 1; }
+(#.*)?\n gPos += yyleng; ++gLine; gColumn = 1;
. return BAD;