]> granicus.if.org Git - re2c/commitdiff
Pass unquoted strings to parsing functions.
authorUlya Trofimovich <skvadrik@gmail.com>
Thu, 14 May 2015 12:58:29 +0000 (13:58 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Thu, 14 May 2015 12:58:29 +0000 (13:58 +0100)
In most cases re2c accepts single-quoted or double-quoted strings
in regexp specifications, but if flex-like syntax if enabled, then
re2c accepts unquoted strings.

Before this commit, functions that parse strings into regexps
expected quoted strings, and we had to add quotes in case of
flex-like syntax. That was very inconvenient and in fact
unnecessary, since the first thing parsing functions do is get rid
of quotes.

re2c/bootstrap/scanner_lex.cc
re2c/src/dfa/actions.cc
re2c/src/parse/scanner.cc
re2c/src/parse/scanner.h
re2c/src/parse/scanner_lex.re

index 8834c700487290ebb8897abb9f0c8951bd0cd718..9f35bbb21bc1d325da6e68c226e7f16988bb1ced 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.14.1.dev on Thu May 14 12:49:02 2015*/
+/* Generated by re2c 0.14.1.dev on Thu May 14 13:56:12 2015*/
 #include <stdlib.h>
 #include <string.h>
 #include <iostream>
@@ -950,11 +950,11 @@ yy164:
                                                cur = cursor;
                                                if (bCaseInsensitive || bCaseInverted)
                                                {
-                                                       yylval.regexp = strToCaseInsensitiveRE(raw_token("\""));
+                                                       yylval.regexp = strToCaseInsensitiveRE(token());
                                                }
                                                else
                                                {
-                                                       yylval.regexp = strToRE(raw_token("\""));
+                                                       yylval.regexp = strToRE(token());
                                                }
                                                return STRING;
                                        }
@@ -1280,11 +1280,11 @@ yy218:
                                        cur = cursor;
                                        if (bCaseInverted)
                                        {
-                                               yylval.regexp = strToRE(token());
+                                               yylval.regexp = strToRE(token(1, cur - tok - 2));
                                        }
                                        else
                                        {
-                                               yylval.regexp = strToCaseInsensitiveRE(token());
+                                               yylval.regexp = strToCaseInsensitiveRE(token(1, cur - tok - 2));
                                        }
                                        return STRING;
                                }
@@ -1309,11 +1309,11 @@ yy223:
                                        cur = cursor;
                                        if (bCaseInsensitive || bCaseInverted)
                                        {
-                                               yylval.regexp = strToCaseInsensitiveRE(token());
+                                               yylval.regexp = strToCaseInsensitiveRE(token(1, cur - tok - 2));
                                        }
                                        else
                                        {
-                                               yylval.regexp = strToRE(token());
+                                               yylval.regexp = strToRE(token(1, cur - tok - 2));
                                        }
                                        return STRING;
                                }
index dd512ae8a51d70b53bafdbf47a31b9536c6379f0..b3d576eb597db69f0ab6db22313ecb990d11f04e 100644 (file)
@@ -759,9 +759,6 @@ RegExp * Scanner::matchSymbol(uint32_t c) const
 
 RegExp * Scanner::strToRE(SubStr s) const
 {
-       s.len -= 2;
-       s.str += 1;
-
        if (s.len == 0)
                return new NullOp;
 
@@ -775,9 +772,6 @@ RegExp * Scanner::strToRE(SubStr s) const
 
 RegExp * Scanner::strToCaseInsensitiveRE(SubStr s) const
 {
-       s.len -= 2;
-       s.str += 1;
-
        if (s.len == 0)
                return new NullOp;
 
index 6393bce7106812062829362d7855d4c8295c9a50..168d5a770e64604320e33aa4800f9347228af2aa 100644 (file)
@@ -450,11 +450,6 @@ void Scanner::check_token_length(char *pos, uint32_t len) const
        }
 }
 
-Str Scanner::raw_token(std::string enclosure) const
-{
-       return Str(std::string(enclosure + token().to_string() + enclosure).c_str());
-}
-
 void Scanner::reuse()
 {
        next_label = 0;
index d7ee5d3eb68d29b7ebb55b3cba8cc965e22407d8..9031a9c6feb752b0a10629a64d52f0ae8dd95657 100644 (file)
@@ -86,7 +86,6 @@ public:
        void check_token_length(char *pos, uint32_t len) const;
        SubStr token() const;
        SubStr token(uint32_t start, uint32_t len) const;
-       Str raw_token(std::string enclosure) const;
 
        uint32_t unescape(SubStr &s) const;
        std::string& unescape(SubStr& str_in, std::string& str_out) const;
index 057e5c0296f042f6a298aeef06d9242369274e08..869ee04d1b3dcedc6ba33fee92aad283774cd900 100644 (file)
@@ -256,11 +256,11 @@ scan:
                                        cur = cursor;
                                        if (bCaseInsensitive || bCaseInverted)
                                        {
-                                               yylval.regexp = strToCaseInsensitiveRE(token());
+                                               yylval.regexp = strToCaseInsensitiveRE(token(1, cur - tok - 2));
                                        }
                                        else
                                        {
-                                               yylval.regexp = strToRE(token());
+                                               yylval.regexp = strToRE(token(1, cur - tok - 2));
                                        }
                                        return STRING;
                                }
@@ -269,11 +269,11 @@ scan:
                                        cur = cursor;
                                        if (bCaseInverted)
                                        {
-                                               yylval.regexp = strToRE(token());
+                                               yylval.regexp = strToRE(token(1, cur - tok - 2));
                                        }
                                        else
                                        {
-                                               yylval.regexp = strToCaseInsensitiveRE(token());
+                                               yylval.regexp = strToCaseInsensitiveRE(token(1, cur - tok - 2));
                                        }
                                        return STRING;
                                }
@@ -386,11 +386,11 @@ scan:
                                                cur = cursor;
                                                if (bCaseInsensitive || bCaseInverted)
                                                {
-                                                       yylval.regexp = strToCaseInsensitiveRE(raw_token("\""));
+                                                       yylval.regexp = strToCaseInsensitiveRE(token());
                                                }
                                                else
                                                {
-                                                       yylval.regexp = strToRE(raw_token("\""));
+                                                       yylval.regexp = strToRE(token());
                                                }
                                                return STRING;
                                        }