18void usage(std::ostream &out,
const char *name)
20 out <<
"Performs grammatical analysis of the input.\n"
21 <<
"USAGE:\n\t" << name <<
" <FILE>"
22 <<
"\n\t" << name <<
" -"
26int main(
int argc,
const char **argv)
29#define ADD(TYPE, VAR, INIT, SHORT, LONG, DESCR, CALLBACK)\
32 AP.add<TYPE>(SHORT, LONG, DESCR, CALLBACK);\
36 "prints this help message",
38 ADD(
bool, color,
false,
41 [&](
bool) { color =
true; });
44 "dump the abstract syntax tree",
45 [&](
bool) { ast =
true; });
50 usage(std::cout, argv[0]);
51 std::cout <<
"WHERE\n" << AP;
52 std::exit(EXIT_SUCCESS);
55 if (AP.
args().size() != 1) {
56 usage(std::cerr, argv[0]);
57 std::cerr <<
"WHERE\n" << AP;
58 std::exit(EXIT_FAILURE);
61 const char *filename = AP.
args()[0];
63 if (
streq(filename,
"-")) {
68 in =
new std::ifstream(filename, std::ios_base::in);
73 std::cerr <<
"Failed to open stdin: ";
75 std::cerr <<
"Failed to open the file '" << filename <<
"': ";
76 std::cerr << strerror(errno) << std::endl;
81 Lexer lexer(diag, pool, filename, *in);
85 while (parser.
token()) {
86 auto cmd = parser.
parse();
91 std::cout << std::endl;
98 std::exit(diag.
num_errors() ? EXIT_FAILURE : EXIT_SUCCESS);
bool show_help
whether to show a help message
A parser for command line arguments.
void parse_args(int argc, const char **argv)
Parses the arguments from argv.
const std::vector< const char * > & args() const
Returns all positional arguments.
bool streq(const char *first, const char *second)
void usage(std::ostream &out, const char *name)
#define ADD(TYPE, VAR, INIT, SHORT, LONG, DESCR, CALLBACK)
unsigned num_errors() const
Returns the number of errors emitted since the last call to clear().
Pretty-prints the AST in SQL.
std::unique_ptr< Command > parse()