lexer: accept single quoted string literals
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 31 Dec 2013 00:07:06 +0000 (00:07 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 31 Dec 2013 00:15:59 +0000 (00:15 +0000)
lexer.l
parser.y

diff --git a/lexer.l b/lexer.l
index a480ca7..18937e8 100644 (file)
--- a/lexer.l
+++ b/lexer.l
@@ -101,17 +101,23 @@ WS                        [ \t\n]*
 
 %%
 
 
 %%
 
-\" {
+["'] {
        s->str_ptr = s->str_buf;
        s->str_ptr = s->str_buf;
+       s->str_quote = *yytext;
        memset(s->str_buf, 0, sizeof(s->str_buf));
        BEGIN(STRING);
 }
 
 <STRING>{
        memset(s->str_buf, 0, sizeof(s->str_buf));
        BEGIN(STRING);
 }
 
 <STRING>{
-       \" {
-               BEGIN(INITIAL);
-               yylval.op = jp_alloc_op(T_STRING, 0, s->str_buf);
-               return T_STRING;
+       ["'] {
+               if (*yytext == s->str_quote)
+               {
+                       BEGIN(INITIAL);
+                       yylval.op = jp_alloc_op(T_STRING, 0, s->str_buf);
+                       return T_STRING;
+               }
+
+               str_put(s, *yytext);
        }
 
        \\([0-3][0-7]{1,2}|[0-7]{0,2})  { str_decode(s, yytext + 1, 8); }
        }
 
        \\([0-3][0-7]{1,2}|[0-7]{0,2})  { str_decode(s, yytext + 1, 8); }
@@ -126,7 +132,7 @@ WS                  [ \t\n]*
        \\t                                                             { str_put(s, '\t'); }
        \\v                                                             { str_put(s, '\v'); }
        \\.                                                             { str_put(s, *yytext); }
        \\t                                                             { str_put(s, '\t'); }
        \\v                                                             { str_put(s, '\v'); }
        \\.                                                             { str_put(s, *yytext); }
-       [^\\"]+                                                 { while (*yytext) str_put(s, *yytext++); }
+       [^\\"']+                                                { while (*yytext) str_put(s, *yytext++); }
 }
 
 {BOOL} {
 }
 
 {BOOL} {
index f5e8966..75c3340 100644 (file)
--- a/parser.y
+++ b/parser.y
@@ -59,6 +59,7 @@ struct jp_state {
        struct jp_opcode *pool;
        struct jp_opcode *path;
        const char *error;
        struct jp_opcode *pool;
        struct jp_opcode *path;
        const char *error;
+       char str_quote;
        char str_buf[128];
        char *str_ptr;
 };
        char str_buf[128];
        char *str_ptr;
 };