]> granicus.if.org Git - re2c/commitdiff
Allow all encoding flags in inplace configurations regardless to '-r' flag.
authorUlya Fokanova <skvadrik@gmail.com>
Tue, 25 Feb 2014 11:08:42 +0000 (14:08 +0300)
committerUlya Fokanova <skvadrik@gmail.com>
Tue, 25 Feb 2014 11:08:42 +0000 (14:08 +0300)
Also allow use '-r' together with '-e'. Added test.

re2c/code.cc
re2c/htdocs/manual.html.in
re2c/main.cc
re2c/re2c.1.in
re2c/test/inplace_config_encoding.is.c [new file with mode: 0644]
re2c/test/inplace_config_encoding.is.re [new file with mode: 0644]

index 7b881c006875864e8c7ffbbf58215a27b8fde22f..3345f36e5adae1c4d6ef0eae5acd6e30bfce935e 100644 (file)
@@ -2244,12 +2244,17 @@ void Scanner::config(const Str& cfg, int num)
        {
                bUseYYSetStateNaked = num != 0;
        }
+       else if (cfg.to_string() == "flags:e")
+       {
+               if (num != 0)
+                       encoding.setEBCDIC();
+               else
+                       encoding.unsetEBCDIC();
+               if (encoding.isBad())
+                       fatal("Cannot set '-e' switch: please reset '-w', '-x', '-u' and '-8' switches at first.\n");
+       }
        else if (cfg.to_string() == "flags:u")
        {
-               if (!rFlag)
-               {
-                       fatalf("cannot use configuration name '%s' without -r flag", cfg.to_string().c_str());
-               }
                if (num != 0)
                        encoding.setUTF32();
                else
@@ -2259,10 +2264,6 @@ void Scanner::config(const Str& cfg, int num)
        }
        else if (cfg.to_string() == "flags:w")
        {
-               if (!rFlag)
-               {
-                       fatalf("cannot use configuration name '%s' without -r flag", cfg.to_string().c_str());
-               }
                if (num != 0)
                        encoding.setUCS2();
                else
@@ -2272,10 +2273,6 @@ void Scanner::config(const Str& cfg, int num)
        }
        else if (cfg.to_string() == "flags:x")
        {
-               if (!rFlag)
-               {
-                       fatalf("cannot use configuration name '%s' without -r flag", cfg.to_string().c_str());
-               }
                if (num != 0)
                        encoding.setUTF16();
                else
@@ -2285,10 +2282,6 @@ void Scanner::config(const Str& cfg, int num)
        }
        else if (cfg.to_string() == "flags:8")
        {
-               if (!rFlag)
-               {
-                       fatalf("cannot use configuration name '%s' without -r flag", cfg.to_string().c_str());
-               }
                if (num != 0)
                        encoding.setUTF8();
                else
index 7000cca5037a452de928f477a0b01a15e74c6523..add8fa4d84d3bfa0c958c01fb836c2a33599220b 100755 (executable)
@@ -133,7 +133,8 @@ Specify the output file.<br /><br /></dd>
 '<b>/*!rules:re2c</b>'. In this mode no '<b>/*!re2c</b>' block and exactly one
 '<b>/*!rules:re2c</b>' must be present. The rules are being saved and used by
 every '<b>/*!use:re2c</b>' block that follows. These blocks can contain
-inplace configurations, especially '<b>re2c:flags:w</b>' and '<b>re2c:flags:u</b>'.
+inplace configurations, especially '<b>re2c:flags:e</b>', '<b>re2c:flags:w</b>', 
+'<b>re2c:flags:x</b>', '<b>re2c:flags:u</b>' and '<b>re2c:flags:8</b>'.
 That way it is possible to create the same scanner multiple times for different
 character types, different input mechanisms or different output mechanisms.
 The '<b>/*!use:re2c</b>' blocks can also contain additional rules that will be
index 86679eee873c86dd57b5b66f0c41a64f33de560c..d5a122ec9bd54ebff6cf63d3e948fc82842b9363 100644 (file)
@@ -154,7 +154,7 @@ static void usage()
        "-e     --ecb            Generate a parser that supports EBCDIC. The generated code\n"
        "                        can deal with any character up to 0xFF. In this mode re2c\n"
        "                        assumes that input character size is 1 byte. This switch is\n"
-       "                        incompatible with -w, -u, -x, -8 and -r\n"
+       "                        incompatible with -w, -u, -x and -8\n"
        "\n"
        "-f     --storable-state Generate a scanner that supports storable states.\n"
        "\n"
@@ -168,7 +168,6 @@ static void usage()
        "-o of  --output=of      Specify the output file (of) instead of stdout\n"
        "\n"
        "-r     --reusable       Allow reuse of scanner definitions.\n"
-       "                        This cannot be used together with -e switch.\n"
        "\n"
        "-s     --nested-ifs     Generate nested ifs for some switches. Many compilers\n"
        "                        need this assist to generate better code.\n"
@@ -373,12 +372,6 @@ int main(int argc, char *argv[])
                return 2;
        }
 
-       if (rFlag && encoding.isEBCDIC())
-       {
-               std::cerr << "re2c: error: Cannot combine -e with -r switch\n";
-               return 2;
-       }
-
        if (encoding.isBad())
        {
                std::cerr << "re2c: error: Only one of switches -e, -w, -x, -u and -8 must be set\n";
index db5289f3e45feeff1ca845b67adde06f9240d64d..d3d8c9e37b3ac0705ef759eb7381ba3825dfeac3 100644 (file)
@@ -150,7 +150,8 @@ Allows reuse of scanner definitions with '\fB/*!use:re2c\fP' after
 '\fB/*!rules:re2c\fP'. In this mode no '\fB/*!re2c\fP' block and exactly one
 '\fB/*!rules:re2c\fP' must be present. The rules are being saved and used by
 every '\fB/*!use:re2c\fP' block that follows. These blocks can contain
-inplace configurations, especially '\fBre2c:flags:w\fP' and '\fBre2c:flags:u\fP'.
+inplace configurations, especially '\fBre2c:flags:e\fP', '\fBre2c:flags:w\fP', 
+'\fBre2c:flags:x\fP', '\fBre2c:flags:u\fP' and '\fBre2c:flags:8\fP'.
 That way it is possible to create the same scanner multiple times for different
 character types, different input mechanisms or different output mechanisms.
 The '\fB/*!use:re2c\fP' blocks can also contain additional rules that will be
diff --git a/re2c/test/inplace_config_encoding.is.c b/re2c/test/inplace_config_encoding.is.c
new file mode 100644 (file)
index 0000000..5b16de4
--- /dev/null
@@ -0,0 +1,105 @@
+/* Generated by re2c */
+EBCDIC:
+
+{
+       YYCTYPE yych;
+
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       if (yych == 0x81) goto yy4;
+       ++YYCURSOR;
+       {return DEFAULT;}
+yy4:
+       ++YYCURSOR;
+       {return 0;}
+}
+
+
+UCS2:
+
+{
+       YYCTYPE yych;
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       if (yych >= 0xFFFF) goto yy10;
+       ++YYCURSOR;
+       {return DEFAULT;}
+yy10:
+       ++YYCURSOR;
+       {return 0;}
+}
+
+
+UTF16:
+
+{
+       YYCTYPE yych;
+       if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
+       yych = *YYCURSOR;
+       if (yych == 0xDBFF) goto yy16;
+       ++YYCURSOR;
+yy15:
+       {return DEFAULT;}
+yy16:
+       yych = *++YYCURSOR;
+       if (yych != 0xDFFF) goto yy15;
+       ++YYCURSOR;
+       {return 0;}
+}
+
+
+UTF32:
+
+{
+       YYCTYPE yych;
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       if (yych >= 0x0010FFFF) goto yy23;
+       ++YYCURSOR;
+       {return DEFAULT;}
+yy23:
+       ++YYCURSOR;
+       {return 0;}
+}
+
+
+UTF8:
+
+{
+       YYCTYPE yych;
+       if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4);
+       yych = *YYCURSOR;
+       if (yych == 0xF4) goto yy29;
+       ++YYCURSOR;
+yy28:
+       {return DEFAULT;}
+yy29:
+       yych = *(YYMARKER = ++YYCURSOR);
+       if (yych != 0x8F) goto yy28;
+       yych = *++YYCURSOR;
+       if (yych == 0xBF) goto yy32;
+yy31:
+       YYCURSOR = YYMARKER;
+       goto yy28;
+yy32:
+       yych = *++YYCURSOR;
+       if (yych != 0xBF) goto yy31;
+       ++YYCURSOR;
+       {return 0;}
+}
+
+
+ASCII:
+
+{
+       YYCTYPE yych;
+       if (YYLIMIT <= YYCURSOR) YYFILL(1);
+       yych = *YYCURSOR;
+       if (yych == 'a') goto yy39;
+       ++YYCURSOR;
+       {return DEFAULT;}
+yy39:
+       ++YYCURSOR;
+       {return 0;}
+}
+
diff --git a/re2c/test/inplace_config_encoding.is.re b/re2c/test/inplace_config_encoding.is.re
new file mode 100644 (file)
index 0000000..64761eb
--- /dev/null
@@ -0,0 +1,45 @@
+EBCDIC:
+/*!re2c
+       re2c:flags:e = 1;
+       "a"     {return 0;}
+       *       {return DEFAULT;}
+*/
+
+UCS2:
+/*!re2c
+       re2c:flags:e = 0;
+       re2c:flags:w = 1;
+       "\uFFFF"        {return 0;}
+       *               {return DEFAULT;}
+*/
+
+UTF16:
+/*!re2c
+       re2c:flags:w = 0;
+       re2c:flags:x = 1;
+       "\U0010FFFF"    {return 0;}
+       *               {return DEFAULT;}
+*/
+
+UTF32:
+/*!re2c
+       re2c:flags:x = 0;
+       re2c:flags:u = 1;
+       "\U0010FFFF"    {return 0;}
+       *               {return DEFAULT;}
+*/
+
+UTF8:
+/*!re2c
+       re2c:flags:u = 0;
+       re2c:flags:8 = 1;
+       "\U0010FFFF"    {return 0;}
+       *               {return DEFAULT;}
+*/
+
+ASCII:
+/*!re2c
+       re2c:flags:8 = 0;
+       "a"     {return 0;}
+       *       {return DEFAULT;}
+*/