aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/script')
-rw-r--r--libbuild2/script/lexer.test.cxx2
-rw-r--r--libbuild2/script/script.cxx68
-rw-r--r--libbuild2/script/script.hxx3
-rw-r--r--libbuild2/script/token.cxx6
-rw-r--r--libbuild2/script/token.hxx2
5 files changed, 76 insertions, 5 deletions
diff --git a/libbuild2/script/lexer.test.cxx b/libbuild2/script/lexer.test.cxx
index 85304ea..24fe335 100644
--- a/libbuild2/script/lexer.test.cxx
+++ b/libbuild2/script/lexer.test.cxx
@@ -45,7 +45,7 @@ namespace build2
{
// Print each token on a separate line without quoting operators.
//
- t.printer (cout, t, false);
+ t.printer (cout, t, print_mode::normal);
cout << endl;
}
}
diff --git a/libbuild2/script/script.cxx b/libbuild2/script/script.cxx
index b5456f9..db34084 100644
--- a/libbuild2/script/script.cxx
+++ b/libbuild2/script/script.cxx
@@ -33,6 +33,74 @@ namespace build2
return o << s;
}
+ void
+ dump (ostream& os, const string& ind, const lines& ls)
+ {
+ for (const line& l: ls)
+ {
+ os << ind;
+
+ // @@ Should be across lines?
+ //
+ // We will consider mixed quoting as a double quoting since the
+ // information is lost and we won't be able to restore the token
+ // original representation.
+ //
+// char qseq ('\0'); // Can be used as bool.
+
+ for (const replay_token& rt: l.tokens)
+ {
+ const token& t (rt.token);
+
+ // Left and right quotes (can be used as bool).
+ //
+ char lq ('\0');
+ char rq ('\0');
+
+ /*
+ if (t.qtype != quote_type::unquoted)
+ {
+ auto quote = [&t] ()
+ {
+ return t.qtype == quote_type::single ? '\'' : '"';
+ }
+
+ if (t.qcomp) // Complete quoting.
+ {
+ // If we are inside quoted token sequence then we do noting.
+ // Otherwise we just quote the token not starting a sequence.
+ //
+ if (!qseq)
+ {
+ lq = quote ();
+ rq = lq;
+ }
+ }
+ else // Partial quoting.
+ {
+ if (!qseq)
+ lq =
+
+ }
+ }
+ */
+ // @@ Add 2 spaces indentation for if block contents.
+
+ if (t.separated &&
+ t.type != token_type::newline &&
+ &rt != &l.tokens[0]) // Not first in the line.
+ os << ' ';
+
+ if (lq) os << lq;
+ t.printer (os, t, print_mode::raw);
+ if (rq) os << rq;
+
+// prev_qcomp = t.qcomp;
+// prev_qtype = t.qtype;
+ }
+ }
+ }
+
// Quote if empty or contains spaces or any of the special characters.
// Note that we use single quotes since double quotes still allow
// expansion.
diff --git a/libbuild2/script/script.hxx b/libbuild2/script/script.hxx
index 96c1343..f02583c 100644
--- a/libbuild2/script/script.hxx
+++ b/libbuild2/script/script.hxx
@@ -48,6 +48,9 @@ namespace build2
//
using lines = small_vector<line, 1>;
+ void
+ dump (ostream&, const string& ind, const lines&);
+
// Parse object model.
//
diff --git a/libbuild2/script/token.cxx b/libbuild2/script/token.cxx
index be0aa54..6c9de87 100644
--- a/libbuild2/script/token.cxx
+++ b/libbuild2/script/token.cxx
@@ -10,13 +10,13 @@ namespace build2
namespace script
{
void
- token_printer (ostream& os, const token& t, bool d)
+ token_printer (ostream& os, const token& t, print_mode m)
{
const string& v (t.value);
// Only quote non-name tokens for diagnostics.
//
- const char* q (d ? "'" : "");
+ const char* q (m == print_mode::diagnostics ? "'" : "");
switch (t.type)
{
@@ -39,7 +39,7 @@ namespace build2
case token_type::out_file_ovr: os << q << ">=" << v << q; break;
case token_type::out_file_app: os << q << ">+" << v << q; break;
- default: build2::token_printer (os, t, d);
+ default: build2::token_printer (os, t, m);
}
}
}
diff --git a/libbuild2/script/token.hxx b/libbuild2/script/token.hxx
index 0630e46..a2ccaee 100644
--- a/libbuild2/script/token.hxx
+++ b/libbuild2/script/token.hxx
@@ -49,7 +49,7 @@ namespace build2
};
void
- token_printer (ostream&, const token&, bool);
+ token_printer (ostream&, const token&, print_mode);
}
}