From: Didier 'Ptitjes Date: Wed, 16 Sep 2009 23:16:11 +0000 (+0200) Subject: Initial import of the rewrited parser X-Git-Tag: 0.37.1~3^2~574 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea055f2d1c68da97f718324233724526d320b652;p=thirdparty%2Fvala.git Initial import of the rewrited parser --- diff --git a/configure.in b/configure.in index da5130c4d..b782cdfc7 100644 --- a/configure.in +++ b/configure.in @@ -14,6 +14,7 @@ AC_PATH_PROG(VALAC, valac, valac) AC_SUBST(VALAC) +AC_SUBST(VALAFLAGS) AC_ARG_ENABLE(valadocorg, AS_HELP_STRING([--enable-valadocorg], []), enable_valadocorg=$enableval, enable_valadocorg=no) AM_CONDITIONAL(ENABLE_VALADOCORG, test x$enable_valadocorg = xyes) @@ -64,7 +65,6 @@ AC_CONFIG_FILES([Makefile src/doclets/htmlhelpers/Makefile src/doclets/htmlhelpers/deps/Makefile src/doclets/htmlhelpers/doclet/Makefile - src/doclets/htmlhelpers/taglets/Makefile src/doclets/htm/Makefile src/doclets/htm/doclet/Makefile src/doclets/valadoc.org/Makefile diff --git a/src/doclets/Makefile.am b/src/doclets/Makefile.am index d4a0a9b50..8f261c9a0 100644 --- a/src/doclets/Makefile.am +++ b/src/doclets/Makefile.am @@ -7,7 +7,6 @@ SUBDIRS = \ htmlhelpers \ htm \ devhelp \ - valadoc.org \ $(NULL) diff --git a/src/doclets/devhelp/doclet/Makefile.am b/src/doclets/devhelp/doclet/Makefile.am index ab736be3e..4472c5d0f 100644 --- a/src/doclets/devhelp/doclet/Makefile.am +++ b/src/doclets/devhelp/doclet/Makefile.am @@ -58,7 +58,7 @@ MAINTAINERCLEANFILES = \ install-data-hook: - cd $(libdir)/valadoc/plugins/devhelp/ && if test -d taglets; then unlink taglets; fi && ln -s ../htmlhelpers/taglets && if test -d deps; then unlink deps; fi && ln -s ../htmlhelpers/deps + cd $(libdir)/valadoc/plugins/devhelp/ && if test -d deps; then unlink deps; fi && ln -s ../htmlhelpers/deps diff --git a/src/doclets/htm/doclet/Makefile.am b/src/doclets/htm/doclet/Makefile.am index 6f9c2bd0c..889d8fc14 100644 --- a/src/doclets/htm/doclet/Makefile.am +++ b/src/doclets/htm/doclet/Makefile.am @@ -59,5 +59,5 @@ MAINTAINERCLEANFILES = \ install-data-hook: - cd $(libdir)/valadoc/plugins/html/ && if test -d taglets; then unlink taglets; fi && ln -s ../htmlhelpers/taglets && if test -d deps; then unlink deps; fi && ln -s ../htmlhelpers/deps + cd $(libdir)/valadoc/plugins/html/ && if test -d deps; then unlink deps; fi && ln -s ../htmlhelpers/deps diff --git a/src/doclets/htmlhelpers/Makefile.am b/src/doclets/htmlhelpers/Makefile.am index acf64ba87..fb343527c 100644 --- a/src/doclets/htmlhelpers/Makefile.am +++ b/src/doclets/htmlhelpers/Makefile.am @@ -3,6 +3,5 @@ NULL = SUBDIRS = \ doclet \ - taglets \ deps \ $(NULL) diff --git a/src/doclets/htmlhelpers/doclet/Makefile.am b/src/doclets/htmlhelpers/doclet/Makefile.am index d04758d09..b2fdb33cf 100644 --- a/src/doclets/htmlhelpers/doclet/Makefile.am +++ b/src/doclets/htmlhelpers/doclet/Makefile.am @@ -25,6 +25,7 @@ libhtmlhelpers_la_VALASOURCES = \ globals.vala \ langlet.vala \ doclet.vala \ + htmlrenderer.vala \ $(NULL) diff --git a/src/doclets/htmlhelpers/doclet/doclet.vala b/src/doclets/htmlhelpers/doclet/doclet.vala index 3192bd98d..e57160719 100755 --- a/src/doclets/htmlhelpers/doclet/doclet.vala +++ b/src/doclets/htmlhelpers/doclet/doclet.vala @@ -19,11 +19,16 @@ using GLib; - +using Valadoc.Content; public abstract class Valadoc.Html.BasicDoclet : Valadoc.Doclet { protected Valadoc.Langlet langlet; protected Settings settings; + protected HtmlRenderer _renderer; + + construct { + _renderer = new HtmlRenderer (this); + } protected string? get_link ( DocumentedElement element, DocumentedElement? pos ) { return get_html_link ( this.settings, element, pos ); @@ -86,7 +91,9 @@ public abstract class Valadoc.Html.BasicDoclet : Valadoc.Doclet { if ( page.name != "index.valadoc" ) { GLib.FileStream file = GLib.FileStream.open ( Path.build_filename(contentp, page.name.ndup( page.name.len()-7).replace ("/", ".")+"html"), "w" ); this.write_file_header ( file, css_path_wiki, this.settings.pkg_name ); - page.write ( file ); + _renderer.set_container (page); + _renderer.set_filestream (file); + _renderer.render (page.documentation); this.write_file_footer ( file ); } } @@ -682,41 +689,30 @@ public abstract class Valadoc.Html.BasicDoclet : Valadoc.Doclet { } private void write_brief_description ( GLib.FileStream file, DocumentedElement element , DocumentedElement? pos ) { - DocumentationTree? doctree = element.documentation; + Comment? doctree = element.documentation; if ( doctree == null ) return ; - Gee.Collection brief = doctree.get_brief ( ); - if ( brief.size > 0 ) { + Gee.List description = doctree.content; + if ( description.size > 0 ) { file.printf ( " - ", css_inline_navigation_brief_description ); - int _max = brief.size; - int _index = 0; - foreach ( DocElement element2 in brief ) { - if ( element2 is InlineTaglet ) - file.puts ( ((InlineTaglet)element2).to_string() ); - else - element2.write ( file, _max, _index ); - - _index++; - } + _renderer.set_container (pos); + _renderer.set_filestream (file); + _renderer.render_children (description.get (0)); file.printf ( " \n" ); } } private void write_documentation ( GLib.FileStream file, DocumentedElement element , DocumentedElement? pos ) { - DocumentationTree? doctree = element.documentation; + Comment? doctree = element.documentation; if ( doctree == null ) return ; - Gee.Collection brief = doctree.get_brief ( ); - if ( brief.size > 0 ) { - doctree.write_brief ( file ); - } - file.printf ( "\n
\n" ); - file.printf ( "\n
\n" ); - doctree.write_content ( file ); + _renderer.set_container (pos); + _renderer.set_filestream (file); + _renderer.render (doctree); } public void write_navi_packages_inline ( GLib.FileStream file, Tree tree ) { @@ -747,7 +743,9 @@ public abstract class Valadoc.Html.BasicDoclet : Valadoc.Doclet { WikiPage? wikiindex = (tree.wikitree == null)? null : tree.wikitree.search ( "index.valadoc" ); if ( wikiindex != null ) { - wikiindex.write ( file ); + _renderer.set_container (null); + _renderer.set_filestream (file); + _renderer.render (wikiindex.documentation); } file.printf ( "\t\t\t\t

Content:

\n", css_title ); @@ -1357,7 +1355,9 @@ public abstract class Valadoc.Html.BasicDoclet : Valadoc.Doclet { file.printf ( "\t\t\t\t

Description:

\n", css_title ); if (wikipage != null) { - wikipage.write (file); + _renderer.set_container (mself); + _renderer.set_filestream (file); + _renderer.render (wikipage.documentation); } file.printf ( "\n\t\t\t\t

Content:

\n", css_title ); diff --git a/src/doclets/htmlhelpers/doclet/htmlrenderer.vala b/src/doclets/htmlhelpers/doclet/htmlrenderer.vala new file mode 100755 index 000000000..344b57cfa --- /dev/null +++ b/src/doclets/htmlhelpers/doclet/htmlrenderer.vala @@ -0,0 +1,279 @@ +/* contentvisitor.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Valadoc.Content; + +public class Valadoc.Html.HtmlRenderer : ContentRenderer { + + private BasicDoclet _doclet; + private Documentation? _container; + private unowned FileStream _stream; + + public HtmlRenderer (BasicDoclet doclet) { + _doclet = doclet; + } + + public void set_container (Documentation? container) { + _container = container; + } + + public void set_filestream (FileStream stream) { + _stream = stream; + } + + public override void render (ContentElement element) { + element.accept (this); + } + + public override void render_children (ContentElement element) { + element.accept_children (this); + } + + private string get_url (DocumentedElement symbol) { + return get_html_link (_doclet.settings, symbol, _container); + } + + private void write_symbol_link (DocumentedElement symbol, string label) { + var url = get_url (symbol); + _stream.printf ("%s", + url, + (label == null || label == "") ? symbol.full_name () : label); + } + + private delegate void TagletWrite (Taglet taglet); + + private void write_taglets (string header, string footer, string separator, + Gee.List taglets, TagletWrite write) { + if (taglets.size > 0) { + _stream.printf (header); + bool first = true; + foreach (var taglet in taglets) { + if (!first) { + _stream.printf (separator); + } + write (taglet); + first = false; + } + _stream.printf (footer); + } + } + + public override void visit_comment (Comment element) { + Gee.List taglets; + + taglets = element.find_taglets ((DocumentedElement) _container, typeof (Taglets.Deprecated)); + write_taglets ( + "

Deprecated: ", + "

", + "", + taglets, + (taglet) => { + var deprecated = taglet as Taglets.Deprecated; + deprecated.accept_children (this); + }); + + // Write description + element.accept_children (this); + + taglets = element.find_taglets ((DocumentedElement) _container, typeof (Taglets.Param)); + write_taglets ( + "

Parameters:

\n", + "
", + "", + taglets, + (taglet) => { + var param = taglet as Taglets.Param; + _stream.printf ("%s", param.parameter_name); + param.accept_children (this); + _stream.printf (""); + }); + + taglets = element.find_taglets ((DocumentedElement) _container, typeof (Taglets.Return)); + write_taglets ( + "

Returns:

\n", + "
", + "", + taglets, + (taglet) => { + var param = taglet as Taglets.Return; + _stream.printf (""); + param.accept_children (this); + _stream.printf (""); + }); + + taglets = element.find_taglets ((DocumentedElement) _container, typeof (Taglets.Throws)); + write_taglets ( + "

Throws:

\n", + "
", + "", + taglets, + (taglet) => { + var exception = taglet as Taglets.Throws; + _stream.printf ("%s", exception.error_domain_name); + exception.accept_children (this); + _stream.printf (""); + }); + + taglets = element.find_taglets ((DocumentedElement) _container, typeof (Taglets.Since)); + write_taglets ( + "

Since:

\n

", + "

", + ", ", + taglets, + (taglet) => { + var since = taglet as Taglets.Since; + _stream.printf ("%s", since.version); + }); + + taglets = element.find_taglets ((DocumentedElement) _container, typeof (Taglets.See)); + write_taglets ( + "

See also:

\n

", + "

", + ", ", + taglets, + (taglet) => { + var see = taglet as Taglets.See; + write_symbol_link (see.symbol, see.symbol_name); + }); + } + + public override void visit_embedded (Embedded element) { + var caption = element.caption; + _stream.printf ("%s", + element.url, + (caption == null || caption == "") ? "" : caption); + } + + public override void visit_headline (Headline element) { + _stream.printf ("", element.level); + element.accept_children (this); + _stream.printf ("", element.level); + } + + public override void visit_highlighted (Highlighted element) { + string tag = null; + switch (element.style) { + case Highlighted.Style.BOLD: + tag = "b"; + break; + case Highlighted.Style.ITALIC: + tag = "i"; + break; + case Highlighted.Style.UNDERLINED: + tag = "u"; + break; + case Highlighted.Style.MONOSPACED: + tag = "code"; + break; + case Highlighted.Style.STROKE: + tag = "stroke"; + break; + } + if (tag != null) { + _stream.printf ("<%s>", tag); + } + element.accept_children (this); + if (tag != null) { + _stream.printf ("", tag); + } + } + + public override void visit_link (Link element) { + var label = element.label; + _stream.printf ("%s", + element.url, + (label == null || label == "") ? element.url : label); + } + + public override void visit_symbol_link (SymbolLink element) { + write_symbol_link (element.symbol, element.label); + } + + public override void visit_list (Content.List element) { + } + + public override void visit_list_item (ListItem element) { + } + + public override void visit_page (Page element) { + element.accept_children (this); + } + + public override void visit_paragraph (Paragraph element) { + _stream.printf ("

"); + element.accept_children (this); + _stream.printf ("

"); + } + + public override void visit_source_code (SourceCode element) { + _stream.printf ("
");
+		_stream.printf (element.code);
+		_stream.printf ("
"); + } + + public override void visit_table (Table element) { + } + + public override void visit_table_cell (TableCell element) { + } + + public override void visit_taglet (Taglet element) { + } + + public override void visit_text (Text element) { + write_string (element.content); + } + + private void write_string (string content) { + unichar chr = content[0]; + long lpos = 0; + int i = 0; + + for (i = 0; chr != '\0' ; i++, chr = content[i]) { + switch (chr) { + case '\n': + _stream.puts (content.substring (lpos, i-lpos)); + _stream.puts ("
"); + lpos = i+1; + break; + case '<': + _stream.puts (content.substring (lpos, i-lpos)); + _stream.puts ("<"); + lpos = i+1; + break; + case '>': + _stream.puts (content.substring (lpos, i-lpos)); + _stream.puts (">"); + lpos = i+1; + break; + case '&': + _stream.puts (content.substring (lpos, i-lpos)); + _stream.puts ("&"); + lpos = i+1; + break; + } + } + _stream.puts (content.substring (lpos, i-lpos)); + } +} diff --git a/src/doclets/htmlhelpers/taglets/Makefile.am b/src/doclets/htmlhelpers/taglets/Makefile.am deleted file mode 100755 index 1c84cfac2..000000000 --- a/src/doclets/htmlhelpers/taglets/Makefile.am +++ /dev/null @@ -1,81 +0,0 @@ -NULL = - - -AM_CFLAGS = -g \ - -I ../../../libvaladoc/ \ - -I ../doclet/ \ - $(GLIB_CFLAGS) \ - $(LIBVALA_CFLAGS) \ - $(LIBGDKPIXBUF_CFLAGS) \ - $(NULL) - - -BUILT_SOURCES = libbasictaglets.vala.stamp - - -basictagletsdir = $(libdir)/valadoc/plugins/htmlhelpers/taglets/ - - -basictaglets_LTLIBRARIES = \ - libbasictaglets.la \ - $(NULL) - - -libbasictaglets_la_VALASOURCES = \ - bold.vala \ - center.vala \ - constant.vala \ - headline.vala \ - image.vala \ - italic.vala \ - link.vala \ - list.vala \ - listelement.vala \ - notification.vala \ - paragraph.vala \ - parameter.vala \ - return.vala \ - right.vala \ - see.vala \ - since.vala \ - source.vala \ - string.vala \ - table.vala \ - tablecell.vala \ - throws.vala \ - typelink.vala \ - underline.vala \ - registerfunction.vala \ - $(NULL) - - -libbasictaglets_la_SOURCES = \ - libbasictaglets.vala.stamp \ - $(libbasictaglets_la_VALASOURCES:.vala=.c) \ - $(NULL) - - -libbasictaglets.vala.stamp: $(libbasictaglets_la_VALASOURCES) - $(VALAC) -C --vapidir ../../../vapi --pkg valadoc-1.0 --vapidir ../doclet/ --pkg libhtmlhelpers-1.0 --basedir . --pkg gdk-pixbuf-2.0 $^ - touch $@ - - -libbasictaglets_la_LDFLAGS = -module -avoid-version - - -libbasictaglets_la_LIBADD = \ - ../../../libvaladoc/libvaladoc.la \ - $(LIBGVC_LIBS) \ - $(LIBVALA_LIBS) \ - $(GLIB_LIBS) \ - $(LIBGDKPIXBUFLIBS_) \ - $(NULL) - - -EXTRA_DIST = $(libbasictaglets_la_VALASOURCES) libbasictaglets.vala.stamp - - -MAINTAINERCLEANFILES = \ - $(libbasictaglets_la_VALASOURCES:.vala=.c) \ - $(NULL) - diff --git a/src/doclets/htmlhelpers/taglets/image.vala b/src/doclets/htmlhelpers/taglets/image.vala deleted file mode 100755 index 46ec129ee..000000000 --- a/src/doclets/htmlhelpers/taglets/image.vala +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; -using Gdk; - - -public class Valadoc.Html.ImageDocElement : Valadoc.ImageDocElement { - private static uint counter = 0; - - private string htmlpath; - private string npath; - private string path; - private string alt; - - public override bool parse ( Settings settings, Documentation pos, owned string path, owned string alt ) { - if ( GLib.FileUtils.test ( path, GLib.FileTest.EXISTS | GLib.FileTest.IS_REGULAR ) == false ) { - return false; - } - - weak string? dotpos = path.rchr ( -1, '.' ); - string filename = "img0%u%s".printf(this.counter++, dotpos.ndup(dotpos.size())); - - this.path = realpath ( path ); - - if ( pos == null || (pos is WikiPage)? ((WikiPage)pos).name=="index.valadoc": false ) { - this.htmlpath = Path.build_filename("content", "img", filename); - this.npath = Path.build_filename(settings.path, this.htmlpath); - this.alt = alt; - } - else if ( pos is DocumentedElement ) { - this.htmlpath = Path.build_filename("img", filename); - this.npath = Path.build_filename(settings.path, ((DocumentedElement)pos).package.name, this.htmlpath); - this.alt = alt; - } - else { - this.htmlpath = Path.build_filename("img", filename); - this.npath = Path.build_filename(settings.path, "content", this.htmlpath); - this.alt = alt; - } - return true; - } - - private string? create_thumb (string filename, string destinationpath) { - int height; - int width; - - weak PixbufFormat format = Pixbuf.get_file_info (filename, out width, out height); - if ( width == 0 || height == 0 ) { - return null; - } - - if ( width > 700 ) { - try { - Pixbuf img = new Pixbuf.from_file (filename); - - int dest_height = (height*700)/width; - int dest_width = 700; - - - if (dest_height == 0) { - dest_height++; - } - - Pixbuf dest = new Pixbuf (img.get_colorspace(), img.get_has_alpha(), img.get_bits_per_sample(), dest_width, dest_height); - img.scale (dest, 0, 0, dest_width, dest_height, 0, 0, (double)dest_width/img.get_width(), (double)dest_height/img.get_height(), Gdk.InterpType.BILINEAR); - - string newfilename = GLib.Path.build_filename(destinationpath, "tmb_"+Path.get_basename (filename)); - dest.save (newfilename, format.get_name()); - return newfilename; - } - catch (Error err) { - return null; - } - } - - return filename; - } - - public override bool write ( void* res, int max, int index ) { - bool tmp = copy_file ( this.path, this.npath ); - if ( tmp == false ) - return false; - - string thumbpath = create_thumb (this.npath, Path.get_dirname(this.npath)); - if ( thumbpath == null ) { - return false; - } - - ((GLib.FileStream)res).printf ( "\"%s\"", this.htmlpath, thumbpath, this.alt ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/link.vala b/src/doclets/htmlhelpers/taglets/link.vala deleted file mode 100755 index e19811b17..000000000 --- a/src/doclets/htmlhelpers/taglets/link.vala +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.LinkDocElement : Valadoc.LinkDocElement { - protected string desc; - protected string path; - - public override bool parse ( Settings settings, Tree tree, Documentation pos, owned string path, owned string desc ) { - if ( path.has_suffix(".valadoc")&&path.has_prefix("/") ) { - if ( tree.wikitree == null ) { - return false; - } - - WikiPage? wikipage = tree.wikitree.search(path.offset(1)); - if ( wikipage == null ) { - return false; - } - - this.path = get_html_link(settings, wikipage, pos); - this.desc = (owned)desc; - return true; - } - - this.path = (owned)path; - this.desc = (owned)desc; - return true; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - file.printf ("%s", this.path, (this.desc==null||this.desc=="")? this.path: this.desc ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/list.vala b/src/doclets/htmlhelpers/taglets/list.vala deleted file mode 100755 index e543782d4..000000000 --- a/src/doclets/htmlhelpers/taglets/list.vala +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.ListDocElement : Valadoc.ListDocElement { - private Gee.ArrayList entries; - private ListType type; - - public override bool parse ( ListType type, Gee.ArrayList entries ) { - this.entries = entries; - this.type = type; - return true; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.entries.size; - int _index = 0; - - file.printf ( (this.type == ListType.UNSORTED)? "
    \n" : "
      \n" ); - - foreach ( ListEntryDocElement entry in this.entries ) { - entry.write ( res, _max, _index ); - _index++; - } - - file.printf ( (this.type == ListType.UNSORTED)? "
\n" : "\n" ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/notification.vala b/src/doclets/htmlhelpers/taglets/notification.vala deleted file mode 100755 index b70679cb9..000000000 --- a/src/doclets/htmlhelpers/taglets/notification.vala +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -using GLib; -using Gee; - - -public class Valadoc.Html.NotificationDocElement : Valadoc.NotificationDocElement { - private Gee.ArrayList content; - - public override bool parse ( Gee.ArrayList content ) { - this.content = content; - return true; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; - - file.printf ( "\n
\n", css_notification_area ); - - foreach ( DocElement element in this.content ) { - element.write ( res, _max, _index ); - _index++; - } - - file.printf ( "\n
\n" ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/parameter.vala b/src/doclets/htmlhelpers/taglets/parameter.vala deleted file mode 100755 index 5464fdc12..000000000 --- a/src/doclets/htmlhelpers/taglets/parameter.vala +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.ParameterTaglet : Valadoc.MainTaglet { - public override int order { get { return 100; } } - private Gee.Collection content; - private string paramname; - - private static bool check_parameter_name ( Valadoc.ParameterListHandler me, string name ) { - if ( name == "" ) - return false; - - foreach ( Valadoc.FormalParameter param in me.get_parameter_list ( ) ) { - if ( param.name == name ) - return true; - } - return false; - } - - public override bool write ( void* ptr, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)ptr; - - file.printf ( "\t\n" ); - file.printf ( "\t\t%s:\n", css_parameter_table_name, this.paramname ); - file.printf ( "\t\t\n", css_parameter_table_text ); - file.puts ( "\t\t\t" ); - - int _max = this.content.size; - int _index = 0; - - foreach ( DocElement tag in this.content ) { - tag.write ( ptr, _max, _index ); - _index++; - } - - file.puts ( "\n" ); - file.printf ( "\t\t\n" ); - file.printf ( "\t\n" ); - return true; - } - - public override bool write_block_start ( void* ptr ) { - weak GLib.FileStream file = (GLib.FileStream)ptr; - file.printf ( "

Parameters:

\n", css_title ); - file.printf ( "\n", css_parameter_table ); - return true; - } - - public override bool write_block_end ( void* ptr ) { - weak GLib.FileStream file = (GLib.FileStream)ptr; - file.printf ( "
\n" ); - return true; - } - - public override bool parse ( Settings settings, Tree tree, DocumentedElement me, Gee.Collection content, ref ErrorLevel errlvl, out string errmsg ) { - if ( me is Valadoc.ParameterListHandler == false ) { - errmsg = "Tag @param cannot be used in this context"; - errlvl = ErrorLevel.ERROR; - return false; - } - - if ( content.size == 0 ) { - errmsg = "Parameter name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - Gee.ArrayList contentlst = new Gee.ArrayList (); - foreach ( DocElement element in content ) { - contentlst.add ( element ); - } - - DocElement tag = contentlst.get( 0 ); - if ( tag is StringTaglet == false ) { - errmsg = "Parameter name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - string str = ((StringTaglet)tag).content; - weak string lposa = str.chr (-1, '\n'); - weak string lposb = str.chr (-1, ' '); - weak string lpos; - - long lposaoffset = (lposa == null)? long.MAX : str.pointer_to_offset ( lposa ); - long lposboffset = (lposb == null)? long.MAX : str.pointer_to_offset ( lposb ); - - if ( lposaoffset < lposboffset ) - lpos = lposa; - else - lpos = lposb; - - if ( lpos == null ) { - this.paramname = str.strip (); - ((StringTaglet)tag).content = ""; - } - else { - int namepos = (int)str.pointer_to_offset ( lpos ); - this.paramname = str.ndup ( namepos ).strip (); - ((StringTaglet)tag).content = lpos.ndup ( lpos.size () ).chomp (); - } - - bool tmp = this.check_parameter_name ( (Valadoc.ParameterListHandler)me, this.paramname ); - if ( tmp == false ) { - errmsg = "Parameter is not available"; - errlvl = ErrorLevel.ERROR; - return false; - } - - this.content = contentlst; - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/registerfunction.vala b/src/doclets/htmlhelpers/taglets/registerfunction.vala deleted file mode 100644 index ab7da07d2..000000000 --- a/src/doclets/htmlhelpers/taglets/registerfunction.vala +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -using Valadoc; - - -[ModuleInit] -public void register_plugin (ModuleLoader loader) { - loader.underline = typeof (Valadoc.Html.UnderlinedDocElement); - loader.table_cell = typeof (Valadoc.Html.TableCellDocElement); - loader.table = typeof (Valadoc.Html.TableDocElement); - loader.string = typeof (Valadoc.Html.StringTaglet); - loader.source = typeof (Valadoc.Html.SourceCodeDocElement); - loader.right = typeof (Valadoc.Html.RightAlignedDocElement); - loader.paragraph = typeof (Valadoc.Html.ParagraphDocElement); - loader.notification = typeof (Valadoc.Html.NotificationDocElement); - loader.list_element = typeof (Valadoc.Html.ListEntryDocElement); - loader.list = typeof (Valadoc.Html.ListDocElement); - loader.link = typeof (Valadoc.Html.LinkDocElement); - loader.italic = typeof (Valadoc.Html.ItalicDocElement); - loader.image = typeof (Valadoc.Html.ImageDocElement); - loader.headline = typeof (Valadoc.Html.HeadlineDocElement); - loader.source_inline = typeof (Valadoc.Html.CodeConstantDocElement); - loader.center = typeof (Valadoc.Html.CenterDocElement); - loader.bold = typeof (Valadoc.Html.BoldDocElement); - - loader.taglets.set ("see", typeof (Valadoc.Html.SeeTaglet)); - loader.taglets.set ("since", typeof (Valadoc.Html.SinceTaglet)); - loader.taglets.set ("link", typeof (Valadoc.Html.TypeLinkInlineTaglet)); - loader.taglets.set ("throws", typeof (Valadoc.Html.ExceptionTaglet)); - loader.taglets.set ("return", typeof (Valadoc.Html.ReturnTaglet)); - loader.taglets.set ("param", typeof (Valadoc.Html.ParameterTaglet)); -} - - diff --git a/src/doclets/htmlhelpers/taglets/return.vala b/src/doclets/htmlhelpers/taglets/return.vala deleted file mode 100755 index 5fb6409fa..000000000 --- a/src/doclets/htmlhelpers/taglets/return.vala +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.ReturnTaglet : Valadoc.MainTaglet { - public override int order { get { return 300; } } - private Gee.Collection content; - - - public override bool parse ( Settings settings, Tree tree, DocumentedElement me, Gee.Collection content, ref ErrorLevel errlvl, out string errmsg ) { - if ( !(me is Valadoc.Method || me is Valadoc.Signal || me is Valadoc.Delegate) ) { - errmsg = "Tag @return cannot be used in this context"; - errlvl = ErrorLevel.ERROR; - return false; - } - this.content = content; - return true; - } - - public override bool write ( void* res, int max, int index ) { - int _max = this.content.size; - int _index = 0; - - foreach ( DocElement element in this.content ) { - element.write ( res, _max, _index ); - _index++; - } - return true; - } - - public override bool write_block_start ( void* res ) { - weak GLib.FileStream file = (GLib.FileStream)res; - file.printf ( "

Returns:

\n", css_title ); - return true; - } - - public override bool write_block_end ( void* res ) { - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/right.vala b/src/doclets/htmlhelpers/taglets/right.vala deleted file mode 100755 index 5a536f785..000000000 --- a/src/doclets/htmlhelpers/taglets/right.vala +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.RightAlignedDocElement : Valadoc.RightAlignedDocElement { - private Gee.ArrayList content; - - public override bool parse ( Gee.ArrayList content ) { - this.content = content; - return true; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; - - file.printf ( "
" ); - - foreach ( DocElement element in this.content ) { - element.write ( res, _max, _index ); - _index++; - } - - file.printf ( "
" ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/see.vala b/src/doclets/htmlhelpers/taglets/see.vala deleted file mode 100755 index 2a68e31e7..000000000 --- a/src/doclets/htmlhelpers/taglets/see.vala +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using Valadoc; -using GLib; -using Gee; - - -public class Valadoc.Html.SeeTaglet : MainTaglet { - public override int order { get { return 400; } } - private string name; - private string link; - private string css; - - protected override bool write_block_start ( void* res ) { - weak GLib.FileStream file = (GLib.FileStream)res; - file.printf ( "

See:

\n", css_title ); - return true; - } - - protected override bool write_block_end ( void* res ) { - return true; - } - - protected override bool write ( void* res, int max, int index ) { - if ( this.link == null ) { - ((GLib.FileStream)res).printf ( "%s", this.css, this.name ); - } - else { - ((GLib.FileStream)res).printf ( "%s", this.css, this.link, this.name ); - } - - if ( max != index+1 ) { - ((GLib.FileStream)res).printf ( ", " ); - } - return true; - } - - public override bool parse ( Settings settings, Tree tree, DocumentedElement me, Gee.Collection content, ref ErrorLevel errlvl, out string errmsg ) { - if ( content.size != 1 ) { - errmsg = "Type name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - Gee.Iterator it = content.iterator (); - it.next (); - - DocElement element = it.get (); - if ( element is StringTaglet == false ) { - errmsg = "Type name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - Valadoc.DocumentedElement? node = tree.search_symbol_str ( me, ((StringTaglet)element).content.strip ( ) ); - if ( node == null ) { - errmsg = "Linked type is not available"; - errlvl = ErrorLevel.ERROR; - return false; - } - - this.name = node.full_name ( ); - this.css = get_html_content_link_css_class ( node ); - this.link = get_html_link ( settings, node, me ); - return true; - } -} - diff --git a/src/doclets/htmlhelpers/taglets/since.vala b/src/doclets/htmlhelpers/taglets/since.vala deleted file mode 100755 index 5d497ca64..000000000 --- a/src/doclets/htmlhelpers/taglets/since.vala +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.SinceTaglet : Valadoc.MainTaglet { - public override int order { get { return 400; } } - private StringTaglet content; - - public override bool write_block_start ( void* ptr ) { - weak GLib.FileStream file = (GLib.FileStream)ptr; - file.printf ( "

Since:

\n", css_title ); - return true; - } - - public override bool write_block_end ( void* res ) { - return true; - } - - public override bool write ( void* res, int max, int index ) { - ((GLib.FileStream)res).printf ( "%s", this.content.content ); - if ( max != index+1 ) - ((GLib.FileStream)res).puts ( ", " ); - - return true; - } - - public override bool parse ( Settings settings, Tree tree, DocumentedElement me, Gee.Collection content, ref ErrorLevel errlvl, out string errmsg ) { - if ( content.size != 1 ) { - errmsg = "Version name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - Gee.Iterator it = content.iterator (); - it.next (); - - DocElement element = it.get (); - if ( element is StringTaglet == false ) { - errmsg = "Version name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - this.content = (StringTaglet)element; - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/source.vala b/src/doclets/htmlhelpers/taglets/source.vala deleted file mode 100755 index 03632f70f..000000000 --- a/src/doclets/htmlhelpers/taglets/source.vala +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.SourceCodeDocElement : Valadoc.SourceCodeDocElement { - private Language lang; - private int srclines; - private string src; - - public override bool parse (string src, Language lang) { - this.src = src; - this.lang = lang; - this.srclines=0; - - for (weak string str=this.src; str.get_char()!='\0'; str=str.next_char()) { - if (str.get_char () == '\n') { - this.srclines++; - } - } - return true; - } - - public override bool write (void* res, int max, int index) { - weak GLib.FileStream file = (GLib.FileStream)res; - file.printf ("\n\n\t
", css_source_sample);
-		file.puts (src);
-		file.puts ("
\n\n"); - return true; - } -} - - - diff --git a/src/doclets/htmlhelpers/taglets/string.vala b/src/doclets/htmlhelpers/taglets/string.vala deleted file mode 100755 index 762223cb1..000000000 --- a/src/doclets/htmlhelpers/taglets/string.vala +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.StringTaglet : Valadoc.StringTaglet { - public override bool parse ( string content ) { - this.content = content; - return true; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - unichar chr = content[0]; - long lpos = 0; - int i = 0; - - for ( i = 0; chr != '\0' ; i++, chr = content[i] ) { - switch ( chr ) { - case '\n': - file.puts ( content.substring (lpos, i-lpos) ); - file.puts ( "
" ); - lpos = i+1; - break; - case '<': - file.puts ( content.substring (lpos, i-lpos) ); - file.puts ( "<" ); - lpos = i+1; - break; - case '>': - file.puts ( content.substring (lpos, i-lpos) ); - file.puts ( ">" ); - lpos = i+1; - break; - case '&': - file.puts ( content.substring (lpos, i-lpos) ); - file.puts ( "&" ); - lpos = i+1; - break; - } - } - file.puts ( content.substring (lpos, i-lpos) ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/table.vala b/src/doclets/htmlhelpers/taglets/table.vala deleted file mode 100755 index eeea92087..000000000 --- a/src/doclets/htmlhelpers/taglets/table.vala +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.TableDocElement : Valadoc.TableDocElement { - private Gee.ArrayList> cells; - - public override void parse ( Gee.ArrayList> cells ) { - this.cells = cells; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - - file.printf ( "\n", css_wiki_table ); - foreach ( Gee.ArrayList row in this.cells ) { - int _max = row.size; - int _index = 0; - - file.puts ( "\t\n" ); - foreach ( TableCellDocElement cell in row ) { - cell.write ( res, _max, _index ); - _index++; - } - file.puts ( "\t\n" ); - - } - file.puts ( "
\n" ); - return true; - } -} - - - diff --git a/src/doclets/htmlhelpers/taglets/tablecell.vala b/src/doclets/htmlhelpers/taglets/tablecell.vala deleted file mode 100755 index adf0938b0..000000000 --- a/src/doclets/htmlhelpers/taglets/tablecell.vala +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -using GLib; -using Gee; - - -public class Valadoc.Html.TableCellDocElement : Valadoc.TableCellDocElement { - private Gee.ArrayList content; - private TextVerticalPosition hpos; - private TextPosition pos; - private int dcells; - private int cells; - - public override void parse ( TextPosition pos, TextVerticalPosition hpos, int cells, int dcells, Gee.ArrayList content ) { - this.content = content; - this.dcells = dcells; - this.cells = cells; - this.hpos = hpos; - this.pos = pos; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; - - GLib.StringBuilder td = new GLib.StringBuilder ( "\t\t' ); - - file.puts ( td.str ); - foreach ( DocElement cell in this.content ) { - cell.write ( res, _max, _index ); - _index++; - } - file.puts ( "\n" ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/throws.vala b/src/doclets/htmlhelpers/taglets/throws.vala deleted file mode 100755 index a8e41202c..000000000 --- a/src/doclets/htmlhelpers/taglets/throws.vala +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.ExceptionTaglet : Valadoc.MainTaglet { - public override int order { get { return 200; } } - private Gee.ArrayList content; - private string paramname; - - public override bool parse ( Settings settings, Tree tree, DocumentedElement me, Gee.Collection content, ref ErrorLevel errlvl, out string errmsg ) { - if ( me is Valadoc.ExceptionHandler == false ) { - errmsg = "Tag @throws cannot be used in this context"; - errlvl = ErrorLevel.ERROR; - return false; - } - - if ( content.size == 0 ) { - errmsg = "Exception name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - - Gee.ArrayList contentlst = new Gee.ArrayList (); - foreach ( DocElement element in content ) { - contentlst.add ( element ); - } - - DocElement tag = contentlst.get( 0 ); - if ( tag is StringTaglet == false ) { - errmsg = "Exception name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - string str = ((StringTaglet)tag).content; - weak string lposa = str.chr (-1, '\n'); - weak string lposb = str.chr (-1, ' '); - weak string lpos; - - long lposaoffset = (lposa == null)? long.MAX : str.pointer_to_offset ( lposa ); - long lposboffset = (lposb == null)? long.MAX : str.pointer_to_offset ( lposb ); - - if ( lposaoffset < lposboffset ) { - lpos = lposa; - } - else { - lpos = lposb; - } - - if ( lpos == null ) { - this.paramname = str.strip (); - ((StringTaglet)tag).content = ""; - } - else { - int namepos = (int)str.pointer_to_offset ( lpos ); - this.paramname = str.ndup ( namepos ).strip (); - ((StringTaglet)tag).content = lpos.ndup ( lpos.size () ).chomp (); - } - - bool tmp = this.check_exception_parameter_name ( (Valadoc.ExceptionHandler)me, this.paramname ); - if ( tmp == false ) { - errmsg = "Exception name was expected"; - errlvl = ErrorLevel.ERROR; - return false; - } - - this.content = contentlst; - return true; - } - - private bool check_exception_parameter_name ( Valadoc.ExceptionHandler me, string paramname ) { - string paramname2 = "."+paramname; - - foreach ( DocumentedElement param in me.get_error_domains() ) { - if ( param.name == paramname || param.full_name() == paramname || param.full_name().has_suffix(paramname2) ) { - return true; - } - } - return false; - } - - public override bool write ( void* ptr, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)ptr; - - file.printf ( "\t\n" ); - file.printf ( "\t\t%s:\n", css_parameter_table_name, this.paramname ); - file.printf ( "\t\t\n", css_parameter_table_text ); - file.puts ( "\t\t\t" ); - - int _max = this.content.size; - int _index = 0; - - foreach ( DocElement element in this.content ) { - element.write ( ptr, _max, _index ); - _index++; - } - - file.puts ( "\n" ); - file.printf ( "\t\t\n" ); - file.printf ( "\t\n" ); - return true; - } - - public override bool write_block_start ( void* ptr ) { - weak GLib.FileStream file = (GLib.FileStream)ptr; - file.printf ( "

Exceptions:

\n", css_title ); - file.printf ( "\n", css_exception_table ); - return true; - } - - public override bool write_block_end ( void* ptr ) { - weak GLib.FileStream file = (GLib.FileStream)ptr; - file.printf ( "
\n" ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/typelink.vala b/src/doclets/htmlhelpers/taglets/typelink.vala deleted file mode 100755 index 873149319..000000000 --- a/src/doclets/htmlhelpers/taglets/typelink.vala +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.TypeLinkInlineTaglet : Valadoc.InlineTaglet { - private string? link = null; - private string? name = null; - private string? css = null; - - protected override string to_string ( ) { - return this.name; - } - - protected override bool write ( void* res, int max, int index ) { - if ( this.link == null ) { - ((GLib.FileStream)res).printf ( "%s", this.css, this.name ); - } - else { - ((GLib.FileStream)res).printf ( "%s", this.css, this.link, this.name ); - } - - return true; - } - - protected override bool parse ( Settings settings, Tree tree, Documentation self, string content, ref ErrorLevel errlvl, out string? errmsg ) { - Valadoc.DocumentedElement? element = tree.search_symbol_str ( (self is DocumentedElement)? (DocumentedElement)self : null, content.strip() ); - if ( element == null ) { - errmsg = "Linked type is not available"; - errlvl = ErrorLevel.ERROR; - return false; - } - - this.name = element.full_name (); - if (self is DocumentedElement) { - var doc_element = (DocumentedElement) self; - var doc_element_name = doc_element.full_name (); - - if (this.name == doc_element_name) { - this.name = element.name; - } else if (this.name.has_prefix (doc_element_name)) { - this.name = this.name.substring (doc_element_name.length + 1); - } else if (doc_element.parent != null && doc_element.parent is DocumentedElement) { - var doc_parent_element_name = ((DocumentedElement) doc_element.parent).full_name (); - if (this.name == doc_parent_element_name) { - this.name = element.name; - } else if (this.name.has_prefix (doc_parent_element_name)) { - this.name = this.name.substring (doc_parent_element_name.length + 1); - } - } - } - this.css = get_html_content_link_css_class ( element ); - this.link = get_html_link ( settings, element, self ); - return true; - } -} - - diff --git a/src/doclets/htmlhelpers/taglets/underline.vala b/src/doclets/htmlhelpers/taglets/underline.vala deleted file mode 100755 index 755159def..000000000 --- a/src/doclets/htmlhelpers/taglets/underline.vala +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -using GLib; -using Gee; - - -public class Valadoc.Html.UnderlinedDocElement : Valadoc.UnderlinedDocElement { - private Gee.ArrayList content; - - public override bool parse ( Gee.ArrayList content ) { - this.content = content; - return true; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; - - file.printf ( "" ); - - foreach ( DocElement element in this.content ) { - element.write ( res, _max, _index ); - _index++; - } - - file.printf ( "" ); - return true; - } -} - - diff --git a/src/libvaladoc/html-apiwriter/apiwriter-vala.vala b/src/doclets/valadoc.org/html-apiwriter/apiwriter-vala.vala similarity index 100% rename from src/libvaladoc/html-apiwriter/apiwriter-vala.vala rename to src/doclets/valadoc.org/html-apiwriter/apiwriter-vala.vala diff --git a/src/libvaladoc/html-apiwriter/apiwriter.vala b/src/doclets/valadoc.org/html-apiwriter/apiwriter.vala similarity index 100% rename from src/libvaladoc/html-apiwriter/apiwriter.vala rename to src/doclets/valadoc.org/html-apiwriter/apiwriter.vala diff --git a/src/libvaladoc/html/attribute.vala b/src/doclets/valadoc.org/html/attribute.vala similarity index 100% rename from src/libvaladoc/html/attribute.vala rename to src/doclets/valadoc.org/html/attribute.vala diff --git a/src/libvaladoc/html/block.vala b/src/doclets/valadoc.org/html/block.vala similarity index 100% rename from src/libvaladoc/html/block.vala rename to src/doclets/valadoc.org/html/block.vala diff --git a/src/libvaladoc/html/htmlwriter.vala b/src/doclets/valadoc.org/html/htmlwriter.vala similarity index 100% rename from src/libvaladoc/html/htmlwriter.vala rename to src/doclets/valadoc.org/html/htmlwriter.vala diff --git a/src/libvaladoc/html/inline.vala b/src/doclets/valadoc.org/html/inline.vala similarity index 100% rename from src/libvaladoc/html/inline.vala rename to src/doclets/valadoc.org/html/inline.vala diff --git a/src/libvaladoc/Makefile.am b/src/libvaladoc/Makefile.am index 9a934f253..9ebad31c9 100644 --- a/src/libvaladoc/Makefile.am +++ b/src/libvaladoc/Makefile.am @@ -26,10 +26,9 @@ libvaladoc_la_VALASOURCES = \ filehelper.vala \ langlet.vala \ settings.vala \ - documentation/doctree.vala \ + documentation/documentation.vala \ documentation/errorreporter.vala \ documentation/moduleloader.vala \ - documentation/parser.vala \ documentation/wiki.vala \ apitree/apitree.vala \ apitree/array.vala \ @@ -74,12 +73,56 @@ libvaladoc_la_VALASOURCES = \ apitree/typeparameter.vala \ apitree/typereference.vala \ apitree/visitable.vala \ - html/attribute.vala \ - html/block.vala \ - html/htmlwriter.vala \ - html/inline.vala \ - html-apiwriter/apiwriter.vala \ - html-apiwriter/apiwriter-vala.vala \ + content/block.vala \ + content/blockcontent.vala \ + content/comment.vala \ + content/contentfactory.vala \ + content/contentelement.vala \ + content/contentrenderer.vala \ + content/contentvisitor.vala \ + content/embedded.vala \ + content/headline.vala \ + content/highlighted.vala \ + content/inline.vala \ + content/inlinetaglet.vala \ + content/inlinecontent.vala \ + content/link.vala \ + content/list.vala \ + content/listitem.vala \ + content/page.vala \ + content/paragraph.vala \ + content/resourcelocator.vala \ + content/sourcecode.vala \ + content/styleattributes.vala \ + content/symbollink.vala \ + content/table.vala \ + content/tablecell.vala \ + content/taglet.vala \ + content/text.vala \ + parser/commentscanner.vala \ + parser/documentationparser.vala \ + parser/manyrule.vala \ + parser/oneofrule.vala \ + parser/optionalrule.vala \ + parser/parser.vala \ + parser/parsercallback.vala \ + parser/rule.vala \ + parser/scanner.vala \ + parser/sequencerule.vala \ + parser/sourcelocation.vala \ + parser/stubrule.vala \ + parser/token.vala \ + parser/tokentype.vala \ + parser/wikiscanner.vala \ + taglets/tagletdeprecated.vala \ + taglets/tagletinheritdoc.vala \ + taglets/tagletinit.vala \ + taglets/tagletlink.vala \ + taglets/tagletparam.vala \ + taglets/tagletreturn.vala \ + taglets/tagletsee.vala \ + taglets/tagletsince.vala \ + taglets/tagletthrows.vala \ $(NULL) @@ -98,7 +141,7 @@ libvaladocincludedir = $(includedir)/ libvaladoc.vala.stamp: $(libvaladoc_la_VALASOURCES) - $(VALAC) -C -H valadoc-1.0.h --pkg vala-1.0 --pkg gmodule-2.0 --vapidir ../vapi --pkg libxml-2.0 --pkg libgvc --library valadoc-1.0 --basedir $(top_srcdir)/src/libvaladoc/ --save-temps $^ + $(VALAC) $(VALAFLAGS) -C -H valadoc-1.0.h --pkg vala-1.0 --pkg gmodule-2.0 --vapidir ../vapi --pkg libxml-2.0 --pkg libgvc --library valadoc-1.0 --basedir $(top_srcdir)/src/libvaladoc/ --save-temps $^ touch $@ diff --git a/src/libvaladoc/apitree/apitree.vala b/src/libvaladoc/apitree/apitree.vala index 31a9e8319..ec7c7f11d 100644 --- a/src/libvaladoc/apitree/apitree.vala +++ b/src/libvaladoc/apitree/apitree.vala @@ -471,7 +471,7 @@ public class Valadoc.Tree : Vala.CodeVisitor { } } - public void parse_comments (Valadoc.Parser docparser) { + public void parse_comments (DocumentationParser docparser) { this.wikitree = new WikiPageTree(this.reporter, this.settings); wikitree.create_tree (docparser); diff --git a/src/libvaladoc/apitree/class.vala b/src/libvaladoc/apitree/class.vala index 31394325f..858ceca05 100644 --- a/src/libvaladoc/apitree/class.vala +++ b/src/libvaladoc/apitree/class.vala @@ -274,18 +274,12 @@ public class Valadoc.Class : DocumentedElement, SymbolAccessibility, Visitable, doclet.visit_class ( this ); } - internal void parse_comments ( Valadoc.Parser docparser ) { + internal void parse_comments ( DocumentationParser docparser ) { if ( this.documentation != null ) return ; if ( this.vcomment != null ) { - if ( docparser.is_inherit_doc ( this ) && this.base_type != null ) { - ((Class)this.base_type).parse_comments ( docparser ); - this.documentation = this.base_type.documentation; - } - else { - this.parse_comment_helper ( docparser ); - } + this.parse_comment_helper ( docparser ); } this.parse_construction_method_comments ( docparser ); diff --git a/src/libvaladoc/apitree/classhandler.vala b/src/libvaladoc/apitree/classhandler.vala index be5e20636..a93ad26f7 100644 --- a/src/libvaladoc/apitree/classhandler.vala +++ b/src/libvaladoc/apitree/classhandler.vala @@ -95,7 +95,7 @@ public interface Valadoc.ClassHandler : Basic { } } - protected void parse_class_comments ( Valadoc.Parser docparser ) { + protected void parse_class_comments ( DocumentationParser docparser ) { foreach ( Class cl in this.classes ) { cl.parse_comments ( docparser ); } diff --git a/src/libvaladoc/apitree/constant.vala b/src/libvaladoc/apitree/constant.vala index c9f033f5b..1f7429403 100644 --- a/src/libvaladoc/apitree/constant.vala +++ b/src/libvaladoc/apitree/constant.vala @@ -55,7 +55,7 @@ public class Valadoc.Constant : DocumentedElement, SymbolAccessibility, Visitabl ((ReturnTypeHandler)this).set_return_type_references ( ); } - internal void parse_comment ( Valadoc.Parser docparser ) { + internal void parse_comment ( DocumentationParser docparser ) { this.parse_comment_helper ( docparser ); } diff --git a/src/libvaladoc/apitree/constanthandler.vala b/src/libvaladoc/apitree/constanthandler.vala index e9fbb484b..6caa9489c 100644 --- a/src/libvaladoc/apitree/constanthandler.vala +++ b/src/libvaladoc/apitree/constanthandler.vala @@ -87,7 +87,7 @@ public interface Valadoc.ConstantHandler : Basic { } } - internal void parse_constant_comments ( Valadoc.Parser docparser ) { + internal void parse_constant_comments ( DocumentationParser docparser ) { foreach ( Constant c in this.constants ) { c.parse_comment ( docparser ); } diff --git a/src/libvaladoc/apitree/constructionmethodhandler.vala b/src/libvaladoc/apitree/constructionmethodhandler.vala index 6a6f00468..efe336e9d 100644 --- a/src/libvaladoc/apitree/constructionmethodhandler.vala +++ b/src/libvaladoc/apitree/constructionmethodhandler.vala @@ -75,7 +75,7 @@ public interface Valadoc.ConstructionMethodHandler : Basic, MethodHandler { return lst.read_only_view; } - protected void parse_construction_method_comments ( Valadoc.Parser docparser ) { + protected void parse_construction_method_comments ( DocumentationParser docparser ) { foreach ( Method cm in this.construction_methods ) { cm.parse_comment ( docparser ); } diff --git a/src/libvaladoc/apitree/delegate.vala b/src/libvaladoc/apitree/delegate.vala index c0a151625..9e4631006 100644 --- a/src/libvaladoc/apitree/delegate.vala +++ b/src/libvaladoc/apitree/delegate.vala @@ -90,7 +90,7 @@ public class Valadoc.Delegate : DocumentedElement, SymbolAccessibility, Visitabl this.add_exception_list ( vexceptionlst ); } - internal void parse_comment ( Valadoc.Parser docparser ) { + internal void parse_comment ( DocumentationParser docparser ) { this.parse_comment_helper ( docparser ); } diff --git a/src/libvaladoc/apitree/delegatehandler.vala b/src/libvaladoc/apitree/delegatehandler.vala index c8d24fdb1..cf9839192 100644 --- a/src/libvaladoc/apitree/delegatehandler.vala +++ b/src/libvaladoc/apitree/delegatehandler.vala @@ -90,7 +90,7 @@ public interface Valadoc.DelegateHandler : Basic { } } - public void parse_delegate_comments ( Valadoc.Parser docparser ) { + public void parse_delegate_comments ( DocumentationParser docparser ) { foreach ( Delegate del in this.delegates ) { del.parse_comment ( docparser ); } diff --git a/src/libvaladoc/apitree/documentedelement.vala b/src/libvaladoc/apitree/documentedelement.vala index ba88f56d2..db94184d7 100644 --- a/src/libvaladoc/apitree/documentedelement.vala +++ b/src/libvaladoc/apitree/documentedelement.vala @@ -74,7 +74,7 @@ public abstract class Valadoc.DocumentedElement : Basic, Documentation { get; set; } - public DocumentationTree? documentation { + public Content.Comment? documentation { protected set; get; } @@ -120,7 +120,7 @@ public abstract class Valadoc.DocumentedElement : Basic, Documentation { return GLib.Path.get_basename ( path ); } - protected void parse_comment_helper ( Valadoc.Parser docparser ) { + protected void parse_comment_helper ( DocumentationParser docparser ) { this.documentation = docparser.parse ( this ); } diff --git a/src/libvaladoc/apitree/enum.vala b/src/libvaladoc/apitree/enum.vala index d71a83411..f798d2fad 100644 --- a/src/libvaladoc/apitree/enum.vala +++ b/src/libvaladoc/apitree/enum.vala @@ -134,7 +134,7 @@ public class Valadoc.Enum : DocumentedElement, SymbolAccessibility, Visitable, M return this.en_values.read_only_view; } - internal void parse_comments ( Valadoc.Parser docparser ) { + internal void parse_comments ( DocumentationParser docparser ) { this.parse_comment_helper ( docparser ); foreach ( EnumValue enval in this.en_values ) { diff --git a/src/libvaladoc/apitree/enumhandler.vala b/src/libvaladoc/apitree/enumhandler.vala index 1efe3b1ff..03b397429 100644 --- a/src/libvaladoc/apitree/enumhandler.vala +++ b/src/libvaladoc/apitree/enumhandler.vala @@ -82,7 +82,7 @@ public interface Valadoc.EnumHandler : Basic { this.enums.add( tmp ); } - protected void parse_enum_comments ( Valadoc.Parser docparser ) { + protected void parse_enum_comments ( DocumentationParser docparser ) { foreach ( Enum en in this.enums ) { en.parse_comments ( docparser ); } diff --git a/src/libvaladoc/apitree/enumvalue.vala b/src/libvaladoc/apitree/enumvalue.vala index ceac5e368..e7f405391 100644 --- a/src/libvaladoc/apitree/enumvalue.vala +++ b/src/libvaladoc/apitree/enumvalue.vala @@ -43,7 +43,7 @@ public class Valadoc.EnumValue: DocumentedElement { return ( this.venval == venval ); } - public void parse_comment ( Valadoc.Parser docparser ) { + public void parse_comment ( DocumentationParser docparser ) { this.parse_comment_helper ( docparser ); } diff --git a/src/libvaladoc/apitree/errorcode.vala b/src/libvaladoc/apitree/errorcode.vala index ca4f0faa9..29d38abae 100644 --- a/src/libvaladoc/apitree/errorcode.vala +++ b/src/libvaladoc/apitree/errorcode.vala @@ -47,7 +47,7 @@ public class Valadoc.ErrorCode : DocumentedElement { langlet.write_error_code ( this, ptr ); } - public void parse_comment ( Valadoc.Parser docparser ) { + public void parse_comment ( DocumentationParser docparser ) { this.parse_comment_helper ( docparser ); } diff --git a/src/libvaladoc/apitree/errordomain.vala b/src/libvaladoc/apitree/errordomain.vala index dbcfe0d50..71794f66f 100644 --- a/src/libvaladoc/apitree/errordomain.vala +++ b/src/libvaladoc/apitree/errordomain.vala @@ -128,7 +128,7 @@ public class Valadoc.ErrorDomain : DocumentedElement, SymbolAccessibility, Visit return null; } - internal void parse_comments ( Valadoc.Parser docparser ) { + internal void parse_comments ( DocumentationParser docparser ) { this.parse_comment_helper ( docparser ); this.parse_method_comments ( docparser ); diff --git a/src/libvaladoc/apitree/errordomainhandler.vala b/src/libvaladoc/apitree/errordomainhandler.vala index 69711fc44..6a8f39153 100644 --- a/src/libvaladoc/apitree/errordomainhandler.vala +++ b/src/libvaladoc/apitree/errordomainhandler.vala @@ -90,7 +90,7 @@ public interface Valadoc.ErrorDomainHandler : Basic { } } - protected void parse_errordomain_comments ( Valadoc.Parser docparser ) { + protected void parse_errordomain_comments ( DocumentationParser docparser ) { foreach ( ErrorDomain errdom in this.errdoms ) { errdom.parse_comments ( docparser ); } diff --git a/src/libvaladoc/apitree/field.vala b/src/libvaladoc/apitree/field.vala index 36b72a511..80f51f420 100644 --- a/src/libvaladoc/apitree/field.vala +++ b/src/libvaladoc/apitree/field.vala @@ -70,7 +70,7 @@ public class Valadoc.Field : DocumentedElement, SymbolAccessibility, ReturnTypeH ((ReturnTypeHandler)this).set_return_type_references ( ); } - internal void parse_comment ( Valadoc.Parser docparser ) { + internal void parse_comment ( DocumentationParser docparser ) { this.parse_comment_helper ( docparser ); } diff --git a/src/libvaladoc/apitree/fieldhandler.vala b/src/libvaladoc/apitree/fieldhandler.vala index d5e3d3af7..5474af72e 100644 --- a/src/libvaladoc/apitree/fieldhandler.vala +++ b/src/libvaladoc/apitree/fieldhandler.vala @@ -90,7 +90,7 @@ public interface Valadoc.FieldHandler : Basic { } } - internal void parse_field_comments ( Valadoc.Parser docparser ) { + internal void parse_field_comments ( DocumentationParser docparser ) { foreach ( Field field in this.fields ) { field.parse_comment ( docparser ); } diff --git a/src/libvaladoc/apitree/interface.vala b/src/libvaladoc/apitree/interface.vala index b0a4b2221..6f0a53227 100644 --- a/src/libvaladoc/apitree/interface.vala +++ b/src/libvaladoc/apitree/interface.vala @@ -246,7 +246,7 @@ public class Valadoc.Interface : DocumentedElement, SymbolAccessibility, Visitab langlet.write_interface ( this, ptr ); } - internal void parse_comments ( Valadoc.Parser docparser ) { + internal void parse_comments ( DocumentationParser docparser ) { this.parse_comment_helper ( docparser ); this.parse_delegate_comments ( docparser ); this.parse_property_comments ( docparser ); diff --git a/src/libvaladoc/apitree/interfacehandler.vala b/src/libvaladoc/apitree/interfacehandler.vala index 8f45722bb..662441713 100644 --- a/src/libvaladoc/apitree/interfacehandler.vala +++ b/src/libvaladoc/apitree/interfacehandler.vala @@ -82,7 +82,7 @@ public interface Valadoc.InterfaceHandler : Basic { } } - protected void parse_interface_comments ( Valadoc.Parser docparser ) { + protected void parse_interface_comments ( DocumentationParser docparser ) { foreach ( Interface iface in this.interfaces ) { iface.parse_comments ( docparser ); } diff --git a/src/libvaladoc/apitree/method.vala b/src/libvaladoc/apitree/method.vala index 4fd47668a..75ae1cb25 100644 --- a/src/libvaladoc/apitree/method.vala +++ b/src/libvaladoc/apitree/method.vala @@ -85,19 +85,13 @@ public class Valadoc.Method : DocumentedElement, ParameterListHandler, Exception return (m.vmethod == this.vmethod); } - internal void parse_comment (Valadoc.Parser docparser) { + internal void parse_comment (DocumentationParser docparser) { if (this.documentation != null) return ; if (this.vcomment == null) return ; - if (this.base_method != null && docparser.is_inherit_doc (this)) { - this.base_method.parse_comment (docparser); - this.documentation = this.base_method.documentation; - return ; - } - this.parse_comment_helper (docparser); } diff --git a/src/libvaladoc/apitree/methodhandler.vala b/src/libvaladoc/apitree/methodhandler.vala index 0c7b34aa1..fc2c1a704 100644 --- a/src/libvaladoc/apitree/methodhandler.vala +++ b/src/libvaladoc/apitree/methodhandler.vala @@ -64,7 +64,7 @@ public interface Valadoc.MethodHandler : Basic { } } - internal void parse_method_comments ( Valadoc.Parser docparser ) { + internal void parse_method_comments ( DocumentationParser docparser ) { foreach ( Method m in this.methods ) { m.parse_comment ( docparser ); } diff --git a/src/libvaladoc/apitree/namespace.vala b/src/libvaladoc/apitree/namespace.vala index 053322466..101c4ed60 100644 --- a/src/libvaladoc/apitree/namespace.vala +++ b/src/libvaladoc/apitree/namespace.vala @@ -247,7 +247,7 @@ public class Valadoc.Namespace : DocumentedElement, MethodHandler, FieldHandler, this.set_enum_type_references (); } - internal void parse_comments (Valadoc.Parser docparser) { + internal void parse_comments (DocumentationParser docparser) { this.parse_comment_helper (docparser); this.parse_enum_comments (docparser); this.parse_field_comments (docparser); diff --git a/src/libvaladoc/apitree/namespacehandler.vala b/src/libvaladoc/apitree/namespacehandler.vala index 961f24fda..8ff6d9f3d 100644 --- a/src/libvaladoc/apitree/namespacehandler.vala +++ b/src/libvaladoc/apitree/namespacehandler.vala @@ -130,7 +130,7 @@ public interface Valadoc.NamespaceHandler : Basic { } } - internal void parse_namespace_comments ( Valadoc.Parser docparser ) { + internal void parse_namespace_comments ( DocumentationParser docparser ) { foreach ( Namespace ns in this.namespaces ){ ns.parse_comments ( docparser ); } diff --git a/src/libvaladoc/apitree/package.vala b/src/libvaladoc/apitree/package.vala index 26ef9ed83..c54f08dc4 100644 --- a/src/libvaladoc/apitree/package.vala +++ b/src/libvaladoc/apitree/package.vala @@ -149,7 +149,7 @@ public class Valadoc.Package : DocumentedElement, NamespaceHandler { doclet.visit_package ( this ); } - internal void parse_comments ( Valadoc.Parser docparser ) { + internal void parse_comments ( DocumentationParser docparser ) { this.parse_namespace_comments ( docparser ); } diff --git a/src/libvaladoc/apitree/property.vala b/src/libvaladoc/apitree/property.vala index 9861f8644..35551ea79 100644 --- a/src/libvaladoc/apitree/property.vala +++ b/src/libvaladoc/apitree/property.vala @@ -113,19 +113,13 @@ public class Valadoc.Property : DocumentedElement, SymbolAccessibility, ReturnTy this.set_return_type_references ( ); } - public void parse_comment (Valadoc.Parser docparser) { + public void parse_comment (DocumentationParser docparser) { if (this.documentation != null) return ; if (this.vcomment == null) return ; - if (this.base_property != null && docparser.is_inherit_doc (this)) { - this.base_property.parse_comment (docparser); - this.documentation = this.base_property.documentation; - return ; - } - this.parse_comment_helper (docparser); } diff --git a/src/libvaladoc/apitree/propertyhandler.vala b/src/libvaladoc/apitree/propertyhandler.vala index 4d84e48c8..d7872c55e 100644 --- a/src/libvaladoc/apitree/propertyhandler.vala +++ b/src/libvaladoc/apitree/propertyhandler.vala @@ -84,7 +84,7 @@ public interface Valadoc.PropertyHandler : Basic { return lst.read_only_view; } - protected void parse_property_comments ( Valadoc.Parser docparser ) { + protected void parse_property_comments ( DocumentationParser docparser ) { foreach ( Property prop in this.properties ) { prop.parse_comment ( docparser ); } diff --git a/src/libvaladoc/apitree/signal.vala b/src/libvaladoc/apitree/signal.vala index 67df44692..f6c54e86f 100644 --- a/src/libvaladoc/apitree/signal.vala +++ b/src/libvaladoc/apitree/signal.vala @@ -66,7 +66,7 @@ public class Valadoc.Signal : DocumentedElement, ParameterListHandler, SymbolAcc this.set_return_type_references ( ); } - internal void parse_comment (Valadoc.Parser docparser) { + internal void parse_comment (DocumentationParser docparser) { this.parse_comment_helper (docparser); } diff --git a/src/libvaladoc/apitree/signalhandler.vala b/src/libvaladoc/apitree/signalhandler.vala index 573b7acc5..2886551b2 100644 --- a/src/libvaladoc/apitree/signalhandler.vala +++ b/src/libvaladoc/apitree/signalhandler.vala @@ -89,7 +89,7 @@ public interface Valadoc.SignalHandler : Basic { } } - internal void parse_signal_comments ( Valadoc.Parser docparser ) { + internal void parse_signal_comments ( DocumentationParser docparser ) { foreach ( Signal sig in this.signals ) { sig.parse_comment ( docparser ); } diff --git a/src/libvaladoc/apitree/struct.vala b/src/libvaladoc/apitree/struct.vala index 7996ea24b..96712a549 100644 --- a/src/libvaladoc/apitree/struct.vala +++ b/src/libvaladoc/apitree/struct.vala @@ -156,18 +156,12 @@ public class Valadoc.Struct : DocumentedElement, SymbolAccessibility, Visitable, langlet.write_struct (this, ptr); } - internal void parse_comments (Valadoc.Parser docparser) { + internal void parse_comments (DocumentationParser docparser) { if (this.documentation != null) return ; if (this.vcomment != null) { - if ( docparser.is_inherit_doc (this) && this.base_type != null) { - ((Valadoc.Struct)this.base_type).parse_comments (docparser); - this.documentation = this.base_type.documentation; - } - else { - this.parse_comment_helper (docparser); - } + this.parse_comment_helper (docparser); } this.parse_construction_method_comments (docparser); diff --git a/src/libvaladoc/apitree/structhandler.vala b/src/libvaladoc/apitree/structhandler.vala index f42f8b669..6b4e72745 100644 --- a/src/libvaladoc/apitree/structhandler.vala +++ b/src/libvaladoc/apitree/structhandler.vala @@ -83,7 +83,7 @@ public interface Valadoc.StructHandler : Basic { } } - protected void parse_struct_comments ( Valadoc.Parser docparser ) { + protected void parse_struct_comments ( DocumentationParser docparser ) { foreach ( Struct stru in this.structs ) { stru.parse_comments ( docparser ); } diff --git a/src/libvaladoc/content/block.vala b/src/libvaladoc/content/block.vala new file mode 100755 index 000000000..8c23390da --- /dev/null +++ b/src/libvaladoc/content/block.vala @@ -0,0 +1,28 @@ +/* block.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public interface Valadoc.Content.Block : ContentElement { +} diff --git a/src/libvaladoc/content/blockcontent.vala b/src/libvaladoc/content/blockcontent.vala new file mode 100755 index 000000000..138618b99 --- /dev/null +++ b/src/libvaladoc/content/blockcontent.vala @@ -0,0 +1,50 @@ +/* blockcontent.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public abstract class Valadoc.Content.BlockContent : ContentElement { + public Gee.List content { get { return _content; } } + + private Gee.List _content; + + internal BlockContent () { + _content = new ArrayList (); + } + + public override void configure (Settings settings, ResourceLocator locator) { + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + foreach (Block element in _content) { + element.check (api_root, container, reporter); + } + } + + public override void accept_children (ContentVisitor visitor) { + foreach (Block element in _content) { + element.accept (visitor); + } + } +} diff --git a/src/libvaladoc/content/comment.vala b/src/libvaladoc/content/comment.vala new file mode 100755 index 000000000..5bf656db8 --- /dev/null +++ b/src/libvaladoc/content/comment.vala @@ -0,0 +1,73 @@ +/* comment.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.Comment : BlockContent { + public Gee.List taglets { get { return _taglets; } } + + private Gee.List _taglets; + + internal Comment () { + base (); + _taglets = new ArrayList (); + } + + public override void configure (Settings settings, ResourceLocator locator) { + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + base.check (api_root, container, reporter); + + foreach (Taglet element in _taglets) { + element.check (api_root, container, reporter); + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_comment (this); + } + + public override void accept_children (ContentVisitor visitor) { + base.accept_children (visitor); + + foreach (Taglet element in _taglets) { + element.accept (visitor); + } + } + + public Gee.List find_taglets (DocumentedElement? container, Type taglet_type) { + Gee.List selected_taglets = new ArrayList (); + + // TODO inherit stuff if needed + + foreach (Taglet taglet in _taglets) { + if (taglet.get_type () == taglet_type) { + selected_taglets.add (taglet); + } + } + + return selected_taglets; + } +} diff --git a/src/libvaladoc/content/contentelement.vala b/src/libvaladoc/content/contentelement.vala new file mode 100755 index 000000000..0f2d40995 --- /dev/null +++ b/src/libvaladoc/content/contentelement.vala @@ -0,0 +1,38 @@ +/* contentelement.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public abstract class Valadoc.Content.ContentElement : Object { + + public virtual void configure (Settings settings, ResourceLocator locator) { + } + + public abstract void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter); + + public abstract void accept (ContentVisitor visitor); + + public virtual void accept_children (ContentVisitor visitor) { + } +} diff --git a/src/libvaladoc/content/contentfactory.vala b/src/libvaladoc/content/contentfactory.vala new file mode 100755 index 000000000..5ce505c5b --- /dev/null +++ b/src/libvaladoc/content/contentfactory.vala @@ -0,0 +1,109 @@ +/* contentfactory.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.ContentFactory : Object { + + public ContentFactory (Settings settings, ResourceLocator locator, ModuleLoader modules) { + _settings = settings; + _locator = locator; + _modules = modules; + } + + private Settings _settings; + private ResourceLocator _locator; + private ModuleLoader _modules; + + private inline ContentElement configure (ContentElement element) { + element.configure (_settings, _locator); + return element; + } + + public Comment create_comment () { + return (Comment) configure (new Comment ()); + } + + public Embedded create_embedded () { + return (Embedded) configure (new Embedded ()); + } + + public Headline create_headline () { + return (Headline) configure (new Headline ()); + } + + public Highlighted create_highlighted (Highlighted.Style style) { + return (Highlighted) configure (new Highlighted (style)); + } + + public Link create_link () { + return (Link) configure (new Link ()); + } + + public List create_list () { + return (List) configure (new List ()); + } + + public ListItem create_list_item () { + return (ListItem) configure (new ListItem ()); + } + + public Page create_page () { + return (Page) configure (new Page ()); + } + + public Paragraph create_paragraph () { + return (Paragraph) configure (new Paragraph ()); + } + + public SourceCode create_source_code () { + return (SourceCode) configure (new SourceCode ()); + } + + public Table create_table () { + return (Table) configure (new Table ()); + } + + public TableCell create_table_cell () { + return (TableCell) configure (new TableCell ()); + } + + public Taglet create_taglet (string name) { + return _modules.create_taglet (name); + } + + public Text create_text (string? text = null) { + return (Text) configure (new Text (text)); + } + + public ContentElement set_style_attributes (StyleAttributes element, + VerticalAlign? valign, + HorizontalAlign? halign, + string? style) { + element.vertical_align = valign; + element.horizontal_align = halign; + element.style = style; + return element; + } +} diff --git a/src/libvaladoc/content/contentrenderer.vala b/src/libvaladoc/content/contentrenderer.vala new file mode 100755 index 000000000..6f3b84990 --- /dev/null +++ b/src/libvaladoc/content/contentrenderer.vala @@ -0,0 +1,32 @@ +/* contentrenderer.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public abstract class Valadoc.Content.ContentRenderer : ContentVisitor { + + public abstract void render (ContentElement element); + + public abstract void render_children (ContentElement element); +} diff --git a/src/libvaladoc/content/contentvisitor.vala b/src/libvaladoc/content/contentvisitor.vala new file mode 100755 index 000000000..2a476088e --- /dev/null +++ b/src/libvaladoc/content/contentvisitor.vala @@ -0,0 +1,73 @@ +/* contentvisitor.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public abstract class Valadoc.Content.ContentVisitor : Object { + + public virtual void visit_comment (Comment element) { + } + + public virtual void visit_embedded (Embedded element) { + } + + public virtual void visit_headline (Headline element) { + } + + public virtual void visit_highlighted (Highlighted element) { + } + + public virtual void visit_link (Link element) { + } + + public virtual void visit_symbol_link (SymbolLink element) { + } + + public virtual void visit_list (List element) { + } + + public virtual void visit_list_item (ListItem element) { + } + + public virtual void visit_paragraph (Paragraph element) { + } + + public virtual void visit_page (Page element) { + } + + public virtual void visit_source_code (SourceCode element) { + } + + public virtual void visit_table (Table element) { + } + + public virtual void visit_table_cell (TableCell element) { + } + + public virtual void visit_taglet (Taglet element) { + } + + public virtual void visit_text (Text element) { + } +} diff --git a/src/libvaladoc/content/embedded.vala b/src/libvaladoc/content/embedded.vala new file mode 100755 index 000000000..543a77635 --- /dev/null +++ b/src/libvaladoc/content/embedded.vala @@ -0,0 +1,52 @@ +/* embedded.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.Embedded : ContentElement, Inline, StyleAttributes { + public string url { get; set; } + public string caption { get; set; } + + public HorizontalAlign? horizontal_align { get; set; } + public VerticalAlign? vertical_align { get; set; } + public string? style { get; set; } + + private ResourceLocator _locator; + + internal Embedded () { + base (); + } + + public override void configure (Settings settings, ResourceLocator locator) { + _locator = locator; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // Check the image exists if it a local resource + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_embedded (this); + } +} diff --git a/src/libvaladoc/content/headline.vala b/src/libvaladoc/content/headline.vala new file mode 100755 index 000000000..1d11a7414 --- /dev/null +++ b/src/libvaladoc/content/headline.vala @@ -0,0 +1,45 @@ +/* headline.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.Headline : Block, InlineContent { + public int level { get; set; } + + internal Headline () { + base (); + _level = 0; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // TODO report error if level == 0 ? + + // Check inline content + base.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_headline (this); + } +} diff --git a/src/doclets/htmlhelpers/taglets/bold.vala b/src/libvaladoc/content/highlighted.vala similarity index 52% rename from src/doclets/htmlhelpers/taglets/bold.vala rename to src/libvaladoc/content/highlighted.vala index 1aa13a4d2..2842a00fc 100755 --- a/src/doclets/htmlhelpers/taglets/bold.vala +++ b/src/libvaladoc/content/highlighted.vala @@ -1,51 +1,52 @@ -/* +/* highlighted.vala + * * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois */ - using GLib; using Gee; - -public class Valadoc.Html.BoldDocElement : Valadoc.BoldDocElement { - private Gee.ArrayList content; - - public override bool parse ( Gee.ArrayList content ) { - this.content = content; - return true; +public class Valadoc.Content.Highlighted : InlineContent, Inline { + public enum Style { + NONE, + BOLD, + ITALIC, + UNDERLINED, + MONOSPACED, + STROKE } - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; + public Style style { get; set; } - file.printf ( "" ); + internal Highlighted (Style style) { + base (); + _style = style; + } - foreach ( DocElement element in this.content ) { - element.write ( res, _max, _index ); - _index++; - } + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // Check inline content + base.check (api_root, container, reporter); + } - file.printf ( "" ); - return true; + public override void accept (ContentVisitor visitor) { + visitor.visit_highlighted (this); } } - - - diff --git a/src/libvaladoc/content/inline.vala b/src/libvaladoc/content/inline.vala new file mode 100755 index 000000000..d225bef8e --- /dev/null +++ b/src/libvaladoc/content/inline.vala @@ -0,0 +1,28 @@ +/* inline.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public interface Valadoc.Content.Inline : ContentElement { +} diff --git a/src/doclets/htmlhelpers/taglets/italic.vala b/src/libvaladoc/content/inlinecontent.vala similarity index 50% rename from src/doclets/htmlhelpers/taglets/italic.vala rename to src/libvaladoc/content/inlinecontent.vala index a1003183a..147b9e5c8 100755 --- a/src/doclets/htmlhelpers/taglets/italic.vala +++ b/src/libvaladoc/content/inlinecontent.vala @@ -1,50 +1,50 @@ -/* +/* inlinecontent.vala + * * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois */ - using GLib; using Gee; +public abstract class Valadoc.Content.InlineContent : ContentElement { + public Gee.List content { get { return _content; } } -public class Valadoc.Html.ItalicDocElement : Valadoc.ItalicDocElement { - private Gee.ArrayList content; + private Gee.List _content; - public override bool parse ( Gee.ArrayList content ) { - this.content = content; - return true; + construct { + _content = new ArrayList (); } - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; - - file.printf ( "" ); + internal InlineContent () { + } - foreach ( DocElement element in this.content ) { - element.write ( res, _max, _index ); - _index++; + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + foreach (Inline element in _content) { + element.check (api_root, container, reporter); } + } - file.printf ( "" ); - return true; + public override void accept_children (ContentVisitor visitor) { + foreach (Inline element in _content) { + element.accept (visitor); + } } } - - diff --git a/src/libvaladoc/content/inlinetaglet.vala b/src/libvaladoc/content/inlinetaglet.vala new file mode 100755 index 000000000..f474c14c1 --- /dev/null +++ b/src/libvaladoc/content/inlinetaglet.vala @@ -0,0 +1,61 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public abstract class Valadoc.Content.InlineTaglet : ContentElement, Taglet, Inline { + protected Settings settings; + protected ResourceLocator locator; + private ContentElement _content; + + public InlineTaglet () { + base (); + } + + public abstract Rule? get_parser_rule (Rule run_rule); + + public abstract ContentElement produce_content (); + + private ContentElement get_content () { + if (_content == null) { + _content = produce_content (); + } + return _content; + } + + public override void configure (Settings settings, ResourceLocator locator) { + this.settings = settings; + this.locator = locator; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + ContentElement element = get_content (); + element.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + ContentElement element = get_content (); + element.accept (visitor); + } +} diff --git a/src/libvaladoc/content/link.vala b/src/libvaladoc/content/link.vala new file mode 100755 index 000000000..2f9abbbdf --- /dev/null +++ b/src/libvaladoc/content/link.vala @@ -0,0 +1,44 @@ +/* link.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.Link : ContentElement, Inline { + public string url { get; set; } + public string label { get; set; } + + internal Link () { + base (); + } + + public override void configure (Settings settings, ResourceLocator locator) { + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_link (this); + } +} diff --git a/src/doclets/htmlhelpers/taglets/listelement.vala b/src/libvaladoc/content/list.vala similarity index 50% rename from src/doclets/htmlhelpers/taglets/listelement.vala rename to src/libvaladoc/content/list.vala index 8b44ff898..59987bfaf 100755 --- a/src/doclets/htmlhelpers/taglets/listelement.vala +++ b/src/libvaladoc/content/list.vala @@ -1,50 +1,49 @@ -/* +/* list.vala + * * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois */ - using GLib; using Gee; +public class Valadoc.Content.List : ContentElement, Block { + public Gee.List items { get { return _items; } } + + private Gee.List _items; -public class Valadoc.Html.ListEntryDocElement : Valadoc.ListEntryDocElement { - private Gee.ArrayList content; - - public override bool parse ( ListType type, long lvl, Gee.ArrayList content ) { - this.content = content; - return true; + internal List () { + base (); + _items = new ArrayList (); } - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; - - file.printf ( "\t
  • " ); + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // Check the list consistency in terms of successive item levels ? - foreach ( DocElement element in this.content ) { - element.write ( res, _max, _index ); - _index++; + // Check individual list items + foreach (ListItem element in _items) { + element.check (api_root, container, reporter); } + } - file.printf ( "
  • \n" ); - return true; + public override void accept (ContentVisitor visitor) { + visitor.visit_list (this); } } - - diff --git a/src/libvaladoc/content/listitem.vala b/src/libvaladoc/content/listitem.vala new file mode 100755 index 000000000..9b11a4bdd --- /dev/null +++ b/src/libvaladoc/content/listitem.vala @@ -0,0 +1,57 @@ +/* listitem.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.ListItem : InlineContent { + public enum Bullet { + NONE, + UNORDERED, + ORDERED, + ORDERED_LATIN, + ORDERED_CAPITAL, + ORDERED_NUMBER, + ORDERED_LOWER_CASE + } + + public Bullet bullet { get; set; } + public int level { get; set; } + + internal ListItem () { + base (); + _bullet = Bullet.UNORDERED; + _level = 0; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // TODO report error if level == 0 ? + + // Check inline content + base.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_list_item (this); + } +} diff --git a/src/doclets/htmlhelpers/taglets/headline.vala b/src/libvaladoc/content/page.vala similarity index 61% rename from src/doclets/htmlhelpers/taglets/headline.vala rename to src/libvaladoc/content/page.vala index 117d52246..2580bf402 100755 --- a/src/doclets/htmlhelpers/taglets/headline.vala +++ b/src/libvaladoc/content/page.vala @@ -1,42 +1,35 @@ -/* +/* page.vala + * * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois */ - using GLib; using Gee; - -public class Valadoc.Html.HeadlineDocElement : Valadoc.HeadlineDocElement { - private string title; - private int lvl; - - public override bool parse (string title, int lvl) { - this.title = title; - this.lvl = lvl; - return true; +public class Valadoc.Content.Page : BlockContent { + internal Page () { + base (); } - public override bool write (void* res, int max, int index) { - weak GLib.FileStream file = (GLib.FileStream)res; - file.printf ("\n\n%s\n", this.lvl, this.title, this.lvl); - return true; + public override void accept (ContentVisitor visitor) { + visitor.visit_page (this); } } - - diff --git a/src/libvaladoc/content/paragraph.vala b/src/libvaladoc/content/paragraph.vala new file mode 100755 index 000000000..138c4c330 --- /dev/null +++ b/src/libvaladoc/content/paragraph.vala @@ -0,0 +1,44 @@ +/* paragraph.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.Paragraph : InlineContent, Block, StyleAttributes { + public HorizontalAlign? horizontal_align { get; set; } + public VerticalAlign? vertical_align { get; set; } + public string? style { get; set; } + + internal Paragraph () { + base (); + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // Check inline content + base.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_paragraph (this); + } +} diff --git a/src/libvaladoc/content/resourcelocator.vala b/src/libvaladoc/content/resourcelocator.vala new file mode 100755 index 000000000..b188cb1ec --- /dev/null +++ b/src/libvaladoc/content/resourcelocator.vala @@ -0,0 +1,29 @@ +/* resourcelocator.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public interface Valadoc.ResourceLocator : Object { + public abstract string resolve (string path); +} diff --git a/src/libvaladoc/content/sourcecode.vala b/src/libvaladoc/content/sourcecode.vala new file mode 100755 index 000000000..4be3aa215 --- /dev/null +++ b/src/libvaladoc/content/sourcecode.vala @@ -0,0 +1,48 @@ +/* sourcecode.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.SourceCode : ContentElement, Block { + public enum Language { + GENIE, + VALA, + C + } + + public string code { get; set; } + public Language language { get; set; } + + internal SourceCode () { + base (); + _language = Language.VALA; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_source_code (this); + } +} diff --git a/src/libvaladoc/content/styleattributes.vala b/src/libvaladoc/content/styleattributes.vala new file mode 100755 index 000000000..09283b9f0 --- /dev/null +++ b/src/libvaladoc/content/styleattributes.vala @@ -0,0 +1,43 @@ +/* styleattributes.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public enum Valadoc.Content.HorizontalAlign { + LEFT, + RIGHT, + CENTER +} + +public enum Valadoc.Content.VerticalAlign { + TOP, + MIDDLE, + BOTTOM +} + +public interface Valadoc.Content.StyleAttributes : ContentElement { + public abstract HorizontalAlign? horizontal_align { get; set; } + public abstract VerticalAlign? vertical_align { get; set; } + public abstract string? style { get; set; } +} diff --git a/src/libvaladoc/content/symbollink.vala b/src/libvaladoc/content/symbollink.vala new file mode 100755 index 000000000..e5ab03403 --- /dev/null +++ b/src/libvaladoc/content/symbollink.vala @@ -0,0 +1,46 @@ +/* link.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.SymbolLink : ContentElement, Inline { + public DocumentedElement symbol { get; set; } + public string label { get; set; } + + internal SymbolLink (DocumentedElement? symbol = null, string? label = null) { + base (); + _symbol = symbol; + _label = label; + } + + public override void configure (Settings settings, ResourceLocator locator) { + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_symbol_link (this); + } +} diff --git a/src/libvaladoc/content/table.vala b/src/libvaladoc/content/table.vala new file mode 100755 index 000000000..a5187d22b --- /dev/null +++ b/src/libvaladoc/content/table.vala @@ -0,0 +1,51 @@ +/* table.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.Table : ContentElement, Block { + public Gee.List> cells { get { return _cells; } } + + private Gee.List> _cells; + + internal Table () { + base (); + _cells = new ArrayList> (); + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // Check the table consistency in term of row/column number + + // Check individual cells + foreach (var row in _cells) { + foreach (var cell in row) { + cell.check (api_root, container, reporter); + } + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_table (this); + } +} diff --git a/src/libvaladoc/content/tablecell.vala b/src/libvaladoc/content/tablecell.vala new file mode 100755 index 000000000..d816d342a --- /dev/null +++ b/src/libvaladoc/content/tablecell.vala @@ -0,0 +1,48 @@ +/* tablecell.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public class Valadoc.Content.TableCell : InlineContent, StyleAttributes { + public HorizontalAlign? horizontal_align { get; set; } + public VerticalAlign? vertical_align { get; set; } + public string? style { get; set; } + public int colspan { get; set; } + public int rowspan { get; set; } + + internal TableCell () { + base (); + _colspan = 1; + _rowspan = 1; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // Check inline content + base.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_table_cell (this); + } +} diff --git a/src/libvaladoc/content/taglet.vala b/src/libvaladoc/content/taglet.vala new file mode 100755 index 000000000..098d0f020 --- /dev/null +++ b/src/libvaladoc/content/taglet.vala @@ -0,0 +1,30 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; + +public interface Valadoc.Content.Taglet : ContentElement { + + public abstract Rule? get_parser_rule (Rule run_rule); +} diff --git a/src/doclets/htmlhelpers/taglets/paragraph.vala b/src/libvaladoc/content/text.vala similarity index 55% rename from src/doclets/htmlhelpers/taglets/paragraph.vala rename to src/libvaladoc/content/text.vala index 42981a38b..c749b1a87 100755 --- a/src/doclets/htmlhelpers/taglets/paragraph.vala +++ b/src/libvaladoc/content/text.vala @@ -1,50 +1,46 @@ -/* +/* text.vala + * * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois */ - using GLib; using Gee; +public class Valadoc.Content.Text : ContentElement, Inline { + public string content { get; set; } -public class Valadoc.Html.ParagraphDocElement : Valadoc.ParagraphDocElement { - private ArrayList content; - - public override bool parse (ArrayList content) { - this.content = content; - return true; + construct { + _content = ""; } - public override bool write (void* res, int max, int index) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; - - file.printf ("

    "); - - foreach (DocElement element in this.content) { - element.write (res, _max, _index); - _index++; + internal Text (string? text = null) { + if (text != null) { + _content = text; } - - file.printf ("

    "); - return true; } -} + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + } + public override void accept (ContentVisitor visitor) { + visitor.visit_text (this); + } +} diff --git a/src/libvaladoc/documentation/doctree.vala b/src/libvaladoc/documentation/doctree.vala deleted file mode 100755 index 23c889875..000000000 --- a/src/libvaladoc/documentation/doctree.vala +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -using GLib; -using Gee; - - - -public enum Valadoc.TextVerticalPosition { - TOP, - MIDDLE, - BOTTOM -} - -public enum Valadoc.TextPosition { - LEFT, - RIGHT, - CENTER -} - -public enum Valadoc.ImageDocElementPosition { - NEUTRAL, - MIDDLE, - RIGHT, - LEFT -} - -public enum Valadoc.Language { - GENIE, - VALA, - C -} - -public enum Valadoc.ListType { - UNSORTED, - SORTED -} - - -public interface Valadoc.Documentation : Object { - public abstract string? get_filename (); -} - -public abstract class Valadoc.DocElement : Object { - public abstract bool write (void* res, int max, int index); -} - -public abstract class Valadoc.Taglet : DocElement { -} - -public abstract class Valadoc.InlineTaglet : Taglet { - public abstract bool parse (Settings settings, Tree tree, Documentation self, string content, ref ErrorLevel errlvl, out string? errmsg); - public abstract string to_string (); -} - -public abstract class Valadoc.CodeConstantDocElement : Valadoc.DocElement { - public abstract bool parse (string constant); -} - -public abstract class Valadoc.MainTaglet : Taglet { - // deprecated - protected string? get_data_type (DocumentedElement me) { - if (me is Valadoc.Class) - return "class"; - if (me is Valadoc.Delegate) - return "delegate"; - if (me is Valadoc.Interface) - return "interface"; - if (me is Valadoc.Method) - return "method"; - if (me is Valadoc.Property) - return "property"; - if (me is Valadoc.Signal) - return "signal"; - if (me is Valadoc.Enum) - return "enum"; - if (me is Valadoc.EnumValue) - return "enum-value"; - if (me is Valadoc.ErrorDomain) - return "errordomain"; - if (me is Valadoc.ErrorCode) - return "error-code"; - if (me is Valadoc.Field) - return "field"; - if (me is Valadoc.Constant) - return "constant"; - if (me is Valadoc.Namespace) - return "namespace"; - - return null; - } - - public virtual int order { get { return 0; } } - public abstract bool parse (Settings settings, Tree tree, DocumentedElement me, Gee.Collection content, ref ErrorLevel errlvl, out string errmsg); - public abstract bool write_block_start (void* res); - public abstract bool write_block_end (void* res); -} - - - -public abstract class Valadoc.StringTaglet : Taglet { - // deprecated - public string content { - protected set; get; - } - - public abstract bool parse (string content); -} - -public abstract class Valadoc.ParagraphDocElement : DocElement { - public abstract bool parse (ArrayList paragraph); -} - -public abstract class Valadoc.HeadlineDocElement : DocElement { - public abstract bool parse (string title, int lvl); -} - -public abstract class Valadoc.ImageDocElement : DocElement { - public abstract bool parse (Settings settings, Documentation pos, owned string path, owned string alt); -} - -public abstract class Valadoc.LinkDocElement : DocElement { - public abstract bool parse (Settings settings, Tree tree, Documentation pos, owned string link, owned string desc); -} - -public abstract class Valadoc.SourceCodeDocElement : DocElement { - public abstract bool parse (string src, Language lang); -} - -public abstract class Valadoc.ListEntryDocElement : DocElement { - public abstract bool parse (ListType type, long lvl, Gee.ArrayList content); -} - -public abstract class Valadoc.ListDocElement : DocElement { - public abstract bool parse (ListType type, Gee.ArrayList entries); -} - -public abstract class Valadoc.NotificationDocElement : DocElement { - public abstract bool parse (Gee.ArrayList content); -} - - -public abstract class Valadoc.HighlightedDocElement : DocElement { - public abstract bool parse (Gee.ArrayList content); -} - -public abstract class Valadoc.ItalicDocElement : HighlightedDocElement { -} - -public abstract class Valadoc.BoldDocElement : HighlightedDocElement { -} - -public abstract class Valadoc.UnderlinedDocElement : HighlightedDocElement { -} - - - -public abstract class Valadoc.ContentPositionDocElement : DocElement { - public abstract bool parse (Gee.ArrayList content); -} - -public abstract class Valadoc.CenterDocElement : ContentPositionDocElement { -} - -public abstract class Valadoc.RightAlignedDocElement : ContentPositionDocElement { -} - -public abstract class Valadoc.TableCellDocElement : DocElement { - public abstract void parse (TextPosition pos, TextVerticalPosition hpos, int size, int dsize, Gee.ArrayList content); -} - -public abstract class Valadoc.TableDocElement : DocElement { - public abstract void parse (Gee.ArrayList> cells); -} - - - - -public class Valadoc.DocumentationTree : Object { - private Gee.ArrayList description = new Gee.ArrayList (); - private Gee.ArrayList brief = new Gee.ArrayList (); - private Gee.HashMap > taglets - = new Gee.HashMap > (); - - public void add_taglet (MainTaglet taglet) { - if ( this.taglets.contains (taglet.get_type())) { - ArrayList lst = this.taglets.get(taglet.get_type()); - lst.add(taglet); - } - else { - ArrayList lst = new ArrayList (); - this.taglets.set(taglet.get_type(), lst); - lst.add(taglet); - } - } - - public void add_taglets (Collection taglets) { - foreach (MainTaglet tag in taglets) { - this.add_taglet(tag); - } - } - - public Gee.Collection get_brief ( ) { - return this.brief == null ? Collection.empty () : this.brief.read_only_view; - } - - public void add_brief (Gee.ArrayList content) { - this.brief = content; - } - - public Gee.Collection get_description () { - return this.description == null ? Collection.empty () : this.description.read_only_view; - } - - public void add_description (Gee.ArrayList content) { - this.description = content; - } - - private static Gee.ArrayList< Gee.ArrayList > sort_tag_collection (Gee.Collection< Gee.ArrayList > lst) { - Gee.ArrayList< Gee.ArrayList > slst - = new Gee.ArrayList< Gee.ArrayList > (); - - foreach (Gee.ArrayList entry in lst) { - slst.add (entry); - } - - // - int count = slst.size; - if (count <= 0) - return slst; - - for (int i = 0; i < count; i++) { - for (int j = count-1; j>i; j--) { - if (slst.get(j).get(0).order < slst.get(j-1).get(0).order) { - Gee.ArrayList tmp1 = slst.get(j-1); - Gee.ArrayList tmp2 = slst.get(j); - - slst.remove_at (j); - slst.insert (j, tmp1); - slst.remove_at (j-1); - slst.insert (j-1, tmp2); - } - } - } - // - return slst; - } - - public bool write_brief (void* res) { - if (this.brief == null) - return true; - - int _max = this.brief.size; - int _index = 0; - - foreach (DocElement element in this.brief) { - element.write (res, _max, _index); - _index++; - } - return true; - } - - public bool write_content (void* res) { - if (this.description == null) - return true; - - int max = this.description.size; - int i = 0; - bool tmp; - - foreach (DocElement tag in this.description) { - tmp = tag.write (res, max, i); - if (tmp == false) - return false; - - i++; - } - - Gee.Collection< Gee.ArrayList > lst = this.taglets.values; - Gee.ArrayList< Gee.ArrayList > alst = sort_tag_collection ( lst ); - - foreach (Gee.ArrayList tags in alst) { - MainTaglet ftag = tags.get (0); - max = tags.size; - i = 0; - - tmp = ftag.write_block_start (res); - if (tmp == false) - return false; - - foreach (MainTaglet tag in tags) { - tmp = tag.write (res, max, i); - if ( tmp == false ) - return false; - - i++; - } - - tmp = ftag.write_block_end (res); - if (tmp == false) - return false; - } - return true; - } -} - diff --git a/src/doclets/htmlhelpers/taglets/constant.vala b/src/libvaladoc/documentation/documentation.vala similarity index 65% rename from src/doclets/htmlhelpers/taglets/constant.vala rename to src/libvaladoc/documentation/documentation.vala index 85ba9d666..7d36140ce 100755 --- a/src/doclets/htmlhelpers/taglets/constant.vala +++ b/src/libvaladoc/documentation/documentation.vala @@ -17,23 +17,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - using GLib; using Gee; - -public class Valadoc.Html.CodeConstantDocElement : Valadoc.CodeConstantDocElement { - private string constant; - - public override bool parse (string constant) { - this.constant = constant; - return true; - } - - public override bool write (void* res, int max, int index) { - weak GLib.FileStream file = (GLib.FileStream)res; - file.printf ("%s", css_content_literal, this.constant); - return true; - } +public interface Valadoc.Documentation : Object { + public abstract string? get_filename (); } - diff --git a/src/libvaladoc/documentation/errorreporter.vala b/src/libvaladoc/documentation/errorreporter.vala index 7c0245846..82f76cd6b 100755 --- a/src/libvaladoc/documentation/errorreporter.vala +++ b/src/libvaladoc/documentation/errorreporter.vala @@ -63,8 +63,17 @@ public class Valadoc.ErrorReporter : Object { private inline void msg ( ErrorType type, string file, long line, long startpos, long endpos, string errline, string msg ) { this.stream.printf ( "%s:%lu.%lu-%lu.%lu: %s: %s\n", file, line, startpos, line, endpos, (type == ErrorType.ERROR)? "error" : "warning", msg ); if (startpos <= endpos) { - this.stream.printf ( "\t%s\n", errline ); - this.stream.printf ( "\t%s%s\n", string.nfill ((uint)startpos, ' '), string.nfill( (uint)(endpos-startpos), '^' ) ); + this.stream.printf ( "%s\n", errline ); + for (int i = 0; i < errline.length; i++) { + if (errline[i] == '\t') { + this.stream.printf ("\t"); + } else if (i >= startpos - 1 && i < endpos - 1) { + this.stream.printf ("^"); + } else { + this.stream.printf (" "); + } + } + this.stream.printf ("\n"); } } diff --git a/src/libvaladoc/documentation/moduleloader.vala b/src/libvaladoc/documentation/moduleloader.vala index ff96f90a6..891fbdbf6 100755 --- a/src/libvaladoc/documentation/moduleloader.vala +++ b/src/libvaladoc/documentation/moduleloader.vala @@ -29,24 +29,7 @@ public static delegate void Valadoc.TagletRegisterFunction (ModuleLoader loader public class Valadoc.ModuleLoader : Object { public Doclet doclet; - public Gee.HashMap taglets; - public GLib.Type bold; - public GLib.Type center; - public GLib.Type headline; - public GLib.Type image; - public GLib.Type italic; - public GLib.Type link; - public GLib.Type list; - public GLib.Type list_element; - public GLib.Type notification; - public GLib.Type right; - public GLib.Type source; - public GLib.Type source_inline; - public GLib.Type @string; - public GLib.Type table; - public GLib.Type table_cell; - public GLib.Type underline; - public GLib.Type paragraph; + public Gee.HashMap taglets = new Gee.HashMap (GLib.str_hash, GLib.str_equal); private Module docletmodule; private Type doclettype; @@ -56,8 +39,11 @@ public class Valadoc.ModuleLoader : Object { if ( tmp == false ) { return false; } + return true; + } - return this.load_taglets ( path ); + public Content.Taglet create_taglet (string keyword) { + return (Content.Taglet) GLib.Object.new (taglets.get (keyword)); } private bool load_doclet ( string path ) { @@ -78,48 +64,4 @@ public class Valadoc.ModuleLoader : Object { this.doclet = (Doclet)GLib.Object.new (doclettype); return true; } - - private bool load_taglets (string fulldirpath) { - try { - taglets = new Gee.HashMap (GLib.str_hash, GLib.str_equal); - Gee.ArrayList modules = new Gee.ArrayList ( ); - - string pluginpath = build_filename(fulldirpath, "taglets"); - size_t modulesuffixlen = Module.SUFFIX.size() + 1; - - void* function; - - GLib.Dir dir = GLib.Dir.open (pluginpath); - - taglets.set ("toto", typeof (Type)); - taglets.unset ("toto"); - - for (weak string entry = dir.read_name(); entry != null ; entry = dir.read_name()) { - if (!entry.has_suffix("." + Module.SUFFIX)) - continue; - - string tagletpath = build_filename (pluginpath, entry); - Module* module = Module.open (tagletpath, ModuleFlags.BIND_LAZY); - if (module == null) { - taglets = null; - return false; - } - - module->symbol("register_plugin", out function); - Valadoc.TagletRegisterFunction tagletregisterfkt = (Valadoc.TagletRegisterFunction) function; - if (function == null) { - taglets = null; - return false; - } - - tagletregisterfkt (this); - } - return true; - } - catch (FileError err) { - taglets = null; - return false; - } - } } - diff --git a/src/libvaladoc/documentation/wiki.vala b/src/libvaladoc/documentation/wiki.vala index 76d25a50e..f539239f2 100755 --- a/src/libvaladoc/documentation/wiki.vala +++ b/src/libvaladoc/documentation/wiki.vala @@ -19,7 +19,10 @@ public class Valadoc.WikiPage : Object, Documentation { - private Gee.ArrayList content; + public Content.Page documentation { + protected set; + get; + } public string documentation_str { private set; @@ -56,31 +59,8 @@ public class Valadoc.WikiPage : Object, Documentation { } } - public bool parse ( Parser docparser ) { - docparser.parse_wikipage ( this ); - return true; - } - - public void add_content (Gee.ArrayList content) { - this.content = content; - } - - public bool write (void* res) { - if ( this.content == null ) - return true; - - int max = this.content.size; - bool tmp = false; - int i = 0; - - foreach ( DocElement tag in this.content ) { - tmp = tag.write ( res, max, i ); - if ( tmp == false ) - return false; - - i++; - } - + public bool parse (DocumentationParser docparser) { + documentation = docparser.parse_wikipage ( this ); return true; } } @@ -113,7 +93,7 @@ public class Valadoc.WikiPageTree : Object { return null; } - private void create_tree_from_path (Parser docparser, string path, string? nameoffset = null) throws GLib.FileError { + private void create_tree_from_path (DocumentationParser docparser, string path, string? nameoffset = null) throws GLib.FileError { Dir dir = Dir.open (path); for (string? curname = dir.read_name(); curname!=null ; curname = dir.read_name()) { @@ -129,7 +109,7 @@ public class Valadoc.WikiPageTree : Object { } } - public void create_tree ( Parser docparser ) throws GLib.FileError { + public void create_tree ( DocumentationParser docparser ) throws GLib.FileError { try { weak string path = this.settings.wiki_directory; if (path == null) { diff --git a/src/libvaladoc/parser/commentscanner.vala b/src/libvaladoc/parser/commentscanner.vala new file mode 100644 index 000000000..aa74ad785 --- /dev/null +++ b/src/libvaladoc/parser/commentscanner.vala @@ -0,0 +1,69 @@ +/* commentscanner.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +public class Valadoc.CommentScanner : WikiScanner { + + public CommentScanner (Settings settings) { + base (settings); + } + + private bool in_line_start; + private bool past_star; + private int start_column; + + public override void reset () { + base.reset (); + + in_line_start = true; + past_star = false; + start_column = 0; + } + + public override int get_line_start_column () { + return start_column; + } + + protected override void accept (unichar c) throws ParserError { + if (in_line_start) { + start_column++; + if (c == '*') { + past_star = true; + } else if (past_star) { + past_star = false; + if (c == '\n') { + base.accept (c); + in_line_start = true; + start_column = 0; + } else if (c == ' ') { + in_line_start = false; + } + } + } else { + base.accept (c); + if (c == '\n') { + in_line_start = true; + start_column = 0; + } + } + } +} diff --git a/src/libvaladoc/parser/documentationparser.vala b/src/libvaladoc/parser/documentationparser.vala new file mode 100644 index 000000000..f0b70f3c6 --- /dev/null +++ b/src/libvaladoc/parser/documentationparser.vala @@ -0,0 +1,518 @@ +/* documentationparser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; +using Valadoc.Content; + +public class Valadoc.DocumentationParser : Object, ResourceLocator { + + public DocumentationParser (Settings settings, ErrorReporter reporter, Tree tree, ModuleLoader modules) { + _settings = settings; + _reporter = reporter; + _tree = tree; + _modules = modules; + + _factory = new ContentFactory (_settings, this, _modules); + + _wiki_scanner = new WikiScanner (_settings); + _wiki_parser = new Parser (_settings, _wiki_scanner, _reporter); + _wiki_scanner.set_parser (_wiki_parser); + + _comment_scanner = new CommentScanner (_settings); + _comment_parser = new Parser (_settings, _comment_scanner, _reporter); + _comment_scanner.set_parser (_comment_parser); + + init_rules (); + } + + private Settings _settings; + private ErrorReporter _reporter; + private Tree _tree; + private ModuleLoader _modules; + + private ContentFactory _factory; + private WikiScanner _wiki_scanner; + private CommentScanner _comment_scanner; + private Parser _wiki_parser; + private Parser _comment_parser; + + private Parser _parser; + private WikiScanner _scanner; + + public Comment? parse (DocumentedElement element) { + if (element.documentation != null) { + return element.documentation; + } + + var comment = element.vcomment as Vala.Comment; + if (comment == null) { + return null; + } + + weak string content = element.vcomment.content; + var source_ref = comment.source_reference; + try { + Comment doc_comment = parse_comment (content, source_ref.file.filename, source_ref.first_line, source_ref.first_column); + doc_comment.check (_tree, element, _reporter); + return doc_comment; + } catch (ParserError error) { + return null; + } + } + + public Page? parse_wikipage (WikiPage page) { + if (page.documentation != null) { + return page.documentation; + } + + if (page.documentation_str == null) { + return null; + } + + try { + Page documentation = parse_wiki (page.documentation_str, page.get_filename ()); + documentation.check (_tree, null, _reporter); + return documentation; + } catch (ParserError error) { + return null; + } + } + + private Comment parse_comment (string content, string filename, int first_line, int first_column) throws ParserError { + _parser = _comment_parser; + _scanner = _comment_scanner; + _stack.clear (); + _comment_parser.parse (content, filename, first_line, first_column); + return (Comment) pop (); + } + + private Page parse_wiki (string content, string filename) throws ParserError { + _parser = _wiki_parser; + _scanner = _wiki_scanner; + _stack.clear (); + _wiki_parser.parse (content, filename, 0, 0); + return (Page) pop (); + } + + public string resolve (string path) { + return path; + } + + private ArrayList _stack = new ArrayList (); + + private void push (Object element) { + _stack.add (element); + } + + private Object peek () { + assert (_stack.size > 0); + return _stack.get (_stack.size - 1); + } + + private Object pop () { + Object node = peek (); + _stack.remove_at (_stack.size - 1); + return node; + } + + private Rule multiline_run; + + private void init_rules () { + // Inline rules + + StubRule run = new StubRule (); + run.set_name ("Run"); + + TokenType.Action add_text = (token) => { + var text = peek () as Text; + if (text == null) { + push (text = _factory.create_text ()); + } + text.content += token.to_string (); + }; + + TokenType word = TokenType.any_word ().action (add_text); + TokenType space = TokenType.SPACE.action (add_text); + + Rule text = + Rule.seq ({ + word, + Rule.option ({ space }), + Rule.option ({ + Rule.many ({ + Rule.one_of ({ + word, + TokenType.STAR.action (add_text), + TokenType.SHARP.action (add_text), + TokenType.LESS_THAN.action (add_text), + TokenType.GREATER_THAN.action (add_text), + TokenType.ALIGN_RIGHT.action (add_text), + TokenType.ALIGN_CENTER.action (add_text) + }), + Rule.option ({ space }) + }) + }) + }) + .set_name ("Text") + .set_start (() => { push (_factory.create_text ()); }); + + Rule run_with_spaces = + Rule.seq ({ + Rule.many ({ + Rule.option ({ + Rule.many ({ TokenType.SPACE }) + }), + run + }) + }) + .set_name ("RunWithSpaces"); + + multiline_run = Rule.many ({ + run_with_spaces, + TokenType.EOL.action (() => { ((InlineContent) peek ()).content.add (_factory.create_text (" ")); }) + }) + .set_name ("MultiLineRun"); + + Rule inline_taglet = + Rule.seq ({ + TokenType.OPEN_BRACE, + TokenType.AROBASE, + TokenType.any_word ().action ((token) => { + var taglet = _factory.create_taglet (token.to_string ()); + if (!(taglet is Inline)) { + _parser.error ("Invalid taglet in this context: %s".printf (token.to_string ())); + } + push (taglet); + Rule? taglet_rule = taglet.get_parser_rule (multiline_run); + if (taglet_rule != null) { + _parser.push_rule (Rule.seq ({ TokenType.SPACE, taglet_rule })); + } + }), + TokenType.CLOSED_BRACE + }) + .set_name ("InlineTaglet"); + + Rule bold = + Rule.seq ({ TokenType.SINGLE_QUOTE_2, run, TokenType.SINGLE_QUOTE_2 }) + .set_name ("Bold") + .set_start (() => { push (_factory.create_highlighted (Highlighted.Style.BOLD)); }); + Rule italic = + Rule.seq ({ TokenType.SLASH_2, run, TokenType.SLASH_2 }) + .set_name ("Italic") + .set_start (() => { push (_factory.create_highlighted (Highlighted.Style.ITALIC)); }); + Rule underlined = + Rule.seq ({ TokenType.UNDERSCORE_2, run, TokenType.UNDERSCORE_2 }) + .set_name ("Underlined") + .set_start (() => { push (_factory.create_highlighted (Highlighted.Style.UNDERLINED)); }); + Rule monospace = + Rule.seq ({ TokenType.BACK_QUOTE, run, TokenType.BACK_QUOTE }) + .set_name ("Monospace") + .set_start (() => { push (_factory.create_highlighted (Highlighted.Style.MONOSPACED)); }); + + Rule embedded = + Rule.seq ({ + TokenType.DOUBLE_OPEN_BRACE.action (() => { _scanner.set_url_escape_mode (true); }), + TokenType.any_word (), + Rule.option ({ + TokenType.PIPE.action (() => { _scanner.set_url_escape_mode (false); }), + run + }), + TokenType.DOUBLE_CLOSED_BRACE.action (() => { _scanner.set_url_escape_mode (false); }) + }) + .set_name ("Embedded") + .set_start (() => { push (_factory.create_embedded ()); }); + Rule link = + Rule.seq ({ + TokenType.DOUBLE_OPEN_BRACKET.action (() => { _scanner.set_url_escape_mode (true); }), + TokenType.any_word (), + Rule.option ({ + TokenType.PIPE.action (() => { _scanner.set_url_escape_mode (false); }), + run + }), + TokenType.DOUBLE_CLOSED_BRACKET.action (() => { _scanner.set_url_escape_mode (false); }) + }) + .set_name ("Link") + .set_start (() => { push (_factory.create_link ()); }); + + run.set_rule ( + Rule.many ({ + Rule.one_of ({ + text, inline_taglet, bold, italic, underlined, monospace, embedded, link + }) + .set_reduce (() => { ((InlineContent) peek ()).content.add ((Inline) pop ()); }), + Rule.option ({ space }) + .set_reduce (() => { ((InlineContent) peek ()).content.add ((Inline) pop ()); }) + }) + .set_name ("Run") + ); + + // Block rules + + Rule paragraph = + Rule.seq ({ + Rule.option ({ + Rule.one_of ({ + TokenType.ALIGN_CENTER.action (() => { ((Paragraph) peek ()).horizontal_align = HorizontalAlign.RIGHT; }), + TokenType.ALIGN_RIGHT.action (() => { ((Paragraph) peek ()).horizontal_align = HorizontalAlign.RIGHT; }) + }) + }), + Rule.many ({ + run, + TokenType.EOL.action (() => { ((Paragraph) peek ()).content.add (_factory.create_text (" ")); }) + }) + }) + .set_name ("Paragraph") + .set_start (() => { push (_factory.create_paragraph ()); }) + .set_reduce (() => { ((BlockContent) peek ()).content.add ((Block) pop ()); }); + + Rule source_code = + Rule.seq ({ + TokenType.TRIPLE_OPEN_BRACE.action ((token) => { _scanner.set_code_escape_mode (true); }), + TokenType.any_word ().action ((token) => { ((SourceCode) peek ()).code = token.to_string (); }), + TokenType.TRIPLE_CLOSED_BRACE.action ((token) => { _scanner.set_code_escape_mode (false); }), + TokenType.EOL + }) + .set_name ("SourceCode") + .set_start (() => { push (_factory.create_source_code ()); }) + .set_reduce (() => { ((BlockContent) peek ()).content.add ((Block) pop ()); }); + + Rule list_item = + Rule.seq ({ + Rule.many ({ + TokenType.SPACE.action ((token) => { ((ListItem) peek ()).level++; }) + }), + Rule.one_of ({ + TokenType.STAR.action ((token) => { ((ListItem) peek ()).bullet = ListItem.Bullet.UNORDERED; }), + TokenType.SHARP.action ((token) => { ((ListItem) peek ()).bullet = ListItem.Bullet.ORDERED; }), + TokenType.str (".").action ((token) => { ((ListItem) peek ()).bullet = ListItem.Bullet.NONE; }), + TokenType.str ("I.").action ((token) => { ((ListItem) peek ()).bullet = ListItem.Bullet.ORDERED_LATIN; }), + TokenType.str ("A.").action ((token) => { ((ListItem) peek ()).bullet = ListItem.Bullet.ORDERED_CAPITAL; }), + TokenType.str ("1.").action ((token) => { ((ListItem) peek ()).bullet = ListItem.Bullet.ORDERED_NUMBER; }), + TokenType.str ("a.").action ((token) => { ((ListItem) peek ()).bullet = ListItem.Bullet.ORDERED_LOWER_CASE; }) + }), + run, + TokenType.EOL + }) + .set_name ("ListItem") + .set_start (() => { push (_factory.create_list_item ()); }) + .set_reduce (() => { ((Content.List) peek ()).items.add ((ListItem) pop ()); }); + Rule list = + Rule.seq ({ + Rule.many ({ + list_item + }), + TokenType.EOL + }) + .set_name ("List") + .set_start (() => { push (_factory.create_list ()); }) + .set_reduce (() => { ((BlockContent) peek ()).content.add ((Block) pop ()); }); + + Rule table_cell_attributes = + Rule.seq ({ + TokenType.LESS_THAN, + Rule.option ({ + Rule.one_of ({ + Rule.seq ({ + Rule.option ({ + Rule.one_of ({ + TokenType.ALIGN_RIGHT.action ((token) => { ((TableCell) peek ()).horizontal_align = HorizontalAlign.RIGHT; }), + TokenType.ALIGN_CENTER.action ((token) => { ((TableCell) peek ()).horizontal_align = HorizontalAlign.CENTER; }) + }) + }), + Rule.option ({ + Rule.one_of ({ + TokenType.ALIGN_TOP.action ((token) => { ((TableCell) peek ()).vertical_align = VerticalAlign.TOP; }), + TokenType.ALIGN_BOTTOM.action ((token) => { ((TableCell) peek ()).vertical_align = VerticalAlign.BOTTOM; }) + }) + }) + }), + TokenType.any_word ().action ((token) => { ((TableCell) peek ()).style = token.to_string (); }) + }) + }), + Rule.option ({ + Rule.one_of ({ + Rule.seq ({ + TokenType.PIPE, + TokenType.any_number ().action ((token) => { ((TableCell) peek ()).colspan = token.to_int (); }) + }), + Rule.seq ({ + TokenType.MINUS, + TokenType.any_number ().action ((token) => { ((TableCell) peek ()).rowspan = token.to_int (); }) + }) + }) + }), + TokenType.GREATER_THAN + }) + .set_name ("CellAttributes"); + Rule table_cell = + Rule.seq ({ + Rule.seq ({ + Rule.option ({ + table_cell_attributes + }), + run_with_spaces, + Rule.option ({ + Rule.many ({ TokenType.SPACE }) + }) + }), + TokenType.DOUBLE_PIPE + }) + .set_name ("Cell") + .set_start (() => { push (_factory.create_table_cell ()); }) + .set_reduce (() => { ((ArrayList) peek ()).add ((TableCell) pop ()); }); + Rule table_row = + Rule.seq ({ + TokenType.DOUBLE_PIPE, + Rule.many ({ + table_cell + }), + TokenType.EOL + }) + .set_name ("Row") + .set_start (() => { push (new ArrayList ()); }) + .set_reduce (() => { ((Table) peek ()).cells.add ((ArrayList) pop ()); }); + Rule table = + Rule.seq ({ + Rule.many ({ + table_row + }) + }) + .set_name ("Table") + .set_start (() => { push (_factory.create_table ()); }) + .set_reduce (() => { ((BlockContent) peek ()).content.add ((Block) pop ()); }); + + Rule headline = + Rule.one_of ({ + Rule.seq ({ + TokenType.EQUAL_1.action ((token) => { ((Headline) peek ()).level = 1; }), + run, + TokenType.EQUAL_1, + TokenType.EOL + }), + Rule.seq ({ + TokenType.EQUAL_2.action ((token) => { ((Headline) peek ()).level = 2; }), + run, + TokenType.EQUAL_2, + TokenType.EOL + }), + Rule.seq ({ + TokenType.EQUAL_3.action ((token) => { ((Headline) peek ()).level = 3; }), + run, + TokenType.EQUAL_3, + TokenType.EOL + }), + Rule.seq ({ + TokenType.EQUAL_4.action ((token) => { ((Headline) peek ()).level = 4; }), + run, + TokenType.EQUAL_4, + TokenType.EOL + }), + Rule.seq ({ + TokenType.EQUAL_5.action ((token) => { ((Headline) peek ()).level = 5; }), + run, + TokenType.EQUAL_5, + TokenType.EOL + }) + }) + .set_name ("Headline") + .set_start (() => { push (_factory.create_headline ()); }) + .set_reduce (() => { ((BlockContent) peek ()).content.add ((Block) pop ()); }); + + Rule blocks = + Rule.one_of ({ + source_code, + list, + table, + headline, + paragraph + }) + .set_name ("Blocks"); + + Rule page = + Rule.seq ({ + blocks, + Rule.option ({ + Rule.many ({ + TokenType.EOL, + Rule.option ({ blocks }) + }) + }) + }) + .set_name ("Page") + .set_start (() => { push (_factory.create_page ()); }); + + Rule description = + Rule.seq ({ + blocks, + Rule.option ({ + Rule.many ({ + TokenType.EOL, + Rule.option ({ blocks }) + }) + }) + }) + .set_name ("Description"); + + Rule taglet = + Rule.seq ({ + TokenType.AROBASE, + TokenType.any_word ().action ((token) => { + var taglet = _factory.create_taglet (token.to_string ()); + if (!(taglet is Block)) { + _parser.error ("Invalid taglet in this context", token); + } + push (taglet); + Rule? taglet_rule = taglet.get_parser_rule (multiline_run); + if (taglet_rule != null) { + _parser.push_rule (Rule.seq ({ TokenType.SPACE, taglet_rule })); + } + }), + Rule.option ({ + Rule.many ({ TokenType.EOL }) + }) + }) + .set_name ("Taglet") + .set_reduce (() => { ((Comment) peek ()).taglets.add ((Taglet) pop ()); }); + + Rule comment = + Rule.seq ({ + TokenType.EOL, + description, + Rule.option ({ + Rule.many ({ taglet }) + }) + }) + .set_name ("Comment") + .set_start (() => { push (_factory.create_comment ()); }); + + _comment_parser.set_root_rule (comment); + _wiki_parser.set_root_rule (page); + } + + private void dump_stack () { + message ("Dumping stack"); + foreach (Object object in _stack) { + message ("%s", object.get_type ().name ()); + } + } +} diff --git a/src/libvaladoc/parser/manyrule.vala b/src/libvaladoc/parser/manyrule.vala new file mode 100644 index 000000000..d3d0673d4 --- /dev/null +++ b/src/libvaladoc/parser/manyrule.vala @@ -0,0 +1,108 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +internal class Valadoc.ManyRule : Rule { + + public ManyRule (Object scheme) { + _scheme = scheme; + } + + private Object _scheme; + + private class State : Object { + public bool started = false; + public bool done_one = false; + } + + public override bool is_optional () { + return is_optional_rule (_scheme); + } + + public override bool starts_with_token (Token token) { + if (has_start_token (_scheme, token)) { + return true; + } + return false; + } + + public override bool accept_token (Token token, ParserCallback parser, Rule.Forward forward) throws ParserError { + var state = parser.get_rule_state () as State; + if (state == null) { + state = new State (); + parser.set_rule_state (state); + } + + if (!state.started) { + do_start (parser); + state.started = true; + } + + if (state.done_one && parser.would_parent_accept_token (token)) { + do_reduce (parser); + return false; + } + if (parser.would_parent_reduce_to_rule (token, this)) { + do_reduce (parser); + return false; + } + + bool handled; + if (try_to_apply (_scheme, token, parser, out handled)) { + state.done_one = true; + return handled; + } + if (parser.would_parent_accept_token (token)) { + do_reduce (parser); + return false; + } + + if (_scheme is TokenType) { + parser.error ("expected %s".printf (((TokenType) _scheme).to_pretty_string ()), token); + } else { + parser.error ("unexpected token", token); + } + assert_not_reached (); + } + + public override bool would_accept_token (Token token, Object? state) { + if (has_start_token (_scheme, token)) { + return true; + } + return false; + } + + public override bool would_reduce (Token token, Object? rule_state) { + var state = rule_state as State; + return state.done_one || is_optional_rule (_scheme); + } + + public override string to_string (Object? rule_state) { + var state = rule_state as State; + if (state == null) { + state = new State (); + } + return "%-15s%-15s(started=%s;done_one=%s)".printf (name != null ? name : " ", "[many]", state.started.to_string (), state.done_one.to_string ()); + } +} diff --git a/src/libvaladoc/parser/oneofrule.vala b/src/libvaladoc/parser/oneofrule.vala new file mode 100644 index 000000000..3613e003d --- /dev/null +++ b/src/libvaladoc/parser/oneofrule.vala @@ -0,0 +1,94 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +internal class Valadoc.OneOfRule : Rule { + + public OneOfRule (Object[] scheme) { + _scheme = scheme; + } + + private Object[] _scheme; + + private class State : Object { + public int selected = -1; + } + + public override bool is_optional () { + return false; + } + + public override bool starts_with_token (Token token) { + foreach (Object? scheme_element in _scheme) { + if (has_start_token (scheme_element, token)) { + return true; + } + } + return false; + } + + public override bool accept_token (Token token, ParserCallback parser, Rule.Forward forward) throws ParserError { + var state = parser.get_rule_state () as State; + if (state == null) { + state = new State (); + parser.set_rule_state (state); + } + + if (state.selected == -1) { + do_start (parser); + + bool handled; + for (int i = 0; i < _scheme.length; i++) { + Object? scheme_element = _scheme[i]; + if (try_to_apply (scheme_element, token, parser, out handled)) { + state.selected = i; + return handled; + } + } + } else { + do_reduce (parser); + return false; + } + + parser.error ("unexpected token", token); + assert_not_reached (); + } + + public override bool would_accept_token (Token token, Object? state) { + return false; + } + + public override bool would_reduce (Token token, Object? rule_state) { + var state = rule_state as State; + return state.selected != -1; + } + + public override string to_string (Object? rule_state) { + var state = rule_state as State; + if (state == null) { + state = new State (); + } + return "%-15s%-15s(selected=%d/%d)".printf (name != null ? name : " ", "[one-of]", state.selected, _scheme.length); + } +} diff --git a/src/libvaladoc/parser/optionalrule.vala b/src/libvaladoc/parser/optionalrule.vala new file mode 100644 index 000000000..656cf4f4c --- /dev/null +++ b/src/libvaladoc/parser/optionalrule.vala @@ -0,0 +1,85 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +internal class Valadoc.OptionalRule : Rule { + + public OptionalRule (Object scheme) { + _scheme = scheme; + } + + private Object _scheme; + + private class State : Object { + public bool started = false; + } + + public override bool is_optional () { + return true; + } + + public override bool starts_with_token (Token token) { + return has_start_token (_scheme, token); + } + + public override bool accept_token (Token token, ParserCallback parser, Rule.Forward forward) throws ParserError { + var state = parser.get_rule_state () as State; + if (state == null) { + state = new State (); + parser.set_rule_state (state); + } + + if (!state.started) { + do_start (parser); + state.started = true; + + bool handled; + if (try_to_apply (_scheme, token, parser, out handled)) { + return handled; + } else { + do_reduce (parser); + return false; + } + } else { + do_reduce (parser); + return false; + } + } + + public override bool would_accept_token (Token token, Object? state) { + return false; + } + + public override bool would_reduce (Token token, Object? state) { + return true; + } + + public override string to_string (Object? rule_state) { + var state = rule_state as State; + if (state == null) { + state = new State (); + } + return "%-15s%-15s(started=%s)".printf (name != null ? name : " ", "[option]", state.started.to_string ()); + } +} diff --git a/src/libvaladoc/parser/parser.vala b/src/libvaladoc/parser/parser.vala new file mode 100644 index 000000000..ade9ec17e --- /dev/null +++ b/src/libvaladoc/parser/parser.vala @@ -0,0 +1,286 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +public errordomain Valadoc.ParserError { + INTERNAL_ERROR, + UNEXPECTED_TOKEN +} + +public class Valadoc.Parser : ParserCallback { + + public Parser (Settings settings, Scanner scanner, ErrorReporter reporter) { + _settings = settings; + _scanner = scanner; + _reporter = reporter; + + TokenType.init_token_types (); + } + + private Settings _settings; + private Scanner _scanner; + private ErrorReporter _reporter; + private Rule _root_rule; + + private string _filename; + private int _first_line; + private int _first_column; + private Token _current_token; + + private ArrayList rule_stack = new ArrayList (); + private ArrayList rule_state_stack = new ArrayList (); + + public void set_root_rule (Rule root_rule) { + _root_rule = root_rule; + } + + public void parse (string content, string filename, int first_line, int first_column) throws ParserError { + _filename = filename; + _first_line = first_line; + _first_column = first_column; + + rule_stack.clear (); + rule_state_stack.clear (); + + try { + push_rule (_root_rule); + _scanner.reset (); + _scanner.scan (content); + _scanner.end (); + + if (rule_stack.size != 0) { + error ("Rule stack is not empty!"); + } + } catch (ParserError e) { + #if DEBUG + log_error (e.message); + #endif + // Set an in_error boolean, try to recover + // And only throw the error at the end of parse ? + throw e; + } + } + + public void accept_token (Token token) throws ParserError { + #if HARD_DEBUG + debug ("Incomming token: %s", token.to_pretty_string ()); + #endif + + _current_token = token; + int rule_depth = rule_stack.size; + Rule.Forward forward = Rule.Forward.NONE; + Rule? rule = peek_rule (); + if (rule == null) { + throw new ParserError.INTERNAL_ERROR ("Rule stack is empty!"); + } + while (rule != null) { + if (rule.accept_token (token, this, forward)) { + break; + } + + // Check for invalid recursion + if (rule_depth != rule_stack.size && peek_rule () == rule) { + error ("Parser state error"); + break; + } + rule = peek_rule (); + + // Rule stack size have changed + // Check for propagation + forward = rule_depth > rule_stack.size ? Rule.Forward.CHILD + : Rule.Forward.PARENT; + rule_depth = rule_stack.size; + } + } + + private Rule? peek_rule (int offset = -1) { + assert (offset < 0); + if (rule_stack.size + offset < 0) { + return null; + } + return rule_stack.get (rule_stack.size + offset); + } + + private Rule pop_rule () { + int last_index = rule_stack.size - 1; + Rule rule = rule_stack.get (last_index); + rule_stack.remove_at (last_index); + rule_state_stack.remove_at (last_index); + return rule; + } + + public void push_rule (Rule rule) { + rule_stack.add (rule); + rule_state_stack.add (null); + + #if HARD_DEBUG + debug ("Pushed at %2d: %s", rule_stack.size - 1, rule.to_string (null)); + #endif + } + + private Object? peek_state (int offset = -1) { + assert (offset < 0); + if (rule_state_stack.size + offset < 0) { + return null; + } + return rule_state_stack.get (rule_state_stack.size + offset); + } + + public Object? get_rule_state () { + return peek_state (); + } + + public void set_rule_state (Object state) { + int last_index = rule_stack.size - 1; + rule_state_stack.set (last_index, state); + } + + public void reduce () { + pop_rule (); + + #if HARD_DEBUG + Rule? parent_rule = peek_rule (); + if (parent_rule != null) { + debug ("Reduced to %2d: %s", rule_stack.size - 1, parent_rule.to_string (peek_state ())); + } + #endif + } + + public bool would_parent_accept_token (Token token) { + int offset = -2; + Rule? parent_rule = peek_rule (offset); + Object? state = peek_state (offset); + while (parent_rule != null) { + #if VERY_HARD_DEBUG + debug ("WouldAccept - Offset %d; Index %d: %s", offset, rule_stack.size + offset, parent_rule.to_string (state)); + #endif + if (parent_rule.would_accept_token (token, state)) { + #if VERY_HARD_DEBUG + debug ("WouldAccept - Yes"); + #endif + return true; + } + if (!parent_rule.would_reduce (token, state)) { + #if VERY_HARD_DEBUG + debug ("WouldAccept - No"); + #endif + return false; + } + offset--; + parent_rule = peek_rule (offset); + state = peek_state (offset); + } + #if VERY_HARD_DEBUG + debug ("WouldAccept - No"); + #endif + return false; + } + + public bool would_parent_reduce_to_rule (Token token, Rule rule) { + int offset = -2; + Rule? parent_rule = peek_rule (offset); + Object? state = peek_state (offset); + while (parent_rule != null) { + #if VERY_HARD_DEBUG + debug ("WouldReduce - Offset %d; Index %d: %s", offset, rule_stack.size + offset, parent_rule.to_string (state)); + #endif + if (!parent_rule.would_reduce (token, state)) { + break; + } + offset--; + parent_rule = peek_rule (offset); + state = peek_state (offset); + } + if ((parent_rule != null && parent_rule.would_accept_token (token, state)) + || (parent_rule == null && TokenType.EOF.matches (token))) { + #if VERY_HARD_DEBUG + debug ("WouldReduce - Yes"); + #endif + return true; + } + #if VERY_HARD_DEBUG + debug ("WouldReduce - No"); + #endif + return false; + } + + public void warning (string message, Token? token = null) { + string error_message = message + (token != null ? ": " + token.to_pretty_string () : ""); + _reporter.warning (_filename, + get_line (token), + get_start_column (token), + get_end_column (token), + _scanner.get_line_content (), + error_message); + } + + public void error (string message, Token? token = null) throws ParserError { + string error_message = message + (token != null ? ": " + token.to_pretty_string () : ""); + _reporter.error (_filename, get_line (token), + get_start_column (token), + get_end_column (token), + _scanner.get_line_content (), + error_message); + throw new ParserError.UNEXPECTED_TOKEN (error_message); + } + + private int get_line (Token? token) { + if (token == null) { + token = _current_token; + } + return token.begin.line + _first_line; + } + + private int get_start_column (Token? token) { + if (token == null) { + token = _current_token; + } + if (token.begin.line == 0) { + return token.begin.column + _first_column + 1; + } else { + return token.begin.column + 1; + } + } + + private int get_end_column (Token? token) { + if (token == null) { + token = _current_token; + } + if (token.end.line == 0) { + return token.end.column + _first_column + 1; + } else { + return token.end.column + 1; + } + } + +#if DEBUG + private void log_error (string message) { + stderr.printf ("An error occured while parsing: %s\n", message); + stderr.printf ("\nDumping rule stack:\n"); + for (int i = 0; i < rule_stack.size; i++) { + stderr.printf ("\t%2d: %s\n", i, rule_stack[i].to_string (rule_state_stack[i])); + } + } +#endif +} diff --git a/src/doclets/htmlhelpers/taglets/center.vala b/src/libvaladoc/parser/parsercallback.vala old mode 100755 new mode 100644 similarity index 52% rename from src/doclets/htmlhelpers/taglets/center.vala rename to src/libvaladoc/parser/parsercallback.vala index 36204c425..6747262c6 --- a/src/doclets/htmlhelpers/taglets/center.vala +++ b/src/libvaladoc/parser/parsercallback.vala @@ -1,50 +1,38 @@ -/* +/* parser.vala + * * Valadoc - a documentation tool for vala. - * Copyright (C) 2008 Florian Brosch - * + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois */ - -using GLib; using Gee; +public interface Valadoc.ParserCallback { + public abstract Object? get_rule_state (); + public abstract void set_rule_state (Object state); -public class Valadoc.Html.CenterDocElement : Valadoc.CenterDocElement { - private Gee.ArrayList content; - - public override bool parse ( Gee.ArrayList content ) { - this.content = content; - return true; - } - - public override bool write ( void* res, int max, int index ) { - weak GLib.FileStream file = (GLib.FileStream)res; - int _max = this.content.size; - int _index = 0; + public abstract void push_rule (Rule rule); + public abstract void reduce (); - file.printf ( "
    " ); + public abstract bool would_parent_accept_token (Token token); + public abstract bool would_parent_reduce_to_rule (Token token, Rule rule); - foreach ( DocElement element in this.content ) { - element.write ( res, _max, _index ); - _index++; - } - - file.printf ( "
    " ); - return true; - } + public abstract void warning (string message, Token? token = null); + public abstract void error (string message, Token? token = null) throws ParserError; } - - diff --git a/src/libvaladoc/parser/rule.vala b/src/libvaladoc/parser/rule.vala new file mode 100644 index 000000000..980c2d1f2 --- /dev/null +++ b/src/libvaladoc/parser/rule.vala @@ -0,0 +1,151 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +public abstract class Valadoc.Rule : Object { + + public static Rule seq (Object?[] scheme) { + return new SequenceRule (scheme); + } + + public static Rule one_of (Object?[] scheme) { + return new OneOfRule (scheme); + } + + public static Rule many (Object?[] scheme) { + if (scheme.length == 1) { + return new ManyRule (scheme[0]); + } else { + return new ManyRule (new SequenceRule (scheme)); + } + } + + public static Rule option (Object?[] scheme) { + if (scheme.length == 1) { + return new OptionalRule (scheme[0]); + } else { + return new OptionalRule (new SequenceRule (scheme)); + } + } + + protected Rule () { + } + + private string? _name = null; + private Action _start_action; + private Action _reduce_action; + + public string name { get { return _name; } } + + public Rule set_name (string name) { + _name = name; + return this; + } + + public delegate void Action () throws ParserError; + + public Rule set_start (Action action) { + _start_action = action; + return this; + } + + public Rule set_reduce (Action action) { + _reduce_action = action; + return this; + } + + public enum Forward { + NONE, PARENT, CHILD + } + + public abstract bool is_optional (); + public abstract bool starts_with_token (Token token); + public abstract bool accept_token (Token token, ParserCallback parser, Rule.Forward forward) throws ParserError; + public abstract bool would_accept_token (Token token, Object? state); + public abstract bool would_reduce (Token token, Object? state); + + public abstract string to_string (Object? state); + + protected bool is_optional_rule (Object? scheme_element) { + Rule? scheme_rule = scheme_element as Rule; + if (scheme_rule != null) { + return scheme_rule.is_optional (); + } + return false; + } + + protected bool has_start_token (Object? scheme_element, Token token) { + TokenType? scheme_token_type = scheme_element as TokenType; + if (scheme_token_type != null) { + return scheme_token_type.matches (token); + } + Rule? scheme_rule = scheme_element as Rule; + if (scheme_rule != null) { + return scheme_rule.starts_with_token (token); + } + return false; + } + + protected bool try_to_apply (Object? scheme_element, Token token, ParserCallback parser, out bool handled) throws ParserError { + #if VERY_HARD_DEBUG + { + TokenType? scheme_token = scheme_element as TokenType; + Rule? scheme_rule = scheme_element as Rule; + if (scheme_token != null) { + message ("TryToApply: token='%s'; scheme_token='%s'", token.to_string (), scheme_token.to_string ()); + } else if (scheme_rule != null) { + message ("TryToApply: token='%s'; scheme_rule='%s'", token.to_string (), scheme_rule.to_string (parser.get_rule_state ())); + } else { + assert (scheme_element != null); + } + } + #endif + TokenType? scheme_token_type = scheme_element as TokenType; + if (scheme_token_type != null && scheme_token_type.matches (token)) { + scheme_token_type.do_action (token); + handled = true; + return true; + } + Rule? scheme_rule = scheme_element as Rule; + if (scheme_rule != null && scheme_rule.starts_with_token (token)) { + parser.push_rule (scheme_rule); + handled = false; + return true; + } + return false; + } + + protected void do_start (ParserCallback parser) throws ParserError { + if (_start_action != null) { + _start_action (); + } + } + + protected void do_reduce (ParserCallback parser) throws ParserError { + if (_reduce_action != null) { + _reduce_action (); + } + parser.reduce (); + } +} diff --git a/src/libvaladoc/parser/scanner.vala b/src/libvaladoc/parser/scanner.vala new file mode 100644 index 000000000..be583ed08 --- /dev/null +++ b/src/libvaladoc/parser/scanner.vala @@ -0,0 +1,37 @@ +/* commentscanner.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +public interface Valadoc.Scanner : Object { + + public abstract void set_parser (Parser parser); + + public abstract void reset (); + + public abstract void scan (string content) throws ParserError; + + public abstract void end () throws ParserError; + + public abstract void stop (); + + public abstract string get_line_content (); +} diff --git a/src/libvaladoc/parser/sequencerule.vala b/src/libvaladoc/parser/sequencerule.vala new file mode 100644 index 000000000..7989afb25 --- /dev/null +++ b/src/libvaladoc/parser/sequencerule.vala @@ -0,0 +1,129 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +internal class Valadoc.SequenceRule : Rule { + + public SequenceRule (Object[] scheme) { + _scheme = scheme; + } + + private Object[] _scheme; + + private class State : Object { + public int index = 0; + } + + public override bool is_optional () { + return false; + } + + public override bool starts_with_token (Token token) { + return test_token (0, token); + } + + private bool test_token (int from_index, Token token) { + int i = from_index; + while (i < _scheme.length) { + if (has_start_token (_scheme[i], token)) { + return true; + } + if (!is_optional_rule (_scheme[i])) { + break; + } + i++; + } + return false; + } + + private bool test_reduce (int from_index, Token token) { + int i = from_index; + while (i < _scheme.length) { + if (!is_optional_rule (_scheme[i])) { + return false; + } + i++; + } + return true; + } + + public override bool accept_token (Token token, ParserCallback parser, Rule.Forward forward) throws ParserError { + var state = parser.get_rule_state () as State; + if (state == null) { + state = new State (); + parser.set_rule_state (state); + } + + if (state.index == 0) { + do_start (parser); + } else if (state.index == _scheme.length) { + do_reduce (parser); + return false; + } + + Object? scheme_element = null; + bool handled; + do { + scheme_element = _scheme[state.index]; + if (try_to_apply (scheme_element, token, parser, out handled)) { + state.index++; + return handled; + } + if (!is_optional_rule (scheme_element)) { + break; + } + state.index++; + } while (state.index < _scheme.length); + + if (state.index == _scheme.length) { + do_reduce (parser); + return false; + } + + if (scheme_element is TokenType) { + parser.error ("expected %s".printf (((TokenType) scheme_element).to_pretty_string ()), token); + } else { + parser.error ("unexpected token", token); + } + assert_not_reached (); + } + + public override bool would_accept_token (Token token, Object? rule_state) { + var state = rule_state as State; + return test_token (state.index, token); + } + + public override bool would_reduce (Token token, Object? rule_state) { + var state = rule_state as State; + return state.index == _scheme.length || test_reduce (state.index, token); + } + + public override string to_string (Object? rule_state) { + var state = rule_state as State; + if (state == null) { + state = new State (); + } + return "%-15s%-15s(index=%d/%d)".printf (name != null ? name : " ", "[seq]", state.index, _scheme.length); + } +} diff --git a/src/libvaladoc/parser/sourcelocation.vala b/src/libvaladoc/parser/sourcelocation.vala new file mode 100644 index 000000000..0a461c197 --- /dev/null +++ b/src/libvaladoc/parser/sourcelocation.vala @@ -0,0 +1,36 @@ +/* sourcelocation.vala + * + * Copyright (C) 2008 Jürg Billeter + * + * 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: + * Jürg Billeter + */ + +using GLib; + +/** + * Represents a position in a source file. + */ +public struct Valadoc.SourceLocation { + public int line; + public int column; + + public SourceLocation (int _line, int _column) { + line = _line; + column = _column; + } +} diff --git a/src/libvaladoc/parser/stubrule.vala b/src/libvaladoc/parser/stubrule.vala new file mode 100644 index 000000000..e9a6f28dc --- /dev/null +++ b/src/libvaladoc/parser/stubrule.vala @@ -0,0 +1,61 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +public class Valadoc.StubRule : Rule { + + public StubRule () { + } + + private Rule _rule; + + public Rule set_rule (Rule rule) { + _rule = rule; + return this; + } + + public override bool is_optional () { + return _rule.is_optional (); + } + + public override bool starts_with_token (Token token) { + return _rule.starts_with_token (token); + } + + public override bool accept_token (Token token, ParserCallback parser, Rule.Forward forward) throws ParserError { + return _rule.accept_token (token, parser, forward); + } + + public override bool would_accept_token (Token token, Object? state) { + return _rule.would_accept_token (token, state); + } + + public override bool would_reduce (Token token, Object? state) { + return _rule.would_reduce (token, state); + } + + public override string to_string (Object? state) { + return _rule.to_string (state); + } +} diff --git a/src/libvaladoc/parser/token.vala b/src/libvaladoc/parser/token.vala new file mode 100644 index 000000000..23654c727 --- /dev/null +++ b/src/libvaladoc/parser/token.vala @@ -0,0 +1,103 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +public class Valadoc.Token : Object { + + public Token.from_type (TokenType type, SourceLocation begin, SourceLocation end) { + _type = type; + _begin = begin; + _end = end; + } + + public Token.from_word (string word, SourceLocation begin, SourceLocation end) { + _word = word; + _begin = begin; + _end = end; + } + + private TokenType? _type = null; + private string? _word = null; + private SourceLocation _begin; + private SourceLocation _end; + + public bool is_word { + get { + return _word != null; + } + } + + public bool is_number { + get { + if (_word == null || _word.length == 0) { + return false; + } else if (_word[0] == '0' && _word.length > 1) { + return false; + } + for (int i = 0; i < _word.length; i++) { + if (_word[i] < '0' || _word[i] > '9') { + return false; + } + } + return true; + } + } + + public string? word { + get { + return _word; + } + } + + public TokenType? token_type { + get { + return _type; + } + } + + public SourceLocation begin { + get { + return _begin; + } + } + + public SourceLocation end { + get { + return _end; + } + } + + public string to_string () { + return _word == null ? _type.to_string () : _word; + } + + public string to_pretty_string () { + return _word == null ? _type.to_pretty_string () : _word; + } + + public int to_int () { + assert (is_number); + return _word.to_int (); + } +} diff --git a/src/libvaladoc/parser/tokentype.vala b/src/libvaladoc/parser/tokentype.vala new file mode 100644 index 000000000..5edaf4bfb --- /dev/null +++ b/src/libvaladoc/parser/tokentype.vala @@ -0,0 +1,183 @@ +/* parser.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using Gee; + +public class Valadoc.TokenType : Object { + + public static TokenType ANY; + public static TokenType ANY_WORD; + public static TokenType ANY_NUMBER; + public static TokenType EOF; + public static TokenType EOL; + public static TokenType AROBASE; + public static TokenType SPACE; + public static TokenType TAB; + public static TokenType EQUAL_1; + public static TokenType EQUAL_2; + public static TokenType EQUAL_3; + public static TokenType EQUAL_4; + public static TokenType EQUAL_5; + public static TokenType MINUS; + public static TokenType STAR; + public static TokenType SHARP; + public static TokenType LESS_THAN; + public static TokenType GREATER_THAN; + public static TokenType ALIGN_TOP; + public static TokenType ALIGN_BOTTOM; + public static TokenType SINGLE_QUOTE_2; + public static TokenType SLASH_2; + public static TokenType UNDERSCORE_2; + public static TokenType BACK_QUOTE; + public static TokenType OPEN_BRACE; + public static TokenType CLOSED_BRACE; + public static TokenType DOUBLE_OPEN_BRACE; + public static TokenType DOUBLE_CLOSED_BRACE; + public static TokenType TRIPLE_OPEN_BRACE; + public static TokenType TRIPLE_CLOSED_BRACE; + public static TokenType DOUBLE_OPEN_BRACKET; + public static TokenType DOUBLE_CLOSED_BRACKET; + public static TokenType PIPE; + public static TokenType DOUBLE_PIPE; + public static TokenType ALIGN_RIGHT; + public static TokenType ALIGN_CENTER; + + private static bool initialized = false; + + internal static void init_token_types () { + if (!initialized) { + ANY = new TokenType.basic (""); + ANY_WORD = new TokenType.basic (""); + ANY_NUMBER = new TokenType.basic (""); + EOF = new TokenType.basic ("\0", ""); + EOL = new TokenType.basic ("\n", ""); + AROBASE = new TokenType.basic ("@"); + SPACE = new TokenType.basic (" ", ""); + TAB = new TokenType.basic ("\t", ""); + EQUAL_1 = new TokenType.basic ("="); + EQUAL_2 = new TokenType.basic ("=="); + EQUAL_3 = new TokenType.basic ("===="); + EQUAL_4 = new TokenType.basic ("====="); + EQUAL_5 = new TokenType.basic ("======"); + MINUS = new TokenType.basic ("-"); + STAR = new TokenType.basic ("*"); + SHARP = new TokenType.basic ("#"); + LESS_THAN = new TokenType.basic ("<"); + GREATER_THAN = new TokenType.basic (">"); + ALIGN_TOP = new TokenType.basic ("^"); + ALIGN_BOTTOM = new TokenType.basic ("v"); + SINGLE_QUOTE_2 = new TokenType.basic ("''"); + SLASH_2 = new TokenType.basic ("//"); + UNDERSCORE_2 = new TokenType.basic ("__"); + BACK_QUOTE = new TokenType.basic ("`"); + OPEN_BRACE = new TokenType.basic ("{"); + CLOSED_BRACE = new TokenType.basic ("}"); + DOUBLE_OPEN_BRACE = new TokenType.basic ("{{"); + DOUBLE_CLOSED_BRACE = new TokenType.basic ("}}"); + TRIPLE_OPEN_BRACE = new TokenType.basic ("{{{"); + TRIPLE_CLOSED_BRACE = new TokenType.basic ("}}}"); + DOUBLE_OPEN_BRACKET = new TokenType.basic ("[["); + DOUBLE_CLOSED_BRACKET = new TokenType.basic ("]]"); + PIPE = new TokenType.basic ("|"); + DOUBLE_PIPE = new TokenType.basic ("||"); + ALIGN_RIGHT = new TokenType.basic ("))"); + ALIGN_CENTER = new TokenType.basic (")("); + initialized = true; + } + } + + private static int EXACT_WORD = -1; + + public static TokenType str (string str) { + return new TokenType (str, EXACT_WORD, null); + } + + public static TokenType any () { + return ANY; + } + + public static TokenType any_word () { + return ANY_WORD; + } + + public static TokenType any_number () { + return ANY_NUMBER; + } + + private TokenType (string string_value, int basic_value, Action? action) { + _string_value = string_value; + _basic_value = basic_value; + _action = action; + } + + private TokenType.basic (string string_value, string? pretty_string = null) { + _string_value = string_value; + _pretty_string = pretty_string; + _basic_value = ++_last_basic_value; + } + + private static int _last_basic_value = -1; + + private string _string_value; + private string? _pretty_string; + private int _basic_value = -1; + private Action? _action = null; + + public delegate void Action (Token token) throws ParserError; + + public TokenType action (Action action) { + return new TokenType (_string_value, _basic_value, action); + } + + public void do_action (Token matched_token) throws ParserError { + if (_action != null) { + _action (matched_token); + } + } + + public bool matches (Token token) { + if (_basic_value == ANY._basic_value) { + return true; + } else if (_basic_value == ANY_WORD._basic_value && token.is_word) { + return true; + } else if (_basic_value == ANY_NUMBER._basic_value && token.is_number) { + return true; + } else if (_basic_value == EXACT_WORD && token.is_word && token.word == _string_value) { + return true; + } else if (token.token_type != null && token.token_type._basic_value == _basic_value) { + return true; + } + return false; + } + + public string to_string () { + return _string_value; + } + + public string to_pretty_string () { + if (_pretty_string != null) { + return _pretty_string; + } + return _string_value; + } +} diff --git a/src/libvaladoc/parser/wikiscanner.vala b/src/libvaladoc/parser/wikiscanner.vala new file mode 100644 index 000000000..1784ccd61 --- /dev/null +++ b/src/libvaladoc/parser/wikiscanner.vala @@ -0,0 +1,395 @@ +/* commentscanner.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +public class Valadoc.WikiScanner : Object, Scanner { + + public WikiScanner (Settings settings) { + _settings = settings; + } + + private Settings _settings; + private Parser _parser; + + private string _content; + private int _index; + private bool _stop; + private int _last_index; + private int _last_line; + private int _last_column; + private int _line; + private int _column; + private bool _url_escape_mode; + private bool _code_escape_mode; + private unichar _last_char; + private int _skip; + private StringBuilder _current_string = new StringBuilder (); + + public void set_parser (Parser parser) { + _parser = parser; + } + + public virtual void reset () { + _stop = false; + _last_index = 0; + _last_line = 0; + _last_column = 0; + _line = 0; + _column = 0; + _url_escape_mode = false; + _code_escape_mode = false; + _last_char = 0; + _skip = 0; + _current_string.erase (0, -1); + } + + public void scan (string _content) throws ParserError { + this._content = _content; + for (_index = 0; !_stop && _index < _content.length; _index++) { + unichar c = _content[_index]; + accept (c); + } + } + + public void end () throws ParserError { + emit_token (TokenType.EOF); + } + + public virtual void stop () { + _stop = true; + } + + public void set_url_escape_mode (bool escape_mode) { + _url_escape_mode = escape_mode; + } + + public void set_code_escape_mode (bool escape_mode) { + _code_escape_mode = escape_mode; + } + + public int get_line () { + return _line; + } + + public virtual string get_line_content () { + int i = _index; + while (i > 0 && _content[i-1] != '\n') { + i--; + } + StringBuilder builder = new StringBuilder (); + while (i < _content.length && _content[i] != '\n') { + unichar c = _content[i++]; + if (c == '\t') { + builder.append (" "); + } else { + builder.append_unichar (c); + } + } + return builder.str; + } + + protected unichar get_next_char (int offset = 1) { + return _content[_index + offset]; + } + + protected virtual void accept (unichar c) throws ParserError { + _column++; + if (_skip == 0) { + if (_code_escape_mode) { + switch (c) { + case '}': + if (get_next_char (1) == c && get_next_char (2) == c) { + _code_escape_mode = false; // This is a temporary hack + emit_token (TokenType.TRIPLE_CLOSED_BRACE); + _skip = 2; + } else { + append_char (c); + } + return; + default: + append_char (c); + return; + } + } else if (_url_escape_mode) { + switch (c) { + // Reserved characters + case ';': + case '/': + case '?': + case ':': + case '@': + case '#': + case '=': + case '&': + // Special characters + case '$': + case '-': + case '_': + case '.': + case '+': + case '!': + case '*': + case '\'': + case '(': + case ')': + case ',': + append_char (c); + return; + default: + break; + } + } + + switch (c) { + case '@': + if (get_next_char () == '@') { + append_char (c); + _skip = 1; + } else { + emit_token (TokenType.AROBASE); + } + break; + + case '{': + look_for_three (c, + TokenType.OPEN_BRACE, + TokenType.DOUBLE_OPEN_BRACE, + TokenType.TRIPLE_OPEN_BRACE); + break; + + case '}': + look_for_three (c, + TokenType.CLOSED_BRACE, + TokenType.DOUBLE_CLOSED_BRACE, + TokenType.TRIPLE_CLOSED_BRACE); + break; + + case '[': + look_for_two_or_append (c, TokenType.DOUBLE_OPEN_BRACKET); + break; + + case ']': + look_for_two_or_append (c, TokenType.DOUBLE_CLOSED_BRACKET); + break; + + case '|': + look_for_two (c, + TokenType.PIPE, + TokenType.DOUBLE_PIPE); + break; + + case ')': + if (get_next_char () == ')') { + emit_token (TokenType.ALIGN_RIGHT); + _skip = 1; + } else if (get_next_char () == '(') { + emit_token (TokenType.ALIGN_CENTER); + _skip = 1; + } else { + append_char (c); + } + break; + + case '*': + emit_token (TokenType.STAR); + break; + + case '#': + emit_token (TokenType.SHARP); + break; + + case '-': + if (_last_char.isalnum () || get_next_char ().isalnum ()) { + append_char (c); + } else { + emit_token (TokenType.MINUS); + } + break; + + case '=': + look_for_five (c, + TokenType.EQUAL_1, + TokenType.EQUAL_2, + TokenType.EQUAL_3, + TokenType.EQUAL_4, + TokenType.EQUAL_5); + break; + + case '<': + emit_token (TokenType.LESS_THAN); + break; + + case '>': + emit_token (TokenType.GREATER_THAN); + break; + + case '^': + emit_token (TokenType.ALIGN_TOP); + break; + + case 'v': + unichar next_char = get_next_char (); + if (_last_char.isalnum () || _last_char == ' ' + || next_char.isalnum () || next_char == ' ') { + append_char (c); + } else { + emit_token (TokenType.ALIGN_BOTTOM); + } + break; + + case '\'': + look_for_two_or_append (c, TokenType.SINGLE_QUOTE_2); + break; + + case '/': + look_for_two_or_append (c, TokenType.SLASH_2); + break; + + case '_': + look_for_two_or_append (c, TokenType.UNDERSCORE_2); + break; + + case '`': + emit_token (TokenType.BACK_QUOTE); + break; + + case '\t': + emit_token (TokenType.TAB); + break; + + case ' ': + emit_token (TokenType.SPACE); + break; + + case '\r': + break; + + case '\n': + emit_token (TokenType.EOL); + _line++; + _column = 0; + _last_column = 0; + break; + + default: + append_char (c); + break; + } + } else { + _skip--; + } + _last_char = c; + } + + private void append_char (unichar c) { + _current_string.append_unichar (c); + } + + public virtual int get_line_start_column () { + return 0; + } + + private SourceLocation get_begin () { + return SourceLocation (_last_line, get_line_start_column () + _last_column); + } + + private SourceLocation get_end (int offset = 0) { + return SourceLocation (_line, get_line_start_column () + _column + offset); + } + + private void emit_current_word () throws ParserError { + if (_current_string.len > 0) { + _parser.accept_token (new Token.from_word (_current_string.str, get_begin (), get_end (-1))); + _current_string.erase (0, -1); + + _last_index = _index; + _last_line = _line; + _last_column = _column - 1; + } + } + + private void emit_token (TokenType type) throws ParserError { + emit_current_word (); + + _parser.accept_token (new Token.from_type (type, get_begin (), get_end (_skip))); + + _last_index = _index; + _last_line = _line; + _last_column = _column; + } + + private void look_for_two_or_append (unichar c, TokenType type) throws ParserError { + if (get_next_char () == c) { + emit_token (type); + _skip = 1; + } else { + append_char (c); + } + } + + private void look_for_two (unichar c, TokenType one, TokenType two) throws ParserError { + if (get_next_char (1) == c) { + emit_token (two); + _skip = 1; + } else { + emit_token (one); + } + } + + private void look_for_three (unichar c, TokenType one, TokenType two, TokenType three) throws ParserError { + if (get_next_char (1) == c) { + if (get_next_char (2) == c) { + emit_token (three); + _skip = 2; + } else { + emit_token (two); + _skip = 1; + } + } else { + emit_token (one); + } + } + + private void look_for_five (unichar c, TokenType one, TokenType two, TokenType three, TokenType four, TokenType five) throws ParserError { + if (get_next_char (1) == c) { + if (get_next_char (2) == c) { + if (get_next_char (3) == c) { + if (get_next_char (4) == c) { + emit_token (five); + _skip = 4; + } else { + emit_token (four); + _skip = 3; + } + } else { + emit_token (three); + _skip = 2; + } + } else { + emit_token (two); + _skip = 1; + } + } else { + emit_token (one); + } + } +} diff --git a/src/libvaladoc/taglets/tagletdeprecated.vala b/src/libvaladoc/taglets/tagletdeprecated.vala new file mode 100755 index 000000000..7efc2bce1 --- /dev/null +++ b/src/libvaladoc/taglets/tagletdeprecated.vala @@ -0,0 +1,40 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; +using Valadoc.Content; + +public class Valadoc.Taglets.Deprecated : InlineContent, Taglet, Block { + public Rule? get_parser_rule (Rule run_rule) { + return run_rule; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + base.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_taglet (this); + } +} diff --git a/src/libvaladoc/taglets/tagletinheritdoc.vala b/src/libvaladoc/taglets/tagletinheritdoc.vala new file mode 100755 index 000000000..f4ff91864 --- /dev/null +++ b/src/libvaladoc/taglets/tagletinheritdoc.vala @@ -0,0 +1,64 @@ +/* tagletinheritdoc.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; +using Valadoc.Content; + +public class Valadoc.Taglets.InheritDoc : InlineTaglet { + private DocumentedElement? _inherited; + + public override Rule? get_parser_rule (Rule run_rule) { + return null; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // TODO Check that the container is an override of an abstract symbol + // Also retrieve that abstract symbol _inherited + + if (container is Method) { + _inherited = ((Method) container).base_method; + } else if (container is Property) { + _inherited = ((Property) container).base_property; + } + + // TODO report error if inherited is null + + // TODO postpone check after complete parse of the api tree comments + // And reenable that check + //base.check (api_root, container, reporter); + } + + public override ContentElement produce_content () { + if (_inherited != null) { + Paragraph inherited_paragraph = _inherited.documentation.content.get (0) as Paragraph; + + Highlighted paragraph = new Highlighted (Highlighted.Style.NONE); + foreach (var element in inherited_paragraph.content) { + paragraph.content.add (element); + } + return paragraph; + } + return new Text (""); + } +} diff --git a/src/doclets/htmlhelpers/taglets/constants.vala b/src/libvaladoc/taglets/tagletinit.vala old mode 100755 new mode 100644 similarity index 55% rename from src/doclets/htmlhelpers/taglets/constants.vala rename to src/libvaladoc/taglets/tagletinit.vala index df7128857..42d914772 --- a/src/doclets/htmlhelpers/taglets/constants.vala +++ b/src/libvaladoc/taglets/tagletinit.vala @@ -17,29 +17,17 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -using GLib; -using Gee; - - -public class Valadoc.Html.CodeConstantDocElement : Valadoc.CodeConstantDocElement { - private string constant; - - public override bool parse (string constant) { - this.constant = constant; - return true; - } - - public override bool write (void* res, int max, int index) { - weak GLib.FileStream file = (GLib.FileStream)res; - file.printf ("%s", css_content_literal, this.constant); - return true; +using Valadoc; + +namespace Valadoc.Taglets { + public void init (ModuleLoader loader) { + loader.taglets.set ("see", typeof (Valadoc.Taglets.See)); + loader.taglets.set ("since", typeof (Valadoc.Taglets.Since)); + loader.taglets.set ("link", typeof (Valadoc.Taglets.Link)); + loader.taglets.set ("throws", typeof (Valadoc.Taglets.Throws)); + loader.taglets.set ("return", typeof (Valadoc.Taglets.Return)); + loader.taglets.set ("param", typeof (Valadoc.Taglets.Param)); + loader.taglets.set ("deprecated", typeof (Valadoc.Taglets.Deprecated)); + loader.taglets.set ("inheritDoc", typeof (Valadoc.Taglets.InheritDoc)); } } - - -[ModuleInit] -public GLib.Type register_plugin (Gee.HashMap taglets) { - return typeof (Valadoc.Html.CodeConstantDocElement); -} - diff --git a/src/libvaladoc/taglets/tagletlink.vala b/src/libvaladoc/taglets/tagletlink.vala new file mode 100755 index 000000000..9849560a9 --- /dev/null +++ b/src/libvaladoc/taglets/tagletlink.vala @@ -0,0 +1,55 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; +using Valadoc.Content; + +public class Valadoc.Taglets.Link : InlineTaglet { + public string symbol_name { private set; get; } + + private DocumentedElement _symbol; + + public override Rule? get_parser_rule (Rule run_rule) { + return Rule.seq ({ + TokenType.any_word ().action ((token) => { symbol_name = token.to_string (); }) + }); + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + _symbol = api_root.search_symbol_str (container, symbol_name); + if (_symbol == null) { + // TODO use ContentElement's source reference + reporter.simple_error ("%s does not exist".printf (symbol_name)); + } + + base.check (api_root, container, reporter); + } + + public override ContentElement produce_content () { + var link = new Content.SymbolLink (); + link.symbol = _symbol; + link.label = symbol_name; + return link; + } +} diff --git a/src/libvaladoc/taglets/tagletparam.vala b/src/libvaladoc/taglets/tagletparam.vala new file mode 100755 index 000000000..786441187 --- /dev/null +++ b/src/libvaladoc/taglets/tagletparam.vala @@ -0,0 +1,48 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; +using Valadoc.Content; + +public class Valadoc.Taglets.Param : InlineContent, Taglet, Block { + public string parameter_name { private set; get; } + + public Rule? get_parser_rule (Rule run_rule) { + return Rule.seq ({ + TokenType.any_word ().action ((token) => { parameter_name = token.to_string (); }), + Rule.many ({ TokenType.SPACE }), + run_rule + }); + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // TODO check for the existence of such a parameter + + base.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_taglet (this); + } +} diff --git a/src/libvaladoc/taglets/tagletreturn.vala b/src/libvaladoc/taglets/tagletreturn.vala new file mode 100755 index 000000000..c43c8d503 --- /dev/null +++ b/src/libvaladoc/taglets/tagletreturn.vala @@ -0,0 +1,42 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; +using Valadoc.Content; + +public class Valadoc.Taglets.Return : InlineContent, Taglet, Block { + public Rule? get_parser_rule (Rule run_rule) { + return run_rule; + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + // TODO check for the existence of a return type + + base.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_taglet (this); + } +} diff --git a/src/libvaladoc/taglets/tagletsee.vala b/src/libvaladoc/taglets/tagletsee.vala new file mode 100755 index 000000000..533a48ce7 --- /dev/null +++ b/src/libvaladoc/taglets/tagletsee.vala @@ -0,0 +1,49 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; +using Valadoc.Content; + +public class Valadoc.Taglets.See : ContentElement, Taglet, Block { + public string symbol_name { private set; get; } + public DocumentedElement symbol { private set; get; } + + public Rule? get_parser_rule (Rule run_rule) { + return Rule.seq ({ + TokenType.any_word ().action ((token) => { symbol_name = token.to_string (); }) + }); + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + symbol = api_root.search_symbol_str (container, symbol_name); + if (symbol == null) { + // TODO use ContentElement's source reference + reporter.simple_error ("%s does not exist".printf (symbol_name)); + } + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_taglet (this); + } +} diff --git a/src/libvaladoc/taglets/tagletsince.vala b/src/libvaladoc/taglets/tagletsince.vala new file mode 100755 index 000000000..e895c13e4 --- /dev/null +++ b/src/libvaladoc/taglets/tagletsince.vala @@ -0,0 +1,43 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; +using Valadoc.Content; + +public class Valadoc.Taglets.Since : ContentElement, Taglet, Block { + public string version; + + public Rule? get_parser_rule (Rule run_rule) { + return Rule.seq ({ + TokenType.any_word ().action ((token) => { version = token.to_string (); }) + }); + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_taglet (this); + } +} diff --git a/src/libvaladoc/taglets/tagletthrows.vala b/src/libvaladoc/taglets/tagletthrows.vala new file mode 100755 index 000000000..5fd7937cf --- /dev/null +++ b/src/libvaladoc/taglets/tagletthrows.vala @@ -0,0 +1,53 @@ +/* taglet.vala + * + * Valadoc - a documentation tool for vala. + * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Author: + * Didier 'Ptitjes Villevalois + */ + +using GLib; +using Gee; +using Valadoc.Content; + +public class Valadoc.Taglets.Throws : InlineContent, Taglet, Block { + public string error_domain_name { private set; get; } + public DocumentedElement error_domain { private set; get; } + + public Rule? get_parser_rule (Rule run_rule) { + return Rule.seq ({ + TokenType.any_word ().action ((token) => { error_domain_name = token.to_string (); }), + Rule.many ({ TokenType.SPACE }), + run_rule + }); + } + + public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) { + error_domain = api_root.search_symbol_str (container, error_domain_name); + if (error_domain == null) { + // TODO use ContentElement's source reference + reporter.simple_error ("%s does not exist".printf (error_domain_name)); + } + + base.check (api_root, container, reporter); + } + + public override void accept (ContentVisitor visitor) { + visitor.visit_taglet (this); + } +} diff --git a/src/libvaladoc/testcomment.test b/src/libvaladoc/testcomment.test new file mode 100644 index 000000000..9e6919d9a --- /dev/null +++ b/src/libvaladoc/testcomment.test @@ -0,0 +1,48 @@ +* + * This is a stupid {@dumb} ''toto'' //''documentation''// comment + * for everything I didn't comment until now + * + * __Another__ description //line// + * + * Yet another __description__ line, but this one __lasts__ + * along some [[http://live.gnome.org/valadoc/|The Valadoc Website]] + * {{./img/an_image.png|An image}} + * //lines// + * + * )) A right-aligned paragraph+ {@link AType} that continues at the + * next line + * + * )( Center-aligned stuff + * + * {@inheritDoc} + * + * {{{ + * if (toto) { + * do_bad_stuff (my_variable++); + * } + * }}} + * * A list item + * * Another list item + * . No bullet + * * A list item + * * Another list item + * + * || Joint Header Cell || + * ||
    Joint Cell || Cell3 || + * || Cell1 || <|2> Joint Cell || + * + * == Header 2 == + * === Header 3 === + * One can write immediately after headers + * + * ==== Header 4 ==== + * A. Mixed with ordered items + * 1. Another ordered items + * + * And some other data + * + * @param test a test parameter + * that continues here + * @return the value it returns + * and this is the @@last line + \ No newline at end of file diff --git a/src/libvaladoc/testparser.sh b/src/libvaladoc/testparser.sh new file mode 100755 index 000000000..46c8c5177 --- /dev/null +++ b/src/libvaladoc/testparser.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +DEBUG_FLAGS="" +#DEBUG_FLAGS="$DEBUG_FLAGS -D DEBUG" +#DEBUG_FLAGS="$DEBUG_FLAGS -D HARD_DEBUG" +#DEBUG_FLAGS="$DEBUG_FLAGS -D VERY_HARD_DEBUG" + +COMMAND="./testparser testcomment.test" +COMMAND="gdb -ex run -ex bt -ex finish -ex quit --args $COMMAND" + +valac -C $DEBUG_FLAGS -g -o testparser --pkg vala-1.0 \ + parser/commentscanner.vala \ + parser/documentationfactory.vala \ + parser/documentationparser.vala \ + parser/manyrule.vala \ + parser/oneofrule.vala \ + parser/parser.vala \ + parser/parsercallback.vala \ + parser/rule.vala \ + parser/scanner.vala \ + parser/sequencerule.vala \ + parser/stubrule.vala \ + parser/token.vala \ + parser/wikiscanner.vala \ + documentation/errorreporter.vala \ + settings.vala \ + testparser.vala \ +&& valac $DEBUG_FLAGS -g -o testparser --pkg vala-1.0 \ + parser/commentscanner.vala \ + parser/documentationfactory.vala \ + parser/documentationparser.vala \ + parser/manyrule.vala \ + parser/oneofrule.vala \ + parser/parser.vala \ + parser/parsercallback.vala \ + parser/rule.vala \ + parser/scanner.vala \ + parser/sequencerule.vala \ + parser/stubrule.vala \ + parser/token.vala \ + parser/wikiscanner.vala \ + documentation/errorreporter.vala \ + settings.vala \ + testparser.vala \ +&& $COMMAND diff --git a/src/libvaladoc/testparser.vala b/src/libvaladoc/testparser.vala new file mode 100644 index 000000000..fff2230d5 --- /dev/null +++ b/src/libvaladoc/testparser.vala @@ -0,0 +1,16 @@ +/** Just a test file for parser2 **/ + +namespace Valadoc { + void main (string[] args) { + Settings settings = new Settings (); + ErrorReporter reporter = new ErrorReporter (); + DocumentationParser parser = new DocumentationParser(settings, reporter); + + string filename = args[1]; + string content; + if (FileUtils.get_contents (filename, out content)) { + Object root = parser.parse_comment (content, filename, 0, 0); + stdout.printf ("\n%s\n", ((Node) root).to_string ()); + } + } +} diff --git a/src/valadoc/valadoc.vala b/src/valadoc/valadoc.vala index 055895502..26ae78be5 100755 --- a/src/valadoc/valadoc.vala +++ b/src/valadoc/valadoc.vala @@ -172,6 +172,7 @@ public class ValaDoc : Object { ModuleLoader modules = new ModuleLoader (); + Taglets.init (modules); bool tmp = modules.load (fulldirpath); if (tmp == false) { reporter.simple_error ("failed to load plugin"); @@ -180,7 +181,7 @@ public class ValaDoc : Object { Valadoc.Tree doctree = new Valadoc.Tree (reporter, settings); - Valadoc.Parser docparser = new Valadoc.Parser (settings, reporter, doctree, modules); + Valadoc.DocumentationParser docparser = new Valadoc.DocumentationParser (settings, reporter, doctree, modules); if (reporter.errors > 0) { return quit (reporter); }