summaryrefslogtreecommitdiff
path: root/cli/context.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-11-19 14:53:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-11-19 14:53:52 +0200
commit813e4744038ec3a1ca8095111074c1cb2a824d83 (patch)
treec4cda65a3280c09c50c0a3e227cdff5b43240247 /cli/context.cxx
parent3e34f8ac2ba3b719f13a8f9ef7422cbee8b02192 (diff)
Implement entire page usage generation
Diffstat (limited to 'cli/context.cxx')
-rw-r--r--cli/context.cxx85
1 files changed, 74 insertions, 11 deletions
diff --git a/cli/context.cxx b/cli/context.cxx
index a014824..d13f1e5 100644
--- a/cli/context.cxx
+++ b/cli/context.cxx
@@ -1403,6 +1403,69 @@ format (output_type ot, string const& s, bool para)
}
string context::
+substitute (const string& s, semantics::cli_unit& u)
+{
+ string r;
+
+ // Scan the string looking for variables ($var$).
+ //
+ size_t b (0), e (b);
+ for (size_t n (s.size ()); e != n; ++e)
+ {
+ if (s[e] == '$' && e + 1 != n)
+ {
+ if (s[e + 1] == '$') // Escape.
+ {
+ r.append (s, b, ++e - b); // Keep one, skip the other.
+ b = e + 1;
+ continue;
+ }
+
+ // Scan for as long as it is a C identifier.
+ //
+ size_t p (e + 1); // Position of the second '$'.
+ for (; p != n; ++p)
+ {
+ char c (s[p]);
+
+ if (!(c == '_' ||
+ ('a' <= c && c <= 'z') ||
+ ('A' <= c && c <= 'Z') ||
+ (p != e + 1 && '0' <= c && c <= '9')))
+ break;
+ }
+
+ // Note: check that the second '$' is not escaped.
+ //
+ if (p != n && s[p] == '$' && (p + 1 == n || s[p + 1] != '$'))
+ {
+ r.append (s, b, e - b);
+
+ // Lookup and substiute the variable.
+ //
+ ++e;
+ string v (s, e, p - e);
+
+ if (semantics::doc* d = u.lookup<semantics::doc> ("", "var: " + v))
+ r += d->front ();
+ else
+ {
+ cerr << "error: undefined variable '" << v << "' in '" << s << "'"
+ << endl;
+ throw generation_failed ();
+ }
+
+ e = p;
+ b = e + 1;
+ }
+ }
+ }
+
+ r.append (s, b, e - b); // Last chunk.
+ return r;
+}
+
+string context::
fq_name (semantics::nameable& n, bool cxx_name)
{
using namespace semantics;
@@ -1423,23 +1486,23 @@ fq_name (semantics::nameable& n, bool cxx_name)
return r;
}
-void context::
-cli_open ()
+string context::
+ns_open (const string& qn, bool last)
{
string::size_type b (0), e;
do
{
- e = cli.find ("::", b);
- string n (cli, b, e == string::npos ? e : e - b);
+ e = qn.find ("::", b);
+ string n (qn, b, e == string::npos ? e : e - b);
- if (!n.empty ())
+ if (!n.empty () && (last || e != string::npos))
os << "namespace " << n << "{";
b = e;
if (b == string::npos)
- break;
+ return n;
b += 2;
@@ -1447,22 +1510,22 @@ cli_open ()
}
void context::
-cli_close ()
+ns_close (const string& qn, bool last)
{
string::size_type b (0), e;
do
{
- e = cli.find ("::", b);
- string n (cli, b, e == string::npos ? e : e - b);
+ e = qn.find ("::", b);
+ string n (qn, b, e == string::npos ? e : e - b);
- if (!n.empty ())
+ if (!n.empty () && (last || e != string::npos))
os << "}";
b = e;
if (b == string::npos)
- break;
+ return;
b += 2;