aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--convert-dtsv0-lexer.l24
-rw-r--r--dtc-lexer.l32
2 files changed, 21 insertions, 35 deletions
diff --git a/convert-dtsv0-lexer.l b/convert-dtsv0-lexer.l
index 64e2916..12b45ea 100644
--- a/convert-dtsv0-lexer.l
+++ b/convert-dtsv0-lexer.l
@@ -17,7 +17,7 @@
* USA
*/
-%option noyywrap nounput stack
+%option noyywrap nounput
%x INCLUDE
%x BYTESTRING
@@ -26,6 +26,11 @@
PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
PATHCHAR ({PROPNODECHAR}|[/])
LABEL [a-zA-Z_][a-zA-Z0-9_]*
+STRING \"([^\\"]|\\.)*\"
+WS [[:space:]]
+COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
+LINECOMMENT "//".*\n
+GAP ({WS}|{COMMENT}|{LINECOMMENT})*
%{
#include <string.h>
@@ -91,16 +96,7 @@ const struct {
%}
%%
-<*>"/include/" {
- ECHO;
- yy_push_state(INCLUDE);
- }
-
-<INCLUDE>\"[^"\n]*\" {
- ECHO;
- yy_pop_state();
- }
-
+<*>"/include/"{GAP}{STRING} ECHO;
<*>\"([^\\"]|\\.)*\" ECHO;
@@ -193,11 +189,7 @@ const struct {
BEGIN(INITIAL);
}
-<*>[[:space:]]+ ECHO;
-
-<*>"/*"([^*]|\*+[^*/])*\*+"/" ECHO;
-
-<*>"//".*\n ECHO;
+<*>{GAP} ECHO;
<*>- { /* Hack to convert old style memreserves */
saw_hyphen = 1;
diff --git a/dtc-lexer.l b/dtc-lexer.l
index 8f15c4d..44dbfd3 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -18,7 +18,7 @@
* USA
*/
-%option noyywrap nounput yylineno stack
+%option noyywrap nounput yylineno
%x INCLUDE
%x BYTESTRING
@@ -28,6 +28,10 @@
PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
PATHCHAR ({PROPNODECHAR}|[/])
LABEL [a-zA-Z_][a-zA-Z0-9_]*
+STRING \"([^\\"]|\\.)*\"
+WS [[:space:]]
+COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
+LINECOMMENT "//".*\n
%{
#include "dtc.h"
@@ -58,22 +62,19 @@ static int pop_input_file(void);
%}
%%
-<*>"/include/" yy_push_state(INCLUDE);
-
-<INCLUDE>\"[^"\n]*\" {
- yytext[strlen(yytext) - 1] = 0;
- push_input_file(yytext + 1);
- yy_pop_state();
+<*>"/include/"{WS}*{STRING} {
+ char *name = strchr(yytext, '\"') + 1;
+ yytext[yyleng-1] = '\0';
+ push_input_file(name);
}
-
<*><<EOF>> {
if (!pop_input_file()) {
yyterminate();
}
}
-<*>\"([^\\"]|\\.)*\" {
+<*>{STRING} {
yylloc.file = srcpos_file;
yylloc.first_line = yylineno;
DPRINT("String: %s\n", yytext);
@@ -197,16 +198,9 @@ static int pop_input_file(void);
return DT_INCBIN;
}
-<*>[[:space:]]+ /* eat whitespace */
-
-<*>"/*"([^*]|\*+[^*/])*\*+"/" {
- yylloc.file = srcpos_file;
- yylloc.first_line = yylineno;
- DPRINT("Comment: %s\n", yytext);
- /* eat comments */
- }
-
-<*>"//".*\n /* eat line comments */
+<*>{WS}+ /* eat whitespace */
+<*>{COMMENT}+ /* eat C-style comments */
+<*>{LINECOMMENT}+ /* eat C++-style comments */
<*>. {
yylloc.file = srcpos_file;