src
msg.cc
Go to the documentation of this file.
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include <string>
4 
5 #include "config.h"
6 #include "src/conf/msg.h"
7 
8 namespace re2c {
9 
10 void error (const char * fmt, ...)
11 {
12  fprintf (stderr, "re2c: error: ");
13 
14  va_list args;
15  va_start (args, fmt);
16  vfprintf (stderr, fmt, args);
17  va_end (args);
18 
19  fprintf (stderr, "\n");
20 }
21 
23 {
24  error ("only one of switches -e, -w, -x, -u and -8 must be set");
25 }
26 
27 void error_arg (const char * option)
28 {
29  error ("expected argument to option %s", option);
30 }
31 
32 void warning_start (uint32_t line, bool error)
33 {
34  static const char * msg = error ? "error" : "warning";
35  fprintf (stderr, "re2c: %s: line %u: ", msg, line);
36 }
37 
38 void warning_end (const char * type, bool error)
39 {
40  if (type != NULL)
41  {
42  const char * prefix = error ? "error-" : "";
43  fprintf (stderr, " [-W%s%s]", prefix, type);
44  }
45  fprintf (stderr, "\n");
46 }
47 
48 void warning (const char * type, uint32_t line, bool error, const char * fmt, ...)
49 {
50  warning_start (line, error);
51 
52  va_list args;
53  va_start (args, fmt);
54  vfprintf (stderr, fmt, args);
55  va_end (args);
56 
57  warning_end (type, error);
58 }
59 
60 void usage ()
61 {
62  fprintf (stderr,
63  "usage: re2c [-bcdDefFghirsuvVwx18] [-o of] [-t th] file\n"
64  "\n"
65  "-? -h --help Display this info.\n"
66  "\n"
67  "-b --bit-vectors Implies -s. Use bit vectors as well in the attempt to\n"
68  " coax better code out of the compiler. Most useful for\n"
69  " specifications with more than a few keywords (e.g. for\n"
70  " most programming languages).\n"
71  "\n"
72  "-c --conditions Require start conditions.\n"
73  "\n"
74  "-d --debug-output Creates a parser that dumps information during\n"
75  " about the current position and in which state the\n"
76  " parser is.\n"
77  "\n"
78  "-D --emit-dot Emit a Graphviz dot view of the DFA graph\n"
79  "\n"
80  "-e --ecb Generate a parser that supports EBCDIC. The generated code\n"
81  " can deal with any character up to 0xFF. In this mode re2c\n"
82  " assumes that input character size is 1 byte. This switch is\n"
83  " incompatible with -w, -u, -x and -8\n"
84  "\n"
85  "-f --storable-state Generate a scanner that supports storable states.\n"
86  "\n"
87  "-F --flex-syntax Partial support for flex syntax.\n"
88  "\n"
89  "-g --computed-gotos Implies -b. Generate computed goto code (only useable\n"
90  " with gcc).\n"
91  "\n"
92  "-i --no-debug-info Do not generate '#line' info (useful for versioning).\n"
93  "\n"
94  "-o of --output=of Specify the output file (of) instead of stdout\n"
95  "\n"
96  "-r --reusable Allow reuse of scanner definitions.\n"
97  "\n"
98  "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n"
99  " need this assist to generate better code.\n"
100  "\n"
101  "-t th --type-header=th Generate a type header file (th) with type definitions.\n"
102  "\n"
103  "-u --unicode Generate a parser that supports UTF-32. The generated code\n"
104  " can deal with any valid Unicode character up to 0x10FFFF.\n"
105  " In this mode re2c assumes that input character size is 4 bytes.\n"
106  " This switch is incompatible with -e, -w, -x and -8. It implies -s.\n"
107  "\n"
108  "-v --version Show version information.\n"
109  "\n"
110  "-V --vernum Show version as one number.\n"
111  "\n"
112  "-w --wide-chars Generate a parser that supports UCS-2. The generated code can\n"
113  " deal with any valid Unicode character up to 0xFFFF. In this mode\n"
114  " re2c assumes that input character size is 2 bytes. This switch is\n"
115  " incompatible with -e, -x, -u and -8. It implies -s."
116  "\n"
117  "-x --utf-16 Generate a parser that supports UTF-16. The generated code can\n"
118  " deal with any valid Unicode character up to 0x10FFFF. In this mode\n"
119  " re2c assumes that input character size is 2 bytes. This switch is\n"
120  " incompatible with -e, -w, -u and -8. It implies -s."
121  "\n"
122  "-8 --utf-8 Generate a parser that supports UTF-8. The generated code can\n"
123  " deal with any valid Unicode character up to 0x10FFFF. In this mode\n"
124  " re2c assumes that input character size is 1 byte. This switch is\n"
125  " incompatible with -e, -w, -x and -u."
126  "\n"
127  "--no-generation-date Suppress date output in the generated file.\n"
128  "\n"
129  "--no-version Suppress version output in the generated file.\n"
130  "\n"
131  "--case-insensitive All strings are case insensitive, so all \"-expressions\n"
132  " are treated in the same way '-expressions are.\n"
133  "\n"
134  "--case-inverted Invert the meaning of single and double quoted strings.\n"
135  " With this switch single quotes are case sensitive and\n"
136  " double quotes are case insensitive.\n"
137  "\n"
138  "--encoding-policy ep Specify what re2c should do when given bad code unit.\n"
139  " ep can be one of the following: fail, substitute, ignore.\n"
140  "\n"
141  "--input i Specify re2c input API.\n"
142  " i can be one of the following: default, custom.\n"
143  "\n"
144  "--skeleton Instead of embedding re2c-generated code into C/C++ source,\n"
145  " generate a self-contained program for the same DFA.\n"
146  " Most useful for correctness and performance testing.\n"
147  "\n"
148  "--empty-class policy What to do if user inputs empty character class. policy can be\n"
149  " one of the following: 'match-empty' (match empty input, default),\n"
150  " 'match-none' (fail to match on any input), 'error' (compilation\n"
151  " error). Note that there are various ways to construct empty class,\n"
152  " e.g: [], [^\\x00-\\xFF], [\\x00-\\xFF]\\[\\x00-\\xFF].\n"
153  "\n"
154  "--dfa-minimization <table | moore>\n"
155  " Internal algorithm used by re2c to minimize DFA (defaults to\n"
156  " 'moore'). Both table filling and Moore's algorithms should\n"
157  " produce identical DFA (up to states relabelling). Table filling\n"
158  " algorithm is much simpler and slower; it serves as a reference\n"
159  " implementation.\n"
160  "\n"
161  "-1 --single-pass Deprecated and does nothing (single pass is by default now).\n"
162  "\n"
163  "-W Turn on all warnings.\n"
164  "\n"
165  "-Werror Turn warnings into errors. Note that this option along doesn't\n"
166  " turn on any warnings, it only affects those warnings that have\n"
167  " been turned on so far or will be turned on later.\n"
168  "\n"
169  "-W<warning> Turn on individual warning.\n"
170  "\n"
171  "-Wno-<warning> Turn off individual warning.\n"
172  "\n"
173  "-Werror-<warning> Turn on individual warning and treat it as error (this implies\n"
174  " '-W<warning>').\n"
175  "\n"
176  "-Wno-error-<warning> Don't treat this particular warning as error. This doesn't turn\n"
177  " off the warning itself.\n"
178  "\n"
179  "Warnings:\n"
180  "\n"
181  "-Wcondition-order Warn if the generated program makes implicit assumptions about\n"
182  " condition numbering. One should use either '-t, --type-header'\n"
183  " option or '/*!types:re2c*/' directive to generate mapping of\n"
184  " condition names to numbers and use autogenerated condition names.\n"
185  "\n"
186  "-Wempty-character-class Warn if regular expression contains empty character class. From\n"
187  " the rational point of view trying to match empty character class\n"
188  " makes no sense: it should always fail. However, for backwards\n"
189  " compatibility reasons re2c allows empty character class and treats\n"
190  " it as empty string. Use '--empty-class' option to change default\n"
191  " behaviour.\n"
192  "\n"
193  "-Wmatch-empty-string Warn if regular expression in a rule is nullable (matches empty\n"
194  " string). If DFA runs in a loop and empty match is unintentional\n"
195  " (input position in not advanced manually), lexer may get stuck\n"
196  " in eternal loop.\n"
197  "\n"
198  "-Wswapped-range Warn if range lower bound is greater that upper bound. Default\n"
199  " re2c behaviour is to silently swap range bounds.\n"
200  "\n"
201  "-Wundefined-control-flow\n"
202  " Warn if some input strings cause undefined control flow in lexer\n"
203  " (the faulty patterns are reported). This is the most dangerous\n"
204  " and common mistake. It can be easily fixed by adding default rule\n"
205  " '*' (this rule has the lowest priority, matches any code unit\n"
206  " and consumes exactly one code unit).\n"
207  "\n"
208  "-Wuseless-escape Warn if a symbol is escaped when it shouldn't be. By default re2c\n"
209  " silently ignores escape, but this may as well indicate a typo\n"
210  " or an error in escape sequence.\n"
211  "\n"
212  );
213 }
214 
215 void vernum ()
216 {
217  std::string vernum (PACKAGE_VERSION);
218  if (vernum[1] == '.')
219  {
220  vernum.insert(0, "0");
221  }
222  vernum.erase(2, 1);
223  if (vernum[3] == '.')
224  {
225  vernum.insert(2, "0");
226  }
227  vernum.erase(4, 1);
228  if (vernum.length() < 6 || vernum[5] < '0' || vernum[5] > '9')
229  {
230  vernum.insert(4, "0");
231  }
232  vernum.resize(6, '0');
233 
234  printf ("%s\n", vernum.c_str ());
235 }
236 
237 void version ()
238 {
239  printf ("re2c %s\n", PACKAGE_VERSION);
240 }
241 
242 std::string incond (const std::string & cond)
243 {
244  std::string s;
245  if (!cond.empty ())
246  {
247  s += "in condition '";
248  s += cond;
249  s += "' ";
250  }
251  return s;
252 }
253 
254 } // namespace re2c
void usage()
Definition: msg.cc:60
void error(const char *fmt,...)
Definition: msg.cc:10
void warning_start(uint32_t line, bool error)
Definition: msg.cc:32
void version()
Definition: msg.cc:237
void error_encoding()
Definition: msg.cc:22
void error_arg(const char *option)
Definition: msg.cc:27
void warning(const char *type, uint32_t line, bool error, const char *fmt,...)
Definition: msg.cc:48
void warning_end(const char *type, bool error)
Definition: msg.cc:38
void vernum()
Definition: msg.cc:215
Definition: bitmap.cc:10
std::string incond(const std::string &cond)
Definition: msg.cc:242