From: Ulya Trofimovich Date: Sun, 19 Jul 2015 14:22:47 +0000 (+0100) Subject: New re2c-based parser for command line options. X-Git-Tag: 0.15~195 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b6e57cf2a1843d05ee7187d6a5f631e54a5da3d;p=re2c New re2c-based parser for command line options. --- diff --git a/re2c/Makefile.am b/re2c/Makefile.am index bca40f8c..9df554af 100644 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -22,6 +22,8 @@ SRC_HDR = \ src/codegen/scc.h \ src/codegen/skeleton/path.h \ src/codegen/skeleton/skeleton.h \ + src/conf/msg.h \ + src/conf/opt.h \ src/ir/bytecode/charset.h \ src/ir/bytecode/bytecode.h \ src/ir/bytecode/ins.h \ @@ -47,7 +49,6 @@ SRC_HDR = \ src/ir/regexp/regexp_close.h \ src/ir/rule_rank.h \ src/globals.h \ - src/mbo_getopt.h \ src/parse/extop.h \ src/parse/input.h \ src/parse/parser.h \ @@ -82,6 +83,8 @@ SRC = \ src/codegen/scc.cc \ src/codegen/skeleton/path.cc \ src/codegen/skeleton/skeleton.cc \ + src/conf/msg.cc \ + src/conf/opt.cc \ src/ir/bytecode/bytecode.cc \ src/ir/bytecode/ins.cc \ src/ir/bytecode/charset.cc \ @@ -102,7 +105,6 @@ SRC = \ src/ir/regexp/regexp.cc \ src/ir/rule_rank.cc \ src/main.cc \ - src/mbo_getopt.cc \ src/parse/input.cc \ src/parse/scanner.cc \ src/parse/unescape.cc \ @@ -113,16 +115,19 @@ re2c_SOURCES = \ # autogenerated sources AUTOGEN_SCANNER = scanner_lex.cc +AUTOGEN_PARSEOPT = parse_opts.cc AUTOGEN_PARSER = parser.cc AUTOGEN_PARSER_HDR = y.tab.h AUTOGEN = \ $(AUTOGEN_PARSER) \ $(AUTOGEN_PARSER_HDR) \ + $(AUTOGEN_PARSEOPT) \ $(AUTOGEN_SCANNER) nodist_re2c_SOURCES = $(AUTOGEN) # bootstrap sources BOOTSTRAP_SCANNER = bootstrap/scanner_lex.cc +BOOTSTRAP_PARSEOPT = bootstrap/parse_opts.cc BOOTSTRAP_PARSER = bootstrap/parser.cc BOOTSTRAP_PARSER_HDR = bootstrap/y.tab.h BOOTSTRAP_DOC_MAN = bootstrap/re2c.1 @@ -132,14 +137,17 @@ BOOTSTRAP = \ $(BOOTSTRAP_DOC_MAN) \ $(BOOTSTRAP_PARSER) \ $(BOOTSTRAP_PARSER_HDR) \ + $(BOOTSTRAP_PARSEOPT) \ $(BOOTSTRAP_SCANNER) # custom sources CUSTOM_SCANNER = src/parse/scanner_lex.re +CUSTOM_PARSEOPT = src/conf/parse_opts.re CUSTOM_PARSER = src/parse/parser.ypp CUSTOM = \ $(CUSTOM_SCANNER) \ - $(CUSTOM_PARSER) + $(CUSTOM_PARSER) \ + $(CUSTOM_PARSEOPT) # docs SRC_DOC = doc/re2c.ad @@ -195,10 +203,21 @@ $(AUTOGEN_SCANNER): $(CUSTOM_SCANNER) cp $(top_srcdir)/$(BOOTSTRAP_SCANNER) $@; \ fi +# rule has side effects: +# - bootstrap file in source directory, must manually prepend $(top_srcdir) +$(AUTOGEN_PARSEOPT): $(CUSTOM_PARSEOPT) + @if test -x $(RE2C); \ + then \ + $(RE2C) $(RE2CFLAGS) -o $@ $< && \ + cp $@ $(top_srcdir)/$(BOOTSTRAP_PARSEOPT); \ + else \ + cp $(top_srcdir)/$(BOOTSTRAP_PARSEOPT) $@; \ + fi + # rebuild lexer (just in case it was bootstrapped) and rebuild re2c .PHONY: bootstrap bootstrap: all - rm $(AUTOGEN_SCANNER) + rm $(AUTOGEN_SCANNER) $(AUTOGEN_PARSEOPT) make all .PHONY: docs diff --git a/re2c/bootstrap/parse_opts.cc b/re2c/bootstrap/parse_opts.cc new file mode 100644 index 00000000..f0707db0 --- /dev/null +++ b/re2c/bootstrap/parse_opts.cc @@ -0,0 +1,1307 @@ +/* Generated by re2c 0.14.3 on Sun Jul 19 12:06:48 2015 */ +#include + +#include "src/conf/msg.h" +#include "src/conf/opt.h" + +namespace re2c +{ + +parse_opts_t parse_opts (int argc, char ** argv, Opt & opts) +{ + if (argc == 1) + { + usage (); + return EXIT_FAIL; + } + +#define YYCTYPE char + YYCTYPE * YYCURSOR; + YYCTYPE * YYMARKER; + + + +opt: + YYCURSOR = *++argv; + if (YYCURSOR == NULL) + { + goto end; + } + +{ + YYCTYPE yych; + static const unsigned char yybm[] = { + 0, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + }; + + yych = *YYCURSOR; + if (yych <= 0x00) goto yy2; + if (yych == '-') goto yy5; + goto yy4; +yy2: + ++YYCURSOR; + { + error ("bad option: %s\n", *argv); + return EXIT_FAIL; + } +yy4: + yych = *(YYMARKER = ++YYCURSOR); + goto yy14; +yy5: + ++YYCURSOR; + if ((yych = *YYCURSOR) <= 0x00) goto yy9; + if (yych == '-') goto yy7; + { goto opt_short; } +yy7: + ++YYCURSOR; + if ((yych = *YYCURSOR) <= 0x00) goto yy11; + { goto opt_long; } +yy9: + ++YYCURSOR; + { opts.source (""); goto opt; } +yy11: + ++YYCURSOR; + { goto end; } +yy13: + ++YYCURSOR; + yych = *YYCURSOR; +yy14: + if (yybm[0+yych] & 128) { + goto yy13; + } + ++YYCURSOR; + { opts.source (*argv); goto opt; } +} + + +opt_short: + +{ + YYCTYPE yych; + yych = *YYCURSOR; + if (yych <= 'c') { + if (yych <= 'C') { + if (yych <= '7') { + if (yych <= 0x00) goto yy19; + if (yych == '1') goto yy23; + goto yy21; + } else { + if (yych <= '8') goto yy25; + if (yych == '?') goto yy27; + goto yy21; + } + } else { + if (yych <= 'U') { + if (yych <= 'D') goto yy29; + if (yych == 'F') goto yy31; + goto yy21; + } else { + if (yych <= 'V') goto yy33; + if (yych <= 'a') goto yy21; + if (yych <= 'b') goto yy35; + goto yy37; + } + } + } else { + if (yych <= 'o') { + if (yych <= 'g') { + if (yych <= 'd') goto yy39; + if (yych <= 'e') goto yy41; + if (yych <= 'f') goto yy43; + goto yy45; + } else { + if (yych <= 'h') goto yy27; + if (yych <= 'i') goto yy47; + if (yych <= 'n') goto yy21; + goto yy49; + } + } else { + if (yych <= 't') { + if (yych <= 'q') goto yy21; + if (yych <= 'r') goto yy51; + if (yych <= 's') goto yy53; + goto yy55; + } else { + if (yych <= 'v') { + if (yych <= 'u') goto yy57; + goto yy59; + } else { + if (yych <= 'w') goto yy61; + if (yych <= 'x') goto yy63; + goto yy21; + } + } + } + } +yy19: + ++YYCURSOR; + { goto opt; } +yy21: + ++YYCURSOR; + { + error ("bad short option: %s\n", *argv); + return EXIT_FAIL; + } +yy23: + ++YYCURSOR; + { goto opt_short; } +yy25: + ++YYCURSOR; + { if (!opts.utf_8 ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } +yy27: + ++YYCURSOR; + { usage (); return EXIT_OK; } +yy29: + ++YYCURSOR; + { opts.emit_dot (); goto opt_short; } +yy31: + ++YYCURSOR; + { opts.flex_syntax (); goto opt_short; } +yy33: + ++YYCURSOR; + { vernum (); return EXIT_OK; } +yy35: + ++YYCURSOR; + { opts.bit_vectors (); goto opt_short; } +yy37: + ++YYCURSOR; + { opts.start_conditions (); goto opt_short; } +yy39: + ++YYCURSOR; + { opts.debug_output (); goto opt_short; } +yy41: + ++YYCURSOR; + { if (!opts.ecb ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } +yy43: + ++YYCURSOR; + { opts.storable_state (); goto opt_short; } +yy45: + ++YYCURSOR; + { opts.computed_gotos (); goto opt_short; } +yy47: + ++YYCURSOR; + { opts.no_debug_info (); goto opt_short; } +yy49: + ++YYCURSOR; + if ((yych = *YYCURSOR) <= 0x00) goto yy67; + { *argv = YYCURSOR; goto opt_output; } +yy51: + ++YYCURSOR; + { opts.reusable (); goto opt_short; } +yy53: + ++YYCURSOR; + { opts.nested_ifs (); goto opt_short; } +yy55: + ++YYCURSOR; + if ((yych = *YYCURSOR) <= 0x00) goto yy65; + { *argv = YYCURSOR; goto opt_header; } +yy57: + ++YYCURSOR; + { if (!opts.unicode ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } +yy59: + ++YYCURSOR; + { version (); return EXIT_OK; } +yy61: + ++YYCURSOR; + { if (!opts.wide_chars ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } +yy63: + ++YYCURSOR; + { if (!opts.utf_16 ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } +yy65: + ++YYCURSOR; + { YYCURSOR = *++argv; goto opt_header; } +yy67: + ++YYCURSOR; + { YYCURSOR = *++argv; goto opt_output; } +} + + +opt_long: + +{ + YYCTYPE yych; + yych = *YYCURSOR; + switch (yych) { + case 'b': goto yy73; + case 'c': goto yy74; + case 'd': goto yy75; + case 'e': goto yy76; + case 'f': goto yy77; + case 'h': goto yy78; + case 'i': goto yy79; + case 'n': goto yy80; + case 'o': goto yy81; + case 'r': goto yy82; + case 's': goto yy83; + case 't': goto yy84; + case 'u': goto yy85; + case 'v': goto yy86; + case 'w': goto yy87; + default: goto yy71; + } +yy71: + ++YYCURSOR; +yy72: + { + error ("bad long option: %s\n", *argv); + return EXIT_FAIL; + } +yy73: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'i') goto yy369; + goto yy72; +yy74: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'a') goto yy329; + if (yych == 'o') goto yy330; + goto yy72; +yy75: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'e') goto yy316; + goto yy72; +yy76: + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= 'l') { + if (yych == 'c') goto yy278; + goto yy72; + } else { + if (yych <= 'm') goto yy276; + if (yych <= 'n') goto yy277; + goto yy72; + } +yy77: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'l') goto yy264; + goto yy72; +yy78: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'e') goto yy259; + goto yy72; +yy79: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'n') goto yy253; + goto yy72; +yy80: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'e') goto yy212; + if (yych == 'o') goto yy211; + goto yy72; +yy81: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'u') goto yy204; + goto yy72; +yy82: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'e') goto yy195; + goto yy72; +yy83: + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= 'j') { + if (yych == 'i') goto yy143; + goto yy72; + } else { + if (yych <= 'k') goto yy144; + if (yych == 't') goto yy145; + goto yy72; + } +yy84: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'y') goto yy131; + goto yy72; +yy85: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'n') goto yy114; + if (yych == 't') goto yy113; + goto yy72; +yy86: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'e') goto yy100; + goto yy72; +yy87: + yych = *(YYMARKER = ++YYCURSOR); + if (yych != 'i') goto yy72; + yych = *++YYCURSOR; + if (yych == 'd') goto yy90; +yy89: + YYCURSOR = YYMARKER; + goto yy72; +yy90: + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'c') goto yy89; + yych = *++YYCURSOR; + if (yych != 'h') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 'r') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { if (!opts.wide_chars ()) { error_encoding (); return EXIT_FAIL; } goto opt; } +yy100: + yych = *++YYCURSOR; + if (yych != 'r') goto yy89; + yych = *++YYCURSOR; + if (yych == 'n') goto yy102; + if (yych == 's') goto yy103; + goto yy89; +yy102: + yych = *++YYCURSOR; + if (yych == 'u') goto yy109; + goto yy89; +yy103: + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { version (); return EXIT_OK; } +yy109: + yych = *++YYCURSOR; + if (yych != 'm') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { vernum (); return EXIT_OK; } +yy113: + yych = *++YYCURSOR; + if (yych == 'f') goto yy122; + goto yy89; +yy114: + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'c') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { if (!opts.unicode ()) { error_encoding (); return EXIT_FAIL; } goto opt; } +yy122: + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych == '1') goto yy124; + if (yych == '8') goto yy125; + goto yy89; +yy124: + yych = *++YYCURSOR; + if (yych == '6') goto yy128; + goto yy89; +yy125: + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { if (!opts.utf_8 ()) { error_encoding (); return EXIT_FAIL; } goto opt; } +yy128: + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { if (!opts.utf_16 ()) { error_encoding (); return EXIT_FAIL; } goto opt; } +yy131: + yych = *++YYCURSOR; + if (yych != 'p') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'h') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'r') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { goto opt_header; } +yy143: + yych = *++YYCURSOR; + if (yych == 'n') goto yy184; + goto yy89; +yy144: + yych = *++YYCURSOR; + if (yych == 'e') goto yy176; + goto yy89; +yy145: + yych = *++YYCURSOR; + if (yych == 'a') goto yy146; + if (yych == 'o') goto yy147; + goto yy89; +yy146: + yych = *++YYCURSOR; + if (yych == 'r') goto yy161; + goto yy89; +yy147: + yych = *++YYCURSOR; + if (yych != 'r') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 'b') goto yy89; + yych = *++YYCURSOR; + if (yych != 'l') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.storable_state (); goto opt; } +yy161: + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'c') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.start_conditions (); goto opt; } +yy176: + yych = *++YYCURSOR; + if (yych != 'l') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.skeleton (); goto opt; } +yy184: + yych = *++YYCURSOR; + if (yych != 'g') goto yy89; + yych = *++YYCURSOR; + if (yych != 'l') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'p') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { goto opt; } +yy195: + yych = *++YYCURSOR; + if (yych != 'u') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 'b') goto yy89; + yych = *++YYCURSOR; + if (yych != 'l') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.reusable (); goto opt; } +yy204: + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'p') goto yy89; + yych = *++YYCURSOR; + if (yych != 'u') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { goto opt_output; } +yy211: + yych = *++YYCURSOR; + if (yych == '-') goto yy223; + goto yy89; +yy212: + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'f') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.nested_ifs (); goto opt; } +yy223: + yych = *++YYCURSOR; + if (yych == 'd') goto yy225; + if (yych != 'g') goto yy89; + yych = *++YYCURSOR; + if (yych == 'e') goto yy237; + goto yy89; +yy225: + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'b') goto yy89; + yych = *++YYCURSOR; + if (yych != 'u') goto yy89; + yych = *++YYCURSOR; + if (yych != 'g') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych != 'f') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.no_debug_info (); goto opt; } +yy237: + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'r') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.no_generation_date (); goto opt; } +yy253: + yych = *++YYCURSOR; + if (yych != 'p') goto yy89; + yych = *++YYCURSOR; + if (yych != 'u') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { goto opt_input; } +yy259: + yych = *++YYCURSOR; + if (yych != 'l') goto yy89; + yych = *++YYCURSOR; + if (yych != 'p') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { usage (); return EXIT_OK; } +yy264: + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'x') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych != 'y') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 'x') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.flex_syntax (); goto opt; } +yy276: + yych = *++YYCURSOR; + if (yych == 'i') goto yy297; + if (yych == 'p') goto yy298; + goto yy89; +yy277: + yych = *++YYCURSOR; + if (yych == 'c') goto yy282; + goto yy89; +yy278: + yych = *++YYCURSOR; + if (yych != 'b') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { if (!opts.ecb ()) { error_encoding (); return EXIT_FAIL; } goto opt; } +yy282: + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych != 'g') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'p') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'l') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'c') goto yy89; + yych = *++YYCURSOR; + if (yych != 'y') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { goto opt_encoding_policy; } +yy297: + yych = *++YYCURSOR; + if (yych == 't') goto yy309; + goto yy89; +yy298: + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'y') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'c') goto yy89; + yych = *++YYCURSOR; + if (yych != 'l') goto yy89; + yych = *++YYCURSOR; + if (yych != 'a') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { goto opt_empty_class; } +yy309: + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.emit_dot (); goto opt; } +yy316: + yych = *++YYCURSOR; + if (yych != 'b') goto yy89; + yych = *++YYCURSOR; + if (yych != 'u') goto yy89; + yych = *++YYCURSOR; + if (yych != 'g') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'u') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'p') goto yy89; + yych = *++YYCURSOR; + if (yych != 'u') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.debug_output (); goto opt; } +yy329: + yych = *++YYCURSOR; + if (yych == 's') goto yy345; + goto yy89; +yy330: + yych = *++YYCURSOR; + if (yych != 'm') goto yy89; + yych = *++YYCURSOR; + if (yych != 'p') goto yy89; + yych = *++YYCURSOR; + if (yych != 'u') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'g') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.computed_gotos (); goto opt; } +yy345: + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych == 's') goto yy351; + if (yych != 'v') goto yy89; + yych = *++YYCURSOR; + if (yych == 'e') goto yy362; + goto yy89; +yy351: + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'n') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'i') goto yy89; + yych = *++YYCURSOR; + if (yych != 'v') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.case_insensitive (); goto opt; } +yy362: + yych = *++YYCURSOR; + if (yych != 'r') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'd') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.case_inverted (); goto opt; } +yy369: + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != '-') goto yy89; + yych = *++YYCURSOR; + if (yych != 'v') goto yy89; + yych = *++YYCURSOR; + if (yych != 'e') goto yy89; + yych = *++YYCURSOR; + if (yych != 'c') goto yy89; + yych = *++YYCURSOR; + if (yych != 't') goto yy89; + yych = *++YYCURSOR; + if (yych != 'o') goto yy89; + yych = *++YYCURSOR; + if (yych != 'r') goto yy89; + yych = *++YYCURSOR; + if (yych != 's') goto yy89; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy89; + ++YYCURSOR; + { opts.bit_vectors (); goto opt; } +} + + +opt_output: + +{ + YYCTYPE yych; + static const unsigned char yybm[] = { + 0, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + }; + yych = *YYCURSOR; + if (yych <= 0x00) goto yy383; + if (yych != '-') goto yy385; +yy383: + ++YYCURSOR; + { + error ("bad argument to option -o, --output: %s\n", *argv); + return EXIT_FAIL; + } +yy385: + yych = *(YYMARKER = ++YYCURSOR); + goto yy387; +yy386: + ++YYCURSOR; + yych = *YYCURSOR; +yy387: + if (yybm[0+yych] & 128) { + goto yy386; + } + ++YYCURSOR; + { opts.output (*argv); goto opt; } +} + + +opt_header: + +{ + YYCTYPE yych; + static const unsigned char yybm[] = { + 0, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + }; + yych = *YYCURSOR; + if (yych <= 0x00) goto yy392; + if (yych != '-') goto yy394; +yy392: + ++YYCURSOR; + { + error ("bad argument to option -t, --type-header: %s\n", *argv); + return EXIT_FAIL; + } +yy394: + yych = *(YYMARKER = ++YYCURSOR); + goto yy396; +yy395: + ++YYCURSOR; + yych = *YYCURSOR; +yy396: + if (yybm[0+yych] & 128) { + goto yy395; + } + ++YYCURSOR; + { opts.type_header (*argv); goto opt; } +} + + +opt_encoding_policy: + YYCURSOR = *++argv; + +{ + YYCTYPE yych; + yych = *YYCURSOR; + if (yych <= 'h') { + if (yych == 'f') goto yy403; + } else { + if (yych <= 'i') goto yy404; + if (yych == 's') goto yy405; + } + ++YYCURSOR; +yy402: + { + error ("bad argument to option --encoding-policy (expected: ignore | substitute | fail): %s\n", *argv); + return EXIT_FAIL; + } +yy403: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'a') goto yy425; + goto yy402; +yy404: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'g') goto yy418; + goto yy402; +yy405: + yych = *(YYMARKER = ++YYCURSOR); + if (yych != 'u') goto yy402; + yych = *++YYCURSOR; + if (yych == 'b') goto yy408; +yy407: + YYCURSOR = YYMARKER; + goto yy402; +yy408: + yych = *++YYCURSOR; + if (yych != 's') goto yy407; + yych = *++YYCURSOR; + if (yych != 't') goto yy407; + yych = *++YYCURSOR; + if (yych != 'i') goto yy407; + yych = *++YYCURSOR; + if (yych != 't') goto yy407; + yych = *++YYCURSOR; + if (yych != 'u') goto yy407; + yych = *++YYCURSOR; + if (yych != 't') goto yy407; + yych = *++YYCURSOR; + if (yych != 'e') goto yy407; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy407; + ++YYCURSOR; + { opts.encoding_policy (Enc::POLICY_SUBSTITUTE); goto opt; } +yy418: + yych = *++YYCURSOR; + if (yych != 'n') goto yy407; + yych = *++YYCURSOR; + if (yych != 'o') goto yy407; + yych = *++YYCURSOR; + if (yych != 'r') goto yy407; + yych = *++YYCURSOR; + if (yych != 'e') goto yy407; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy407; + ++YYCURSOR; + { opts.encoding_policy (Enc::POLICY_IGNORE); goto opt; } +yy425: + yych = *++YYCURSOR; + if (yych != 'i') goto yy407; + yych = *++YYCURSOR; + if (yych != 'l') goto yy407; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy407; + ++YYCURSOR; + { opts.encoding_policy (Enc::POLICY_FAIL); goto opt; } +} + + +opt_input: + YYCURSOR = *++argv; + +{ + YYCTYPE yych; + yych = *YYCURSOR; + if (yych <= 'b') goto yy432; + if (yych <= 'c') goto yy434; + if (yych <= 'd') goto yy435; +yy432: + ++YYCURSOR; +yy433: + { + error ("bad argument to option --input (expected: default | custom): %s\n", *argv); + return EXIT_FAIL; + } +yy434: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'u') goto yy445; + goto yy433; +yy435: + yych = *(YYMARKER = ++YYCURSOR); + if (yych != 'e') goto yy433; + yych = *++YYCURSOR; + if (yych == 'f') goto yy438; +yy437: + YYCURSOR = YYMARKER; + goto yy433; +yy438: + yych = *++YYCURSOR; + if (yych != 'a') goto yy437; + yych = *++YYCURSOR; + if (yych != 'u') goto yy437; + yych = *++YYCURSOR; + if (yych != 'l') goto yy437; + yych = *++YYCURSOR; + if (yych != 't') goto yy437; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy437; + ++YYCURSOR; + { opts.input (InputAPI::DEFAULT); goto opt; } +yy445: + yych = *++YYCURSOR; + if (yych != 's') goto yy437; + yych = *++YYCURSOR; + if (yych != 't') goto yy437; + yych = *++YYCURSOR; + if (yych != 'o') goto yy437; + yych = *++YYCURSOR; + if (yych != 'm') goto yy437; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy437; + ++YYCURSOR; + { opts.input (InputAPI::CUSTOM); goto opt; } +} + + +opt_empty_class: + YYCURSOR = *++argv; + +{ + YYCTYPE yych; + yych = *YYCURSOR; + if (yych == 'e') goto yy456; + if (yych == 'm') goto yy457; + ++YYCURSOR; +yy455: + { + error ("bad argument to option --empty-class (expected: match-empty | match-none | error): %s\n", *argv); + return EXIT_FAIL; + } +yy456: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == 'r') goto yy477; + goto yy455; +yy457: + yych = *(YYMARKER = ++YYCURSOR); + if (yych != 'a') goto yy455; + yych = *++YYCURSOR; + if (yych == 't') goto yy460; +yy459: + YYCURSOR = YYMARKER; + goto yy455; +yy460: + yych = *++YYCURSOR; + if (yych != 'c') goto yy459; + yych = *++YYCURSOR; + if (yych != 'h') goto yy459; + yych = *++YYCURSOR; + if (yych != '-') goto yy459; + yych = *++YYCURSOR; + if (yych == 'e') goto yy464; + if (yych == 'n') goto yy465; + goto yy459; +yy464: + yych = *++YYCURSOR; + if (yych == 'm') goto yy471; + goto yy459; +yy465: + yych = *++YYCURSOR; + if (yych != 'o') goto yy459; + yych = *++YYCURSOR; + if (yych != 'n') goto yy459; + yych = *++YYCURSOR; + if (yych != 'e') goto yy459; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy459; + ++YYCURSOR; + { opts.empty_class (EMPTY_CLASS_MATCH_NONE); goto opt; } +yy471: + yych = *++YYCURSOR; + if (yych != 'p') goto yy459; + yych = *++YYCURSOR; + if (yych != 't') goto yy459; + yych = *++YYCURSOR; + if (yych != 'y') goto yy459; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy459; + ++YYCURSOR; + { opts.empty_class (EMPTY_CLASS_MATCH_EMPTY); goto opt; } +yy477: + yych = *++YYCURSOR; + if (yych != 'r') goto yy459; + yych = *++YYCURSOR; + if (yych != 'o') goto yy459; + yych = *++YYCURSOR; + if (yych != 'r') goto yy459; + yych = *++YYCURSOR; + if (yych >= 0x01) goto yy459; + ++YYCURSOR; + { opts.empty_class (EMPTY_CLASS_ERROR); goto opt; } +} + + +end: + if (!cFlag && opts.header_file) + { + error ("can only output a header file when using -c switch\n"); + return EXIT_FAIL; + } + if (DFlag && (bFlag || dFlag || sFlag || flag_skeleton)) + { + error ("cannot combine -D with -b, -d, -s or --skeleton switches\n"); + return EXIT_FAIL; + } + + return OK; + +#undef YYCTYPE +} + +} // namespace re2c diff --git a/re2c/src/conf/msg.cc b/re2c/src/conf/msg.cc new file mode 100644 index 00000000..2becf970 --- /dev/null +++ b/re2c/src/conf/msg.cc @@ -0,0 +1,149 @@ +#include +#include +#include + +#include "config.h" +#include "src/conf/msg.h" + +namespace re2c { + +void error (const char * fmt, ...) +{ + fprintf (stderr, "re2c: error: "); + + va_list args; + va_start (args, fmt); + fprintf (stderr, fmt, args); + va_end (args); +} + +void error_encoding () +{ + error ("only one of switches -e, -w, -x, -u and -8 must be set\n"); +} + +void usage () +{ + fprintf (stderr, + "usage: re2c [-bcdDefFghirsuvVwx18] [-o of] [-t th] file\n" + "\n" + "-? -h --help Display this info.\n" + "\n" + "-b --bit-vectors Implies -s. Use bit vectors as well in the attempt to\n" + " coax better code out of the compiler. Most useful for\n" + " specifications with more than a few keywords (e.g. for\n" + " most programming languages).\n" + "\n" + "-c --conditions Require start conditions.\n" + "\n" + "-d --debug-output Creates a parser that dumps information during\n" + " about the current position and in which state the\n" + " parser is.\n" + "\n" + "-D --emit-dot Emit a Graphviz dot view of the DFA graph\n" + "\n" + "-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 and -8\n" + "\n" + "-f --storable-state Generate a scanner that supports storable states.\n" + "\n" + "-F --flex-syntax Partial support for flex syntax.\n" + "\n" + "-g --computed-gotos Implies -b. Generate computed goto code (only useable\n" + " with gcc).\n" + "\n" + "-i --no-debug-info Do not generate '#line' info (usefull for versioning).\n" + "\n" + "-o of --output=of Specify the output file (of) instead of stdout\n" + "\n" + "-r --reusable Allow reuse of scanner definitions.\n" + "\n" + "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" + " need this assist to generate better code.\n" + "\n" + "-t th --type-header=th Generate a type header file (th) with type definitions.\n" + "\n" + "-u --unicode Generate a parser that supports UTF-32. The generated code\n" + " can deal with any valid Unicode character up to 0x10FFFF.\n" + " In this mode re2c assumes that input character size is 4 bytes.\n" + " This switch is incompatible with -e, -w, -x and -8. It implies -s.\n" + "\n" + "-v --version Show version information.\n" + "\n" + "-V --vernum Show version as one number.\n" + "\n" + "-w --wide-chars Generate a parser that supports UCS-2. The generated code can\n" + " deal with any valid Unicode character up to 0xFFFF. In this mode\n" + " re2c assumes that input character size is 2 bytes. This switch is\n" + " incompatible with -e, -x, -u and -8. It implies -s." + "\n" + "-x --utf-16 Generate a parser that supports UTF-16. The generated code can\n" + " deal with any valid Unicode character up to 0x10FFFF. In this mode\n" + " re2c assumes that input character size is 2 bytes. This switch is\n" + " incompatible with -e, -w, -u and -8. It implies -s." + "\n" + "-8 --utf-8 Generate a parser that supports UTF-8. The generated code can\n" + " deal with any valid Unicode character up to 0x10FFFF. In this mode\n" + " re2c assumes that input character size is 1 byte. This switch is\n" + " incompatible with -e, -w, -x and -u." + "\n" + "--no-generation-date Suppress date output in the generated output so that it\n" + " only shows the re2c version.\n" + "\n" + "--case-insensitive All strings are case insensitive, so all \"-expressions\n" + " are treated in the same way '-expressions are.\n" + "\n" + "--case-inverted Invert the meaning of single and double quoted strings.\n" + " With this switch single quotes are case sensitive and\n" + " double quotes are case insensitive.\n" + "\n" + "--encoding-policy ep Specify what re2c should do when given bad code unit.\n" + " ep can be one of the following: fail, substitute, ignore.\n" + "\n" + "--input i Specify re2c input API.\n" + " i can be one of the following: default, custom.\n" + "\n" + "--skeleton Instead of embedding re2c-generated code into C/C++ source,\n" + " generate a self-contained program for the same DFA.\n" + " Most useful for correctness and performance testing.\n" + "\n" + "--empty-class policy What to do if user inputs empty character class. policy can be\n" + " one of the following: 'match-empty' (match empty input, default),\n" + " 'match-none' (fail to match on any input), 'error' (compilation\n" + " error). Note that there are various ways to construct empty class,\n" + " e.g: [], [^\\x00-\\xFF], [\\x00-\\xFF]\\[\\x00-\\xFF].\n" + "\n" + "-1 --single-pass Deprecated and does nothing (single pass is by default now).\n" + ); +} + +void vernum () +{ + std::string vernum (PACKAGE_VERSION); + if (vernum[1] == '.') + { + vernum.insert(0, "0"); + } + vernum.erase(2, 1); + if (vernum[3] == '.') + { + vernum.insert(2, "0"); + } + vernum.erase(4, 1); + if (vernum.length() < 6 || vernum[5] < '0' || vernum[5] > '9') + { + vernum.insert(4, "0"); + } + vernum.resize(6); + + printf ("%s\n", vernum.c_str ()); +} + +void version () +{ + printf ("re2c %s\n", PACKAGE_VERSION); +} + +} // namespace re2c diff --git a/re2c/src/conf/msg.h b/re2c/src/conf/msg.h new file mode 100644 index 00000000..74c3398e --- /dev/null +++ b/re2c/src/conf/msg.h @@ -0,0 +1,14 @@ +#ifndef _RE2C_CONF_MSG_ +#define _RE2C_CONF_MSG_ + +namespace re2c { + +void error (const char * fmt, ...); +void error_encoding (); +void usage (); +void vernum (); +void version (); + +} // namespace re2c + +#endif // _RE2C_CONF_MSG_ diff --git a/re2c/src/conf/opt.cc b/re2c/src/conf/opt.cc new file mode 100644 index 00000000..561a51be --- /dev/null +++ b/re2c/src/conf/opt.cc @@ -0,0 +1,191 @@ +#include "src/conf/opt.h" + +namespace re2c +{ + +bool bFlag = false; +bool cFlag = false; +bool dFlag = false; +bool DFlag = false; +bool fFlag = false; +bool FFlag = false; +bool gFlag = false; +bool iFlag = false; +bool rFlag = false; +bool sFlag = false; +bool tFlag = false; +bool flag_skeleton = false; + +bool bNoGenerationDate = false; +bool bEmitYYCh = true; +bool bUseStateNext = false; +bool bUseYYFill = true; +bool bUseYYFillParam = true; +bool bUseYYFillCheck = true; +bool bUseYYFillNaked = false; +bool bUseYYSetConditionParam = true; +bool bUseYYGetConditionNaked = false; +bool bUseYYSetStateParam = true; +bool bUseYYSetStateNaked = false; +bool bUseYYGetStateNaked = false; + +std::string labelPrefix("yy"); +std::string condPrefix("yyc_"); +std::string condEnumPrefix("yyc"); +std::string condDivider("/* *********************************** */"); +std::string condDividerParam("@@"); +std::string condGoto("goto @@;"); +std::string condGotoParam("@@"); +std::string yychConversion(""); +std::string yyFillLength("@@"); +std::string yySetConditionParam("@@"); +std::string yySetStateParam("@@"); +std::string yySetupRule(""); +uint32_t cGotoThreshold = 9; + +uint32_t topIndent = 0; +std::string indString("\t"); +bool yybmHexTable = false; +bool bUseStateAbort = false; +bool bCaseInsensitive = false; +bool bCaseInverted = false; + +Enc encoding; +InputAPI input_api; + +empty_class_policy_t empty_class_policy = EMPTY_CLASS_MATCH_EMPTY; + +void Opt::bit_vectors () +{ + bFlag = true; + sFlag = true; +} + +void Opt::start_conditions () +{ + cFlag = true; +} + +void Opt::debug_output () +{ + dFlag = true; +} + +void Opt::emit_dot () +{ + DFlag = true; + iFlag = true; +} + +void Opt::storable_state () +{ + fFlag = true; +} + +void Opt::flex_syntax () +{ + FFlag = true; +} + +void Opt::computed_gotos () +{ + gFlag = true; + bFlag = true; + sFlag = true; +} + +void Opt::no_debug_info () +{ + iFlag = true; +} + +void Opt::reusable () +{ + rFlag = true; +} + +void Opt::nested_ifs () +{ + sFlag = true; +} + +void Opt::no_generation_date () +{ + bNoGenerationDate = true; +} + +void Opt::case_insensitive () +{ + bCaseInsensitive = true; +} + +void Opt::case_inverted () +{ + bCaseInverted = true; +} + +void Opt::skeleton () +{ + flag_skeleton = true; +} + +void Opt::source (const char * s) +{ + source_file = s; +} + +void Opt::output (const char * s) +{ + output_file = s; +} + +void Opt::type_header (const char * s) +{ + tFlag = true; + header_file = s; +} + +void Opt::encoding_policy (Enc::policy_t p) +{ + encoding.setPolicy (p); +} + +void Opt::input (InputAPI::type_t i) +{ + input_api.set (i); +} + +void Opt::empty_class (empty_class_policy_t p) +{ + empty_class_policy = p; +} + +bool Opt::ecb () +{ + return encoding.set (Enc::EBCDIC); +} + +bool Opt::unicode () +{ + sFlag = true; + return encoding.set(Enc::UTF32); +} + +bool Opt::wide_chars () +{ + sFlag = true; + return encoding.set(Enc::UCS2); +} + +bool Opt::utf_16 () +{ + sFlag = true; + return encoding.set(Enc::UTF16); +} + +bool Opt::utf_8 () +{ + return encoding.set(Enc::UTF8); +} + +} // namespace re2c diff --git a/re2c/src/conf/opt.h b/re2c/src/conf/opt.h new file mode 100644 index 00000000..6bc202f3 --- /dev/null +++ b/re2c/src/conf/opt.h @@ -0,0 +1,64 @@ +#ifndef _RE2C_CONF_OPT_ +#define _RE2C_CONF_OPT_ + +#include + +#include "src/codegen/input_api.h" +#include "src/globals.h" +#include "src/ir/regexp/encoding/enc.h" +#include "src/ir/regexp/empty_class_policy.h" + +namespace re2c +{ + +struct Opt +{ + const char * source_file; + const char * output_file; + const char * header_file; + + Opt () + : source_file (NULL) + , output_file ("") + , header_file (NULL) + {} + + void bit_vectors (); + void start_conditions (); + void debug_output (); + void emit_dot (); + void storable_state (); + void flex_syntax (); + void computed_gotos (); + void no_debug_info (); + void reusable (); + void nested_ifs (); + void no_generation_date (); + void case_insensitive (); + void case_inverted (); + void skeleton (); + void source (const char * s); + void output (const char * s); + void type_header (const char * s); + void encoding_policy (Enc::policy_t); + void input (InputAPI::type_t); + void empty_class (empty_class_policy_t); + bool ecb (); + bool unicode (); + bool wide_chars (); + bool utf_16 (); + bool utf_8 (); +}; + +enum parse_opts_t +{ + OK, + EXIT_OK, + EXIT_FAIL +}; + +parse_opts_t parse_opts (int argc, char ** argv, Opt & opts); + +} // namespace re2c + +#endif // _RE2C_CONF_OPT_ diff --git a/re2c/src/conf/parse_opts.re b/re2c/src/conf/parse_opts.re new file mode 100644 index 00000000..dadbe819 --- /dev/null +++ b/re2c/src/conf/parse_opts.re @@ -0,0 +1,195 @@ +#include + +#include "src/conf/msg.h" +#include "src/conf/opt.h" + +namespace re2c +{ + +parse_opts_t parse_opts (int argc, char ** argv, Opt & opts) +{ + if (argc == 1) + { + usage (); + return EXIT_FAIL; + } + +#define YYCTYPE char + YYCTYPE * YYCURSOR; + YYCTYPE * YYMARKER; + +/*!re2c + re2c:yyfill:enable = 0; + + end = "\x00"; + filename = [^\x00-] [^\x00]*; +*/ + +opt: + YYCURSOR = *++argv; + if (YYCURSOR == NULL) + { + goto end; + } +/*!re2c + * + { + error ("bad option: %s\n", *argv); + return EXIT_FAIL; + } + + "--" end { goto end; } + + "-" end { opts.source (""); goto opt; } + filename end { opts.source (*argv); goto opt; } + + "-" { goto opt_short; } + "--" { goto opt_long; } +*/ + +opt_short: +/*!re2c + * + { + error ("bad short option: %s\n", *argv); + return EXIT_FAIL; + } + end { goto opt; } + [?h] { usage (); return EXIT_OK; } + "v" { version (); return EXIT_OK; } + "V" { vernum (); return EXIT_OK; } + "b" { opts.bit_vectors (); goto opt_short; } + "c" { opts.start_conditions (); goto opt_short; } + "d" { opts.debug_output (); goto opt_short; } + "D" { opts.emit_dot (); goto opt_short; } + "f" { opts.storable_state (); goto opt_short; } + "F" { opts.flex_syntax (); goto opt_short; } + "g" { opts.computed_gotos (); goto opt_short; } + "i" { opts.no_debug_info (); goto opt_short; } + "r" { opts.reusable (); goto opt_short; } + "s" { opts.nested_ifs (); goto opt_short; } + "e" { if (!opts.ecb ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } + "u" { if (!opts.unicode ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } + "w" { if (!opts.wide_chars ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } + "x" { if (!opts.utf_16 ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } + "8" { if (!opts.utf_8 ()) { error_encoding (); return EXIT_FAIL; } goto opt_short; } + "o" end { YYCURSOR = *++argv; goto opt_output; } + "o" { *argv = YYCURSOR; goto opt_output; } + "t" end { YYCURSOR = *++argv; goto opt_header; } + "t" { *argv = YYCURSOR; goto opt_header; } + "1" { goto opt_short; } // deprecated +*/ + +opt_long: +/*!re2c + * + { + error ("bad long option: %s\n", *argv); + return EXIT_FAIL; + } + "help" end { usage (); return EXIT_OK; } + "version" end { version (); return EXIT_OK; } + "vernum" end { vernum (); return EXIT_OK; } + "bit-vectors" end { opts.bit_vectors (); goto opt; } + "start-conditions" end { opts.start_conditions (); goto opt; } + "debug-output" end { opts.debug_output (); goto opt; } + "emit-dot" end { opts.emit_dot (); goto opt; } + "storable-state" end { opts.storable_state (); goto opt; } + "flex-syntax" end { opts.flex_syntax (); goto opt; } + "computed-gotos" end { opts.computed_gotos (); goto opt; } + "no-debug-info" end { opts.no_debug_info (); goto opt; } + "reusable" end { opts.reusable (); goto opt; } + "nested-ifs" end { opts.nested_ifs (); goto opt; } + "no-generation-date" end { opts.no_generation_date (); goto opt; } + "case-insensitive" end { opts.case_insensitive (); goto opt; } + "case-inverted" end { opts.case_inverted (); goto opt; } + "skeleton" end { opts.skeleton (); goto opt; } + "ecb" end { if (!opts.ecb ()) { error_encoding (); return EXIT_FAIL; } goto opt; } + "unicode" end { if (!opts.unicode ()) { error_encoding (); return EXIT_FAIL; } goto opt; } + "wide-chars" end { if (!opts.wide_chars ()) { error_encoding (); return EXIT_FAIL; } goto opt; } + "utf-16" end { if (!opts.utf_16 ()) { error_encoding (); return EXIT_FAIL; } goto opt; } + "utf-8" end { if (!opts.utf_8 ()) { error_encoding (); return EXIT_FAIL; } goto opt; } + "output" end { goto opt_output; } + "type-header" end { goto opt_header; } + "encoding-policy" end { goto opt_encoding_policy; } + "input" end { goto opt_input; } + "empty-class" end { goto opt_empty_class; } + "single-pass" end { goto opt; } // deprecated +*/ + +opt_output: +/*!re2c + * + { + error ("bad argument to option -o, --output: %s\n", *argv); + return EXIT_FAIL; + } + filename end { opts.output (*argv); goto opt; } +*/ + +opt_header: +/*!re2c + * + { + error ("bad argument to option -t, --type-header: %s\n", *argv); + return EXIT_FAIL; + } + filename end { opts.type_header (*argv); goto opt; } +*/ + +opt_encoding_policy: + YYCURSOR = *++argv; +/*!re2c + * + { + error ("bad argument to option --encoding-policy (expected: ignore | substitute | fail): %s\n", *argv); + return EXIT_FAIL; + } + "ignore" end { opts.encoding_policy (Enc::POLICY_IGNORE); goto opt; } + "substitute" end { opts.encoding_policy (Enc::POLICY_SUBSTITUTE); goto opt; } + "fail" end { opts.encoding_policy (Enc::POLICY_FAIL); goto opt; } +*/ + +opt_input: + YYCURSOR = *++argv; +/*!re2c + * + { + error ("bad argument to option --input (expected: default | custom): %s\n", *argv); + return EXIT_FAIL; + } + "default" end { opts.input (InputAPI::DEFAULT); goto opt; } + "custom" end { opts.input (InputAPI::CUSTOM); goto opt; } +*/ + +opt_empty_class: + YYCURSOR = *++argv; +/*!re2c + * + { + error ("bad argument to option --empty-class (expected: match-empty | match-none | error): %s\n", *argv); + return EXIT_FAIL; + } + "match-empty" end { opts.empty_class (EMPTY_CLASS_MATCH_EMPTY); goto opt; } + "match-none" end { opts.empty_class (EMPTY_CLASS_MATCH_NONE); goto opt; } + "error" end { opts.empty_class (EMPTY_CLASS_ERROR); goto opt; } +*/ + +end: + if (!cFlag && opts.header_file) + { + error ("can only output a header file when using -c switch\n"); + return EXIT_FAIL; + } + if (DFlag && (bFlag || dFlag || sFlag || flag_skeleton)) + { + error ("cannot combine -D with -b, -d, -s or --skeleton switches\n"); + return EXIT_FAIL; + } + + return OK; + +#undef YYCTYPE +} + +} // namespace re2c diff --git a/re2c/src/main.cc b/re2c/src/main.cc index 37c44acc..39e48624 100644 --- a/re2c/src/main.cc +++ b/re2c/src/main.cc @@ -1,479 +1,56 @@ -#include -#include -#include -#include - #include "config.h" +#include "src/conf/msg.h" +#include "src/conf/opt.h" #include "src/globals.h" -#include "src/mbo_getopt.h" #include "src/parse/parser.h" namespace re2c { -bool bFlag = false; -bool cFlag = false; -bool dFlag = false; -bool DFlag = false; -bool fFlag = false; -bool FFlag = false; -bool gFlag = false; -bool iFlag = false; -bool rFlag = false; -bool sFlag = false; -bool tFlag = false; -bool flag_skeleton = false; - -bool bNoGenerationDate = false; bool bUsedYYBitmap = false; -bool bEmitYYCh = true; -bool bUseStateNext = false; -bool bUseYYFill = true; -bool bUseYYFillParam = true; -bool bUseYYFillCheck = true; -bool bUseYYFillNaked = false; -bool bUseYYSetConditionParam = true; -bool bUseYYGetConditionNaked = false; -bool bUseYYSetStateParam = true; -bool bUseYYSetStateNaked = false; -bool bUseYYGetStateNaked = false; - -std::string labelPrefix("yy"); -std::string condPrefix("yyc_"); -std::string condEnumPrefix("yyc"); -std::string condDivider("/* *********************************** */"); -std::string condDividerParam("@@"); -std::string condGoto("goto @@;"); -std::string condGotoParam("@@"); -std::string yychConversion(""); -std::string yyFillLength("@@"); -std::string yySetConditionParam("@@"); -std::string yySetStateParam("@@"); -std::string yySetupRule(""); -uint32_t cGotoThreshold = 9; - -uint32_t topIndent = 0; -std::string indString("\t"); -bool yybmHexTable = false; -bool bUseStateAbort = false; bool bWroteGetState = false; bool bWroteCondCheck = false; -bool bCaseInsensitive = false; -bool bCaseInverted = false; - -Enc encoding; -InputAPI input_api; - -empty_class_policy_t empty_class_policy = EMPTY_CLASS_MATCH_EMPTY; - uint32_t last_fill_index = 0; CodeNames mapCodeName; - free_list RegExp::vFreeList; -using namespace std; - -static char *opt_arg = NULL; -static int opt_ind = 1; - -static const mbo_opt_struct OPTIONS[] = -{ - mbo_opt_struct('?', 0, "help"), - mbo_opt_struct('b', 0, "bit-vectors"), - mbo_opt_struct('c', 0, "start-conditions"), - mbo_opt_struct('d', 0, "debug-output"), - mbo_opt_struct('D', 0, "emit-dot"), - mbo_opt_struct('e', 0, "ecb"), - mbo_opt_struct('f', 0, "storable-state"), - mbo_opt_struct('F', 0, "flex-syntax"), - mbo_opt_struct('g', 0, "computed-gotos"), - mbo_opt_struct('h', 0, "help"), - mbo_opt_struct('i', 0, "no-debug-info"), - mbo_opt_struct('o', 1, "output"), - mbo_opt_struct('r', 0, "reusable"), - mbo_opt_struct('s', 0, "nested-ifs"), - mbo_opt_struct('t', 1, "type-header"), - mbo_opt_struct('u', 0, "unicode"), - mbo_opt_struct('v', 0, "version"), - mbo_opt_struct('V', 0, "vernum"), - mbo_opt_struct('w', 0, "wide-chars"), - mbo_opt_struct('x', 0, "utf-16"), - mbo_opt_struct('8', 0, "utf-8"), - mbo_opt_struct('1', 0, "deprecated, single-pass"), - mbo_opt_struct(10, 0, "no-generation-date"), - mbo_opt_struct(11, 0, "case-insensitive"), - mbo_opt_struct(12, 0, "case-inverted"), - mbo_opt_struct(13, 1, "encoding-policy"), - mbo_opt_struct(14, 1, "input"), - mbo_opt_struct(15, 0, "skeleton"), - mbo_opt_struct(16, 1, "empty-class"), - mbo_opt_struct('-', 0, NULL) /* end of args */ -}; - -static void usage() -{ - std::cerr << "usage: re2c [-bcdDefFghirsuvVwx18] [-o of] [-t th] file\n" - "\n" - "-? -h --help Display this info.\n" - "\n" - "-b --bit-vectors Implies -s. Use bit vectors as well in the attempt to\n" - " coax better code out of the compiler. Most useful for\n" - " specifications with more than a few keywords (e.g. for\n" - " most programming languages).\n" - "\n" - "-c --conditions Require start conditions.\n" - "\n" - "-d --debug-output Creates a parser that dumps information during\n" - " about the current position and in which state the\n" - " parser is.\n" - "\n" - "-D --emit-dot Emit a Graphviz dot view of the DFA graph\n" - "\n" - "-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 and -8\n" - "\n" - "-f --storable-state Generate a scanner that supports storable states.\n" - "\n" - "-F --flex-syntax Partial support for flex syntax.\n" - "\n" - "-g --computed-gotos Implies -b. Generate computed goto code (only useable\n" - " with gcc).\n" - "\n" - "-i --no-debug-info Do not generate '#line' info (usefull for versioning).\n" - "\n" - "-o of --output=of Specify the output file (of) instead of stdout\n" - "\n" - "-r --reusable Allow reuse of scanner definitions.\n" - "\n" - "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" - " need this assist to generate better code.\n" - "\n" - "-t th --type-header=th Generate a type header file (th) with type definitions.\n" - "\n" - "-u --unicode Generate a parser that supports UTF-32. The generated code\n" - " can deal with any valid Unicode character up to 0x10FFFF.\n" - " In this mode re2c assumes that input character size is 4 bytes.\n" - " This switch is incompatible with -e, -w, -x and -8. It implies -s.\n" - "\n" - "-v --version Show version information.\n" - "\n" - "-V --vernum Show version as one number.\n" - "\n" - "-w --wide-chars Generate a parser that supports UCS-2. The generated code can\n" - " deal with any valid Unicode character up to 0xFFFF. In this mode\n" - " re2c assumes that input character size is 2 bytes. This switch is\n" - " incompatible with -e, -x, -u and -8. It implies -s." - "\n" - "-x --utf-16 Generate a parser that supports UTF-16. The generated code can\n" - " deal with any valid Unicode character up to 0x10FFFF. In this mode\n" - " re2c assumes that input character size is 2 bytes. This switch is\n" - " incompatible with -e, -w, -u and -8. It implies -s." - "\n" - "-8 --utf-8 Generate a parser that supports UTF-8. The generated code can\n" - " deal with any valid Unicode character up to 0x10FFFF. In this mode\n" - " re2c assumes that input character size is 1 byte. This switch is\n" - " incompatible with -e, -w, -x and -u." - "\n" - "--no-generation-date Suppress date output in the generated output so that it\n" - " only shows the re2c version.\n" - "\n" - "--case-insensitive All strings are case insensitive, so all \"-expressions\n" - " are treated in the same way '-expressions are.\n" - "\n" - "--case-inverted Invert the meaning of single and double quoted strings.\n" - " With this switch single quotes are case sensitive and\n" - " double quotes are case insensitive.\n" - "\n" - "--encoding-policy ep Specify what re2c should do when given bad code unit.\n" - " ep can be one of the following: fail, substitute, ignore.\n" - "\n" - "--input i Specify re2c input API.\n" - " i can be one of the following: default, custom.\n" - "\n" - "--skeleton Instead of embedding re2c-generated code into C/C++ source,\n" - " generate a self-contained program for the same DFA.\n" - " Most useful for correctness and performance testing.\n" - "\n" - "--empty-class policy What to do if user inputs empty character class. policy can be\n" - " one of the following: 'match-empty' (match empty input, default),\n" - " 'match-none' (fail to match on any input), 'error' (compilation\n" - " error). Note that there are various ways to construct empty class,\n" - " e.g: [], [^\\x00-\\xFF], [\\x00-\\xFF]\\[\\x00-\\xFF].\n" - "\n" - "-1 --single-pass Deprecated and does nothing (single pass is by default now).\n" - ; -} - } // end namespace re2c using namespace re2c; int main(int argc, char *argv[]) { - int c; - const char *sourceFileName = 0; - const char *outputFileName = ""; - const char *headerFileName = 0; - - if (argc == 1) - { - usage(); - return 2; - } - - while ((c = mbo_getopt(argc, argv, OPTIONS, &opt_arg, &opt_ind, 1)) != -1) - { - switch (c) - { - - case 'b': - bFlag = true; - sFlag = true; - break; - - case 'c': - cFlag = true; - break; - - case 'e': - if (!encoding.set(Enc::EBCDIC)) - { - std::cerr << "re2c: error: Only one of switches -e, -w, -x, -u and -8 must be set\n"; - return 2; - } - break; - - case 'd': - dFlag = true; - break; - - case 'D': - DFlag = true; - iFlag = true; - break; - - case 'f': - fFlag = true; - break; - - case 'F': - FFlag = true; - break; - - case 'g': - gFlag = true; - bFlag = true; - sFlag = true; - break; - - case 'i': - iFlag = true; - break; - - case 'o': - outputFileName = opt_arg; - break; - - case 'r': - rFlag = true; - break; - - case 's': - sFlag = true; - break; - - case 't': - tFlag = true; - headerFileName = opt_arg; - break; - - case '1': - break; - - case 'v': - cout << "re2c " << PACKAGE_VERSION << "\n"; - return 2; - - case 'V': { - string vernum(PACKAGE_VERSION); - - if (vernum[1] == '.') - { - vernum.insert(0, "0"); - } - vernum.erase(2, 1); - if (vernum[3] == '.') - { - vernum.insert(2, "0"); - } - vernum.erase(4, 1); - if (vernum.length() < 6 || vernum[5] < '0' || vernum[5] > '9') - { - vernum.insert(4, "0"); - } - vernum.resize(6); - cout << vernum << endl; - return 2; - } - - case 'w': - sFlag = true; - if (!encoding.set(Enc::UCS2)) - { - std::cerr << "re2c: error: Only one of switches -e, -w, -x, -u and -8 must be set\n"; - return 2; - } - break; - - case 'x': - sFlag = true; - if (!encoding.set(Enc::UTF16)) - { - std::cerr << "re2c: error: Only one of switches -e, -w, -x, -u and -8 must be set\n"; - return 2; - } - break; - - case 'u': - sFlag = true; - if (!encoding.set(Enc::UTF32)) - { - std::cerr << "re2c: error: Only one of switches -e, -w, -x, -u and -8 must be set\n"; - return 2; - } - break; - - case '8': - if (!encoding.set(Enc::UTF8)) - { - std::cerr << "re2c: error: Only one of switches -e, -w, -x, -u and -8 must be set\n"; - return 2; - } - break; - - default: - case 'h': - case '?': - usage(); - return 2; - - case 10: - bNoGenerationDate = true; - break; - - case 11: - bCaseInsensitive = true; - break; - - case 12: - bCaseInverted = true; - break; - - case 13: - if (strcmp(opt_arg, "fail") == 0) - encoding.setPolicy(Enc::POLICY_FAIL); - else if (strcmp(opt_arg, "substitute") == 0) - encoding.setPolicy(Enc::POLICY_SUBSTITUTE); - else if (strcmp(opt_arg, "ignore") == 0) - encoding.setPolicy(Enc::POLICY_IGNORE); - else - { - std::cerr << "re2c: error: Invalid encoding policy: \"" << opt_arg << "\"\n"; - return 1; - } - break; - - case 14: - if (strcmp(opt_arg, "default") == 0) - input_api.set (InputAPI::DEFAULT); - else if (strcmp(opt_arg, "custom") == 0) - input_api.set (InputAPI::CUSTOM); - else - { - std::cerr << "re2c: error: Invalid input API: \"" << opt_arg << "\"\n"; - return 1; - } - break; - - case 15: - flag_skeleton = true; - input_api.set (InputAPI::CUSTOM); - break; - - case 16: - if (strcmp(opt_arg, "match-empty") == 0) - empty_class_policy = EMPTY_CLASS_MATCH_EMPTY; - else if (strcmp(opt_arg, "match-none") == 0) - empty_class_policy = EMPTY_CLASS_MATCH_NONE; - else if (strcmp(opt_arg, "error") == 0) - empty_class_policy = EMPTY_CLASS_ERROR; - else - { - std::cerr << "re2c: error: Invalid empty class policy: \"" << opt_arg << "\"\n"; - return 1; - } - break; - } - } - - if (!cFlag && headerFileName) - { - std::cerr << "re2c: error: Can only output a header file when using -c switch\n"; - return 2; - } - - if (DFlag && (bFlag || dFlag || sFlag || flag_skeleton)) - { - std::cerr << "re2c: error: Cannot combine -D with -b, -d, -s or --skeleton switches\n"; - return 2; - } - - if (argc == opt_ind + 1) - { - sourceFileName = argv[opt_ind]; - if (strcmp (sourceFileName, "-") == 0) - { - if (fFlag) - { - std::cerr << "re2c: error: multiple /*!re2c stdin is not acceptable when -f is specified\n"; - return 1; - } - sourceFileName = ""; - outputFileName = ""; - } - } - else + Opt opts; + switch (parse_opts (argc, argv, opts)) { - std::cerr << "Unexpected argument: " << argv[argc-1] << "\n\n"; - usage(); - return 2; + case OK: break; + case EXIT_OK: return 0; + case EXIT_FAIL: return 1; } // set up the source stream - re2c::Input input (sourceFileName); + re2c::Input input (opts.source_file); if (!input.open ()) { - cerr << "re2c: error: cannot open " << sourceFileName << "\n"; + error ("cannot open source file: %s\n", opts.source_file); return 1; } // set up the output streams - re2c::Output output (outputFileName, headerFileName); + re2c::Output output (opts.output_file, opts.header_file); if (!output.source.open ()) { - cerr << "re2c: error: cannot open " << outputFileName << "\n"; + error ("cannot open output file: %s\n", opts.output_file); return 1; } if (tFlag && !output.header.open ()) { - cerr << "re2c: error: cannot open " << headerFileName << "\n"; + error ("cannot open header file: %s\n", opts.header_file); return 1; } if (flag_skeleton && !output.data.open ()) { - cerr << "re2c: error: cannot open " << output.data.file_name << "\n"; + error ("cannot open data file: %s\n", output.data.file_name.c_str ()); return 1; } diff --git a/re2c/src/mbo_getopt.cc b/re2c/src/mbo_getopt.cc deleted file mode 100644 index 51a3d76f..00000000 --- a/re2c/src/mbo_getopt.cc +++ /dev/null @@ -1,209 +0,0 @@ -/* - Author: Marcus Boerger -*/ - -#include -#include -#include -#include - -#include "src/mbo_getopt.h" - -#define OPTERRCOLON (1) -#define OPTERRNF (2) -#define OPTERRARG (3) - -namespace re2c -{ - -static int mbo_opt_error(int, char * const *argv, int oint, int optchr, int err, int show_err) -{ - if (show_err) - { - fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr + 1); - - switch (err) - { - - case OPTERRCOLON: - fprintf(stderr, ": in flags\n"); - break; - - case OPTERRNF: - fprintf(stderr, "option not found %c\n", argv[oint][optchr]); - break; - - case OPTERRARG: - fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]); - break; - - default: - fprintf(stderr, "unknown\n"); - break; - } - } - - return ('?'); -} - -int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **optarg, int *optind, int show_err) -{ - static int optchr = 0; - static int dash = 0; /* have already seen the - */ - int arg_start = 2; - - int opts_idx = -1; - - if (*optind >= argc) - { - return (EOF); - } - - if (!dash) - { - if ((argv[*optind][0] != '-')) - { - return (EOF); - } - else - { - if (!argv[*optind][1]) - { - /* - * use to specify stdin. Need to let pgm process this and - * the following args - */ - return (EOF); - } - } - } - - if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) - { - /* '--' indicates end of args if not followed by a known long option name */ - if (argv[*optind][2] == '\0') { - (*optind)++; - return(EOF); - } - - while (1) - { - opts_idx++; - - if (opts[opts_idx].opt_char == '-') - { - (*optind)++; - return (mbo_opt_error(argc, argv, *optind - 1, optchr, OPTERRARG, show_err)); - } - else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) - { - break; - } - } - - optchr = 0; - dash = 0; - arg_start = 2 + strlen(opts[opts_idx].opt_name); - } - else - { - if (!dash) - { - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - if (argv[*optind][optchr] == ':') - { - dash = 0; - (*optind)++; - return (mbo_opt_error(argc, argv, *optind - 1, optchr, OPTERRCOLON, show_err)); - } - arg_start = 1 + optchr; - } - - if (opts_idx < 0) - { - while (1) - { - opts_idx++; - - if (opts[opts_idx].opt_char == '-') - { - int errind = *optind; - int errchr = optchr; - - if (!argv[*optind][optchr + 1]) - { - dash = 0; - (*optind)++; - } - else - { - optchr++; - arg_start++; - } - - return (mbo_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); - } - else if (argv[*optind][optchr] == opts[opts_idx].opt_char) - { - break; - } - } - } - - if (opts[opts_idx].need_param) - { - /* Check for cases where the value of the argument - is in the form - or in the form - */ - dash = 0; - - if (!argv[*optind][arg_start]) - { - (*optind)++; - - if (*optind == argc) - { - return (mbo_opt_error(argc, argv, *optind - 1, optchr, OPTERRARG, show_err)); - } - - *optarg = argv[(*optind)++]; - } - else - { - *optarg = &argv[*optind][arg_start]; - (*optind)++; - } - - return opts[opts_idx].opt_char; - } - else - { - if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) - { - if (!argv[*optind][optchr + 1]) - { - dash = 0; - (*optind)++; - } - else - { - optchr++; - } - } - else - { - (*optind)++; - } - - return opts[opts_idx].opt_char; - } - - assert(0); - return (0); /* never reached */ -} - -} // end namespace re2c - diff --git a/re2c/src/mbo_getopt.h b/re2c/src/mbo_getopt.h deleted file mode 100644 index 7d1b23bc..00000000 --- a/re2c/src/mbo_getopt.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Author: Marcus Boerger -*/ - -/* Define structure for one recognized option (both single char and long name). - * If short_open is '-' this is the last option. - */ - -#ifndef _RE2C_MBO_GETOPT_ -#define _RE2C_MBO_GETOPT_ - -namespace re2c -{ - -struct mbo_opt_struct -{ - mbo_opt_struct(char _opt_char, int _need_param, const char * _opt_name) - : opt_char(_opt_char), need_param(_need_param), opt_name(_opt_name) - { - } - - const char opt_char; - const int need_param; - const char * opt_name; -}; - -int mbo_getopt(int argc, char* const *argv, const mbo_opt_struct *opts, char **optarg, int *optind, int show_err); - -} // end namespace re2c - -#endif // _RE2C_MBO_GETOPT_ -