43int main (
int argc,
char *argv[])
45 QCoreApplication app (argc, argv);
47 bool generate_dot =
false;
48 bool generate_report =
false;
49 bool no_lines =
false;
50 bool debug_info =
true;
51 bool use_pragma_once =
false;
53 bool qt_copyright =
false;
54 bool no_copyright_header =
false;
55 bool warnings_are_errors =
false;
58 const QStringList args = app.arguments().mid(1);
59 for (
const QString &arg : args) {
60 if (arg ==
"-h"_L1 || arg ==
"--help"_L1)
63 else if (arg ==
"-v"_L1 || arg ==
"--verbose"_L1)
64 generate_report =
true;
66 else if (arg ==
"--dot"_L1)
69 else if (arg ==
"--no-lines"_L1)
72 else if (arg ==
"--no-debug"_L1)
75 else if (arg ==
"--use-pragma-once"_L1)
76 use_pragma_once =
true;
78 else if (
constexpr auto qtsec =
"--qt-security="_L1; arg.startsWith(qtsec))
80 auto sh = CppGenerator::SecurityHeader::parse(QStringView{arg}.slice(qtsec.size()));
82 qerr() <<
"*** Warning. Could not parse `" << arg <<
"'" << Qt::endl;
84 security = std::move(sh);
87 else if (arg ==
"--qt"_L1)
90 else if (arg ==
"--no-copyright-header"_L1)
91 no_copyright_header =
true;
93 else if (arg ==
"--exit-on-warn"_L1)
94 warnings_are_errors =
true;
96 else if (file_name.isEmpty ())
100 qerr() <<
"*** Warning. Ignore argument `" << arg <<
"'" << Qt::endl;
103 if (file_name.isEmpty ())
110 Recognizer p (&grammar, no_lines);
112 if (! p.parse (file_name))
115 if (grammar
.rules.empty())
117 qerr() <<
"*** Fatal. No rules!" << Qt::endl;
121 else if (grammar
.start == grammar.names.end ())
123 qerr() <<
"*** Fatal. No start symbol!" << Qt::endl;
141 }
else if (!no_copyright_header && !grammar.inputCopyright.isEmpty()) {
143 gen.setCopyrightText (grammar.inputCopyright);
154 else if (generate_report)
163QString Recognizer::expand (
const QString &text)
const
167 if (_M_grammar
->start != _M_grammar->names.end ())
169 code = code.replace (
"$start_id"_L1, QString::number (std::distance (_M_grammar->names.begin (), _M_grammar->start)));
170 code = code.replace (
"$start"_L1, *_M_grammar
->start);
173 code = code.replace (
"$header"_L1, _M_grammar->table_name.toLower () +
"_p.h"_L1);
175 code = code.replace (
"$table"_L1, _M_grammar->table_name);
176 code = code.replace (
"$parser"_L1, _M_grammar->table_name);
178 if (_M_current_rule != _M_grammar
->rules.end ())
180 code = code.replace (
"$rule_number"_L1, QString::number (std::distance (_M_grammar->rules.begin (), _M_current_rule)));
181 code = code.replace (
"$rule"_L1, *_M_current_rule->lhs);