summaryrefslogtreecommitdiff
path: root/client/docgen/parse.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/docgen/parse.cc')
-rw-r--r--client/docgen/parse.cc113
1 files changed, 92 insertions, 21 deletions
diff --git a/client/docgen/parse.cc b/client/docgen/parse.cc
index d1631c1..6303eae 100644
--- a/client/docgen/parse.cc
+++ b/client/docgen/parse.cc
@@ -29,16 +29,61 @@
#include <QFileInfo>
#include <QRegExp>
+#include <QStringList>
typedef enum {
none,
indesc,
+ indescex,
inatt,
inmeth,
+ inmethex,
inpar,
inret,
} state_t;
+static QString convert(QString in)
+{
+ QString out;
+ bool linkme = false;
+ QStringList tokens = in.split(QRegExp("\\s+"));
+ QStringList::iterator i = tokens.begin();
+ while(i != tokens.end()) {
+ if(linkme) {
+ QString link = *i;
+
+ if(i->right(1) == ".") link = link.left(link.length() - 1);
+
+ if(link.indexOf("(") != -1 && link.indexOf(")") != -1 ) {
+ // method link
+ out += "<a href=\"#"+link.left(link.indexOf("("))+"\">"+link+"</a>";
+ } else {
+ // tag link
+ out += "<a href=\""+link+".html\">"+link+"</a>";
+ }
+
+ if(i->right(1) == ".") out += ".";
+ out += " ";
+
+ i++;
+ linkme = false;
+ continue;
+ }
+
+ if(*i == "@see") {
+ linkme = true;
+ i++;
+ continue;
+ }
+
+ out += *i + " ";
+
+ i++;
+ }
+
+ return out;
+}
+
Doc parse(QString filename)
{
Doc doc;
@@ -68,13 +113,14 @@ Doc parse(QString filename)
if(line.contains("*/")) running = false;
if(running) {
- line.remove(QRegExp("^[ \t*]*"));
- // printf("line [%s]\n", line.toStdString().c_str());
+ line.remove(QRegExp("^[ \t]*[*][ \t]"));
if(state == indesc && line.left(1) == "@") state = none;
+ if(state == indescex && line.left(1) == "@") state = none;
if(state == inatt && line.left(1) == "@") state = none;
if(state == inpar && line.left(1) == "@") state = inmeth;
if(state == inret && line.left(1) == "@") state = inmeth;
+ if(state == inmethex && line.left(1) == "@") state = inmeth;
if(state == none && doc.title == "") {
doc.title = line;
@@ -83,6 +129,7 @@ Doc parse(QString filename)
if(state == none && line.left(4) == "@tag") {
doc.tag = line.right(line.length() - line.indexOf(" ") - 1);
+ doc.name = doc.tag;
continue;
}
@@ -105,12 +152,41 @@ Doc parse(QString filename)
state = indesc;
}
-
if(state == indesc) {
doc.description += line + "\n";
continue;
}
+ if((state == none || state == indesc || state == inmeth)
+ && line.left(8) == "@example") {
+
+ Example e;
+ e.name = line.right(line.length() - 8);
+
+ if(state == none || state == indesc) {
+ doc.examples.push_back(e);
+ state = indescex;
+ } else {
+ Method &m = doc.methods[doc.methods.size() - 1];
+ m.examples.push_back(e);
+ state = inmethex;
+ }
+
+ continue;
+ }
+
+ if(state == indescex || state == inmethex) {
+ Example *e;
+ if(state == indescex) {
+ e = &doc.examples[doc.examples.size() - 1];
+ } else {
+ Method &m = doc.methods[doc.methods.size() - 1];
+ e = &m.examples[m.examples.size() - 1];
+ }
+ e->code += line + "\n";
+ continue;
+ }
+
if(state == none && line.left(4) == "@att") {
Attribute att;
att.name = line.mid(5, line.indexOf(" ", 5) - 5);
@@ -176,23 +252,18 @@ Doc parse(QString filename)
if(line == "/***") running = true;
}
+ // Convert all @see to links
+ doc.description = convert(doc.description);
+ QVector<Attribute>::iterator i = doc.attributes.begin();
+ while(i != doc.attributes.end()) {
+ i->description = convert(i->description);
+ i++;
+ }
+ QVector<Method>::iterator j = doc.methods.begin();
+ while(j != doc.methods.end()) {
+ j->description = convert(j->description);
+ j++;
+ }
+
return doc;
}
-
-#ifdef TEST_PARSE
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
-
-TEST_BEGIN;
-
-// TODO: Put some testcode here (see test.h for usable macros).
-TEST_TRUE(false, "No tests yet!");
-
-TEST_END;
-
-#endif/*TEST_PARSE*/