aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-03-17 11:25:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-03-17 11:25:35 +0200
commit262d2b3711fefd0b82100d2aaeaf94f6d2e6ea77 (patch)
tree8887ba34cf3bd1b378683c855c9fadfc61f64063
parent120722059c8612fb13d7bf585a5593582a49220d (diff)
Make line numbers signify argument numbers in buildspec
-rw-r--r--build2/b.cxx11
-rw-r--r--build2/lexer3
-rw-r--r--build2/lexer.cxx18
-rw-r--r--build2/test/script/lexer.cxx3
4 files changed, 23 insertions, 12 deletions
diff --git a/build2/b.cxx b/build2/b.cxx
index 1f0464f..17a6645 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -203,16 +203,11 @@ main (int argc, char* argv[])
}
// Merge all the individual buildspec arguments into a single string.
- // Instead, we could also parse them individually (and merge the
- // result). The benefit of doing it this way is potentially better
- // diagnostics (i.e., we could have used <buildspec-1>, <buildspec-2>
- // to give the idea about which argument is invalid).
- //
- // Or we could separate arguments with newlines so that a line number
- // signifies the argument number.
+ // We wse newlines to separate arguments so that line numbers in
+ // diagnostics signify argument numbers. Clever, huh?
//
if (argn != 0)
- args += ' ';
+ args += '\n';
args += s;
diff --git a/build2/lexer b/build2/lexer
index aac1c40..76308e4 100644
--- a/build2/lexer
+++ b/build2/lexer
@@ -121,7 +121,8 @@ namespace build2
lexer_mode mode;
char sep_pair;
- bool sep_space; // Are whitespaces separators (see skip_spaces())?
+ bool sep_space; // Are whitespaces separators (see skip_spaces())?
+ bool sep_newline; // Is newline special (see skip_spaces())?
bool quotes; // Recognize quoted fragments.
const char* escapes; // Effective escape sequences to recognize.
diff --git a/build2/lexer.cxx b/build2/lexer.cxx
index 5989548..d3afdb0 100644
--- a/build2/lexer.cxx
+++ b/build2/lexer.cxx
@@ -26,6 +26,7 @@ namespace build2
const char* s1 (nullptr);
const char* s2 (nullptr);
bool s (true);
+ bool n (true);
bool q (true);
if (!esc)
@@ -70,8 +71,11 @@ namespace build2
//
// 2. Recognizes comma.
//
+ // 3. Treat newline as an ordinary space.
+ //
s1 = " $(){}[],\t\n";
s2 = " ";
+ n = false;
break;
}
case lexer_mode::single_quoted:
@@ -87,7 +91,7 @@ namespace build2
default: assert (false); // Unhandled custom mode.
}
- state_.push (state {m, ps, s, q, *esc, s1, s2});
+ state_.push (state {m, ps, s, n, q, *esc, s1, s2});
}
token lexer::
@@ -585,9 +589,11 @@ namespace build2
bool r (sep_);
sep_ = false;
+ const state& s (state_.top ());
+
// In some special modes we don't skip spaces.
//
- if (!state_.top ().sep_space)
+ if (!s.sep_space)
return r;
xchar c (peek ());
@@ -605,6 +611,14 @@ namespace build2
}
case '\n':
{
+ // In some modes we treat newlines as ordinary spaces.
+ //
+ if (!s.sep_newline)
+ {
+ r = true;
+ break;
+ }
+
// Skip empty lines.
//
if (start)
diff --git a/build2/test/script/lexer.cxx b/build2/test/script/lexer.cxx
index c7f9193..fab5cc2 100644
--- a/build2/test/script/lexer.cxx
+++ b/build2/test/script/lexer.cxx
@@ -22,6 +22,7 @@ namespace build2
const char* s1 (nullptr);
const char* s2 (nullptr);
bool s (true);
+ bool n (true);
bool q (true);
if (!esc)
@@ -135,7 +136,7 @@ namespace build2
}
assert (ps == '\0');
- state_.push (state {m, ps, s, q, *esc, s1, s2});
+ state_.push (state {m, ps, s, n, q, *esc, s1, s2});
}
token lexer::