From f5c7b962c4d3512f32df8c3bbd3370f846239b02 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 23 Nov 2021 11:20:03 +0200 Subject: WIP: complete --- libbuild2/make-parser.test.cxx | 90 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 libbuild2/make-parser.test.cxx (limited to 'libbuild2/make-parser.test.cxx') diff --git a/libbuild2/make-parser.test.cxx b/libbuild2/make-parser.test.cxx new file mode 100644 index 0000000..189407a --- /dev/null +++ b/libbuild2/make-parser.test.cxx @@ -0,0 +1,90 @@ +// file : libbuild2/make-parser.test.cxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include + +#include +#include + +#undef NDEBUG +#include + +using namespace std; + +namespace build2 +{ + int + main (int, char* argv[]) + { + bool strict (false); + + // Fake build system driver, default verbosity. + // + init_diag (1); + init (nullptr, argv[0]); + + path_name in (""); + + try + { + cin.exceptions (istream::badbit); + + using make_state = make_parser; + using make_type = make_parser::type; + + make_parser make; + + location ll (in, 1); + for (string l; !eof (getline (cin, l)); ++ll.line) + { + if (make.state == make_state::end) + { + cout << endl; + make.state = make_state::begin; + } + + // Skip leading blank lines to reduce output noise. + // + if (make.state == make_state::begin && l.empty ()) + continue; + + size_t pos (0); + do + { + pair r (make.next (l, pos, ll, strict)); + + cout << (r.first == make_type::target ? 'T' : 'P'); + + if (!r.second.empty ()) + cout << ' ' << r.second; + + cout << endl; + } + while (pos != l.size ()); + } + + if (make.state != make_state::end && make.state != make_state::begin) + fail (ll) << "incomplete make dependency declaration"; + } + catch (const io_error& e) + { + cerr << "unable to read stdin: " << e << endl; + return 1; + } + catch (const failed&) + { + return 1; + } + + return 0; + } +} + +int +main (int argc, char* argv[]) +{ + return build2::main (argc, argv); +} -- cgit v1.1