Commit b4a6e4a9 authored by Florian Brosch's avatar Florian Brosch

Add initial reading-support for <doc>

parent b753b88a
......@@ -125,7 +125,6 @@ div.site_body {
color: #a52a2a;
}
div.main_code_definition {
padding-right: 10px;
padding-left: 10px;
......@@ -140,6 +139,30 @@ div.main_code_definition {
margin: 10px;
}
div.main_notification_block {
padding-right: 10px;
padding-left: 10px;
padding-bottom: 5px;
padding-top: 5px;
border-color: #d08717;
background-color: #fbf2c3;
border-style: solid;
border-width: 1px;
margin: 10px;
}
span.main_block_headline {
background-image:url(tip.png);
background-repeat:no-repeat;
background-position:center right;
font-weight:bold;
display:block;
}
div.main_block_content {
margin-left:15px;
}
span.leaf_code_definition {
font: monospace;
......
......@@ -154,6 +154,30 @@ div.main_code_definition {
margin: 10px;
}
div.main_notification_block {
padding-right: 10px;
padding-left: 10px;
padding-bottom: 5px;
padding-top: 5px;
border-color: #d08717;
background-color: #fbf2c3;
border-style: solid;
border-width: 1px;
margin: 10px;
}
span.main_block_headline {
background-image:url(tip.png);
background-repeat:no-repeat;
background-position:center right;
font-weight:bold;
display:block;
}
div.main_block_content {
margin-left:15px;
}
span.leaf_code_definition {
font: monospace;
......
......@@ -32,6 +32,31 @@ ul.external_link {
background-image: url(warning.png);
}
div.main_notification_block {
padding-right: 10px;
padding-left: 10px;
padding-bottom: 5px;
padding-top: 5px;
border-color: #d08717;
background-color: #fbf2c3;
border-style: solid;
border-width: 1px;
margin: 10px;
}
span.main_block_headline {
background-image:url(tip.png);
background-repeat:no-repeat;
background-position:center right;
font-weight:bold;
display:block;
}
div.main_block_content {
margin-left:15px;
}
.main_sourcesample {
padding-right: 10px;
padding-left: 5px;
......
......@@ -29,11 +29,25 @@ using Gee;
* Creates an simpler, minimized, more abstract AST for valacs AST.
*/
public class Valadoc.Drivers.Driver : Object, Valadoc.Driver {
private Api.Tree? tree;
public void write_gir (Settings settings, ErrorReporter reporter) {
var gir_writer = new Vala.GIRWriter ();
// put .gir file in current directory unless -d has been explicitly specified
string gir_directory = ".";
if (settings.gir_directory != null) {
gir_directory = settings.gir_directory;
}
gir_writer.write_file ((Vala.CodeContext) tree.data, gir_directory, settings.gir_namespace, settings.gir_version, settings.pkg_name);
}
public Api.Tree? build (Settings settings, ErrorReporter reporter) {
TreeBuilder builder = new TreeBuilder ();
Api.Tree? tree = builder.build (settings, reporter);
tree = builder.build (settings, reporter);
if (reporter.errors > 0) {
tree = null;
return null;
}
......
......@@ -29,11 +29,25 @@ using Gee;
* Creates an simpler, minimized, more abstract AST for valacs AST.
*/
public class Valadoc.Drivers.Driver : Object, Valadoc.Driver {
private Api.Tree? tree;
public void write_gir (Settings settings, ErrorReporter reporter) {
var gir_writer = new Vala.GIRWriter ();
// put .gir file in current directory unless -d has been explicitly specified
string gir_directory = ".";
if (settings.gir_directory != null) {
gir_directory = settings.gir_directory;
}
gir_writer.write_file ((Vala.CodeContext) tree.data, gir_directory, settings.gir_namespace, settings.gir_version, settings.pkg_name);
}
public Api.Tree? build (Settings settings, ErrorReporter reporter) {
TreeBuilder builder = new TreeBuilder ();
Api.Tree? tree = builder.build (settings, reporter);
tree = builder.build (settings, reporter);
if (reporter.errors > 0) {
tree = null;
return null;
}
......
......@@ -29,11 +29,25 @@ using Gee;
* Creates an simpler, minimized, more abstract AST for valacs AST.
*/
public class Valadoc.Drivers.Driver : Object, Valadoc.Driver {
private Api.Tree? tree;
public void write_gir (Settings settings, ErrorReporter reporter) {
var gir_writer = new Vala.GIRWriter ();
// put .gir file in current directory unless -d has been explicitly specified
string gir_directory = ".";
if (settings.gir_directory != null) {
gir_directory = settings.gir_directory;
}
gir_writer.write_file ((Vala.CodeContext) tree.data, gir_directory, settings.gir_namespace, settings.gir_version, settings.pkg_name);
}
public Api.Tree? build (Settings settings, ErrorReporter reporter) {
TreeBuilder builder = new TreeBuilder ();
Api.Tree? tree = builder.build (settings, reporter);
tree = builder.build (settings, reporter);
if (reporter.errors > 0) {
tree = null;
return null;
}
......
......@@ -33,6 +33,7 @@ libdriver_la_VALASOURCES = \
initializerbuilder.vala \
symbolresolver.vala \
treebuilder.vala \
girwriter.vala \
driver.vala \
$(NULL)
......
......@@ -29,15 +29,29 @@ using Gee;
* Creates an simpler, minimized, more abstract AST for valacs AST.
*/
public class Valadoc.Drivers.Driver : Object, Valadoc.Driver {
private SymbolResolver resolver;
private Api.Tree? tree;
public void write_gir (Settings settings, ErrorReporter reporter) {
var gir_writer = new Drivers.GirWriter (resolver);
// put .gir file in current directory unless -d has been explicitly specified
string gir_directory = ".";
if (settings.gir_directory != null) {
gir_directory = settings.gir_directory;
}
gir_writer.write_file ((Vala.CodeContext) tree.data, gir_directory, settings.gir_namespace, settings.gir_version, settings.pkg_name);
}
public Api.Tree? build (Settings settings, ErrorReporter reporter) {
TreeBuilder builder = new TreeBuilder ();
Api.Tree? tree = builder.build (settings, reporter);
tree = builder.build (settings, reporter);
if (reporter.errors > 0) {
return null;
}
SymbolResolver resolver = new SymbolResolver (builder);
resolver = new SymbolResolver (builder);
tree.accept (resolver);
return tree;
......
/* girwriter.vala
*
* Copyright (C) 2011 Florian Brosch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Florian Brosch <flo.brosch@gmail.com>
*/
using Valadoc.Api;
/**
* Code visitor generating .gir file for the public interface.
*/
public class Valadoc.Drivers.GirWriter : Vala.GIRWriter {
private GtkdocRenderer renderer;
private SymbolResolver resolver;
public GirWriter (SymbolResolver resolver) {
this.renderer = new GtkdocRenderer ();
this.resolver = resolver;
}
private string? translate (Content.Comment? documentation) {
if (documentation == null) {
return null;
}
renderer.render_symbol (documentation);
return MarkupWriter.escape (renderer.content);
}
private string? translate_taglet (Content.Taglet? taglet) {
if (taglet == null) {
return null;
}
renderer.render_children (taglet);
return MarkupWriter.escape (renderer.content);
}
protected override string? get_interface_comment (Vala.Interface viface) {
Interface iface = resolver.resolve (viface) as Interface;
return translate (iface.documentation);
}
protected override string? get_struct_comment (Vala.Struct vst) {
Struct st = resolver.resolve (vst) as Struct;
return translate (st.documentation);
}
protected override string? get_enum_comment (Vala.Enum ven) {
Enum en = resolver.resolve (ven) as Enum;
return translate (en.documentation);
}
protected override string? get_class_comment (Vala.Class vc) {
Class c = resolver.resolve (vc) as Class;
return translate (c.documentation);
}
protected override string? get_error_code_comment (Vala.ErrorCode vecode) {
ErrorCode ecode = resolver.resolve (vecode) as ErrorCode;
return translate (ecode.documentation);
}
protected override string? get_enum_value_comment (Vala.EnumValue vev) {
Api.EnumValue ev = resolver.resolve (vev) as Api.EnumValue;
return translate (ev.documentation);
}
protected override string? get_constant_comment (Vala.Constant vc) {
Constant c = resolver.resolve (vc) as Constant;
return translate (c.documentation);
}
protected override string? get_error_domain_comment (Vala.ErrorDomain vedomain) {
ErrorDomain edomain = resolver.resolve (vedomain) as ErrorDomain;
return translate (edomain.documentation);
}
protected override string? get_field_comment (Vala.Field vf) {
Field f = resolver.resolve (vf) as Field;
return translate (f.documentation);
}
protected override string? get_delegate_comment (Vala.Delegate vcb) {
Delegate cb = resolver.resolve (vcb) as Delegate;
return translate (cb.documentation);
}
protected override string? get_method_comment (Vala.Method vm) {
Method m = resolver.resolve (vm) as Method;
return translate (m.documentation);
}
protected override string? get_property_comment (Vala.Property vprop) {
Property prop = resolver.resolve (vprop) as Property;
return translate (prop.documentation);
}
protected override string? get_delegate_return_comment (Vala.Delegate vcb) {
Delegate cb = resolver.resolve (vcb) as Delegate;
if (cb.documentation == null) {
return null;
}
Content.Comment? documentation = cb.documentation;
if (documentation == null) {
return null;
}
Gee.List<Content.Taglet> taglets = documentation.find_taglets (cb, typeof(Taglets.Return));
foreach (Content.Taglet taglet in taglets) {
return translate_taglet (taglet);
}
return null;
}
protected override string? get_signal_return_comment (Vala.Signal vsig) {
Api.Signal sig = resolver.resolve (vsig) as Api.Signal;
if (sig.documentation == null) {
return null;
}
Content.Comment? documentation = sig.documentation;
if (documentation == null) {
return null;
}
Gee.List<Content.Taglet> taglets = documentation.find_taglets (sig, typeof(Taglets.Return));
foreach (Content.Taglet taglet in taglets) {
return translate_taglet (taglet);
}
return null;
}
protected override string? get_method_return_comment (Vala.Method vm) {
Method m = resolver.resolve (vm) as Method;
if (m.documentation == null) {
return null;
}
Content.Comment? documentation = m.documentation;
if (documentation == null) {
return null;
}
Gee.List<Content.Taglet> taglets = documentation.find_taglets (m, typeof(Taglets.Return));
foreach (Content.Taglet taglet in taglets) {
return translate_taglet (taglet);
}
return null;
}
protected override string? get_signal_comment (Vala.Signal vsig) {
Api.Signal sig = resolver.resolve (vsig) as Api.Signal;
return translate (sig.documentation);
}
protected override string? get_parameter_comment (Vala.Parameter param) {
Api.Symbol symbol = resolver.resolve (((Vala.Symbol) param.parent_symbol));
if (symbol == null) {
return null;
}
Content.Comment? documentation = symbol.documentation;
if (documentation == null) {
return null;
}
Gee.List<Content.Taglet> taglets = documentation.find_taglets (symbol, typeof(Taglets.Param));
foreach (Content.Taglet _taglet in taglets) {
Taglets.Param taglet = (Taglets.Param) _taglet;
if (taglet.parameter_name == param.name) {
return translate_taglet (taglet);
}
}
return null;
}
}
......@@ -34,7 +34,7 @@ public class Valadoc.Drivers.SymbolResolver : Visitor {
this.glib_error = builder.get_glib_error ();
}
private Symbol? resolve (Vala.Symbol symbol) {
public Symbol? resolve (Vala.Symbol symbol) {
return symbol_map.get (symbol);
}
......
......@@ -1137,11 +1137,12 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
//
public Api.Tree? build (Settings settings, ErrorReporter reporter) {
this.tree = new Api.Tree (reporter, settings);
this.settings = settings;
this.reporter = reporter;
this.tree = new Api.Tree (reporter, settings);
var context = create_valac_tree (settings);
this.tree.data = context;
reporter.warnings_offset = context.report.get_warnings ();
reporter.errors_offset = context.report.get_errors ();
......
......@@ -35,6 +35,7 @@ public delegate Type Valadoc.DriverRegisterFunction (ModuleLoader module_loader)
public interface Valadoc.Driver : Object {
public abstract void write_gir (Settings settings, ErrorReporter reporter);
public abstract Api.Tree? build (Settings settings, ErrorReporter reporter);
}
......
......@@ -44,6 +44,11 @@ public class Valadoc.Api.Tree {
this.packages.add (package);
}
public void* data {
set;
get;
}
/**
* The root of the wiki tree.
*/
......@@ -196,9 +201,10 @@ public class Valadoc.Api.Tree {
return params;
}
public Tree (ErrorReporter reporter, Settings settings) {
public Tree (ErrorReporter reporter, Settings settings, void* data = null) {
this.settings = settings;
this.reporter = reporter;
this.data = data;
}
// copied from valacodecontext.vala
......
......@@ -21,8 +21,12 @@
*/
public class Valadoc.Devhelp.MarkupWriter : Valadoc.MarkupWriter {
public MarkupWriter (FileStream stream, bool xml_declaration = true) {
base (stream, xml_declaration);
public MarkupWriter (FileStream stream, bool xml_declaration = true) {
// avoid broken implicit copy
unowned FileStream _stream = stream;
base ((str) => { _stream.printf (str); }, xml_declaration);
}
protected override bool inline_element (string name) {
......
......@@ -418,7 +418,7 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
return item;
}
private LinkedList<Block>? parse_docbook_information_box_template (string tagname) {
private BlockContent? parse_docbook_information_box_template (string tagname, BlockContent container) {
if (!check_xml_open_tag (tagname)) {
this.report_unexpected_token (current, "<%s>".printf (tagname));
return null;
......@@ -427,60 +427,39 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
next ();
parse_docbook_spaces ();
LinkedList<Block> content = new LinkedList<Block> ();
var header_run = factory.create_run (Run.Style.BOLD);
header_run.content.add (factory.create_text ("Note:"));
Token tmp = null;
while (current.type != TokenType.XML_CLOSE && current.type != TokenType.EOF) {
if (current.type == TokenType.XML_OPEN && current.content == "para") {
var paragraphs = parse_docbook_para ();
if (header_run != null) {
content.add_all (paragraphs);
} else {
Paragraph fp = paragraphs.first ();
fp.content.insert (0, factory.create_text (" "));
fp.content.insert (0, header_run);
}
} else {
Token tmp_t = current;
Run? inline_run = parse_inline_content ();
tmp = current;
var ic = parse_inline_content ();
if (ic != null && ic.content.size > 0) {
Paragraph p = factory.create_paragraph ();
if (content != null) {
p.content.add (header_run);
p.content.add (factory.create_text (" "));
header_run = null;
}
p.content.add (inline_run);
content.add (p);
p.content.add (ic);
container.content.add (p);
}
if (tmp_t == current) {
break;
}
var bc = parse_block_content ();
if (bc != null && bc.size > 0) {
container.content.add_all (bc);
}
}
//parse_block_content ();
parse_docbook_spaces ();
if (!check_xml_close_tag (tagname)) {
this.report_unexpected_token (current, "</%s>".printf (tagname));
return content;
return container;
}
next ();
return content;
return container;
}
private LinkedList<Block>? parse_docbook_note () {
return parse_docbook_information_box_template ("note");
private Note? parse_docbook_note () {
return (Note?) parse_docbook_information_box_template ("note", factory.create_note ());
}
private LinkedList<Block>? parse_docbook_warning () {
return parse_docbook_information_box_template ("warning");
private Warning? parse_docbook_warning () {
return (Warning?) parse_docbook_information_box_template ("warning", factory.create_warning ());
}
private Content.List? parse_docbook_itemizedlist () {
......@@ -871,9 +850,9 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
} else if (current.type == TokenType.XML_OPEN && current.content == "example") {
this.append_block_content_not_null_all (content, parse_docbook_example ());
} else if (current.type == TokenType.XML_OPEN && current.content == "warning") {
this.append_block_content_not_null_all (content, parse_docbook_warning ());
this.append_block_content_not_null (content, parse_docbook_warning ());
} else if (current.type == TokenType.XML_OPEN && current.content == "note") {
this.append_block_content_not_null_all (content, parse_docbook_note ());
this.append_block_content_not_null (content, parse_docbook_note ());
} else if (current.type == TokenType.XML_OPEN && current.content == "refsect2") {
this.append_block_content_not_null_all (content, parse_docbook_refsect2 ());
} else if (current.type == TokenType.GTKDOC_PARAGRAPH) {
......
/* gtkdocmarkupwriter.vala
*
* Copyright (C) 2012 Florian Brosch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Florian Brosch <flo.brosch@gmail.com>
*/
public class Valadoc.GtkDocMarkupWriter : Valadoc.MarkupWriter {
private unowned StringBuilder builder;
public void reset () {
last_was_tag = true;
current_column = 0;
builder.erase ();
indent = -1;
}
public unowned string content {
get { return builder.str; }
}
public GtkDocMarkupWriter () {
StringBuilder builder = new StringBuilder ();
base ((str) => { builder.append (str); }, false);
this.builder = builder;
}
protected override bool inline_element (string name) {
return name != "para"
&& name != "programlisting"
&& name != "table"
&& name != "example"
&& name != "figure"
&& name != "tr"
&& name != "td"
&& name != "mediaobject"
&& name != "imageobject"
&& name != "textobject"
&& name != "listitem"
&& name != "orderedlist"
&& name != "itemizedlist"
&& name != "title";
}
protected override bool content_inline_element (string name) {
return name == "para"
|| name == "programlisting"
|| name == "emphasis"
|| name == "blockquote"
|| name == "ulink"
|| name == "listitem"
|| name == "title";
}
}
/* gtkdocrenderer.vala
*
* Copyright (C) 2011 Florian Brosch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Florian Brosch <flo.brosch@gmail.com>
*/
using GLib;
using Valadoc.Content;
public class Valadoc.GtkdocRenderer : ContentRenderer {
private GtkDocMarkupWriter writer = new GtkDocMarkupWriter ();
protected Settings settings;
private bool separated;
private string? get_cname (Api.Item item) {
if (item is Api.Method) {
return ((Api.Method)item).get_cname ();
} else if (item is Api.FormalParameter) {
return ((Api.FormalParameter)item).name;
} else if (item is Api.Constant) {
return ((Api.Constant)item).get_cname ();
} else if (item is Api.Property) {
return ((Api.Property)