From: Ulya Fokanova Date: Tue, 25 Feb 2014 11:08:42 +0000 (+0300) Subject: Allow all encoding flags in inplace configurations regardless to '-r' flag. X-Git-Tag: 0.13.7.1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e30ce19771d414c005e33dbcf4f14ce39ac75d99;p=re2c Allow all encoding flags in inplace configurations regardless to '-r' flag. Also allow use '-r' together with '-e'. Added test. --- diff --git a/re2c/code.cc b/re2c/code.cc index 7b881c00..3345f36e 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -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 diff --git a/re2c/htdocs/manual.html.in b/re2c/htdocs/manual.html.in index 7000cca5..add8fa4d 100755 --- a/re2c/htdocs/manual.html.in +++ b/re2c/htdocs/manual.html.in @@ -133,7 +133,8 @@ Specify the output file.

'/*!rules:re2c'. In this mode no '/*!re2c' block and exactly one '/*!rules:re2c' must be present. The rules are being saved and used by every '/*!use:re2c' block that follows. These blocks can contain -inplace configurations, especially 're2c:flags:w' and 're2c:flags:u'. +inplace configurations, especially 're2c:flags:e', 're2c:flags:w', +'re2c:flags:x', 're2c:flags:u' and 're2c:flags:8'. That way it is possible to create the same scanner multiple times for different character types, different input mechanisms or different output mechanisms. The '/*!use:re2c' blocks can also contain additional rules that will be diff --git a/re2c/main.cc b/re2c/main.cc index 86679eee..d5a122ec 100644 --- a/re2c/main.cc +++ b/re2c/main.cc @@ -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"; diff --git a/re2c/re2c.1.in b/re2c/re2c.1.in index db5289f3..d3d8c9e3 100644 --- a/re2c/re2c.1.in +++ b/re2c/re2c.1.in @@ -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 index 00000000..5b16de4d --- /dev/null +++ b/re2c/test/inplace_config_encoding.is.c @@ -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 index 00000000..64761ebf --- /dev/null +++ b/re2c/test/inplace_config_encoding.is.re @@ -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;} +*/