aboutsummaryrefslogtreecommitdiff
path: root/build/b.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-03-30 14:16:54 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-03-30 14:16:54 +0200
commitb1715878d50aa8a3c3e2404f3ded120329994aba (patch)
tree85c9feb4556f7555f0acc0e2d012ee52b73c1b34 /build/b.cxx
parent70256514a09e4692c6839f5c2b21b7ec9c1055bd (diff)
Initial support for command line variables
Diffstat (limited to 'build/b.cxx')
-rw-r--r--build/b.cxx44
1 files changed, 40 insertions, 4 deletions
diff --git a/build/b.cxx b/build/b.cxx
index c676f8a..bd02052 100644
--- a/build/b.cxx
+++ b/build/b.cxx
@@ -12,7 +12,6 @@
#include <sstream>
#include <cassert>
-#include <iostream> //@@ TMP, for dump()
#include <typeinfo>
#include <system_error>
@@ -32,6 +31,9 @@
#include <build/context>
#include <build/utility>
#include <build/filesystem>
+
+#include <build/token>
+#include <build/lexer>
#include <build/parser>
using namespace std;
@@ -223,6 +225,40 @@ main (int argc, char* argv[])
//
reset ();
+ // Parse command line variables. They should come before the
+ // buildspec.
+ //
+ int argi (1);
+ for (; argi != argc; argi++)
+ {
+ const char* s (argv[argi]);
+
+ istringstream is (s);
+ is.exceptions (istringstream::failbit | istringstream::badbit);
+ lexer l (is, "<cmdline>");
+ token t (l.next ());
+
+ if (t.type () == token_type::eos)
+ continue; // Whitespace-only argument.
+
+ // Unless this is a name followed by = or +=, assume it is
+ // a start of the buildspec.
+ //
+ if (t.type () != token_type::name)
+ break;
+
+ token_type tt (l.next ().type ());
+
+ if (tt != token_type::equal && tt != token_type::plus_equal)
+ break;
+
+ parser p;
+ t = p.parse_variable (l, *root_scope, t.name (), tt);
+
+ if (t.type () != token_type::eos)
+ fail << "unexpected " << t << " in variable " << s;
+ }
+
// Parse the buildspec.
//
buildspec bspec;
@@ -235,10 +271,10 @@ main (int argc, char* argv[])
// which argument is invalid).
//
string s;
- for (int i (1); i != argc;)
+ for (; argi != argc;)
{
- s += argv[i];
- if (++i != argc)
+ s += argv[argi];
+ if (++argi != argc)
s += ' ';
}