aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/cc/lexer/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'unit-tests/cc/lexer/driver.cxx')
-rw-r--r--unit-tests/cc/lexer/driver.cxx37
1 files changed, 29 insertions, 8 deletions
diff --git a/unit-tests/cc/lexer/driver.cxx b/unit-tests/cc/lexer/driver.cxx
index db3f516..5803a88 100644
--- a/unit-tests/cc/lexer/driver.cxx
+++ b/unit-tests/cc/lexer/driver.cxx
@@ -16,38 +16,59 @@ namespace build2
{
namespace cc
{
- // Usage: argv[0] [<file>]
+ // Usage: argv[0] [-l] [<file>]
//
int
main (int argc, char* argv[])
{
+ bool loc (false);
+ const char* file (nullptr);
+
+ for (int i (1); i != argc; ++i)
+ {
+ string a (argv[i]);
+
+ if (a == "-l")
+ loc = true;
+ else
+ {
+ file = argv[i];
+ break;
+ }
+ }
+
try
{
istream* is;
- const char* in;
// Reading from file is several times faster.
//
ifdstream ifs;
- if (argc > 1)
+ if (file != nullptr)
{
- in = argv[1];
- ifs.open (in);
+ ifs.open (file);
is = &ifs;
}
else
{
- in = "stdin";
+ file = "stdin";
cin.exceptions (istream::failbit | istream::badbit);
is = &cin;
}
- lexer l (*is, path (in));
+ lexer l (*is, path (file));
// No use printing eos since we will either get it or loop forever.
//
for (token t; l.next (t) != token_type::eos; )
- cout << t << endl;
+ {
+ cout << t;
+
+ if (loc)
+ cout << ' ' << t.file << ':' << t.line << ':' << t.column;
+
+ cout << endl;
+ }
}
catch (const failed&)
{