Many libraries are now using gi-docgen and we are starting to see the doc:format
entry in the .girs.
return parameters.get (param_name);
}
- public GirSourceComment (string content, SourceFile file, int first_line, int first_column, int last_line, int last_column) {
- base (content, file, first_line, first_column, last_line, last_column);
+ public GirSourceComment (string content, SourceComment.Format format, SourceFile file, int first_line, int first_column, int last_line, int last_column) {
+ base (content, format, file, first_line, first_column, last_line, last_column);
}
}
* A documentation comment used by valadoc
*/
public class Valadoc.Api.SourceComment {
+ public enum Format {
+ UNKNOWN,
+ GI_DOCGEN,
+ GTK_DOC_MARKDOWN,
+ GTK_DOC_DOCBOOK,
+ HOTDOC;
+
+ public static Format from_string (string val) {
+ var enum_class = (EnumClass) typeof(Format).class_ref ();
+ unowned GLib.EnumValue? enum_value = enum_class.get_value_by_nick (val);
+ if (enum_value != null) {
+ return (Format) enum_value.value;
+ }
+
+ return Format.UNKNOWN;
+ }
+ }
+
public SourceFile file {
private set;
get;
get;
}
+ /**
+ * The format of the documentation comment.
+ */
+ public Format format {
+ private set;
+ get;
+ }
+
/**
* The first line number of the referenced source code.
*/
get;
}
- public SourceComment (string content, SourceFile file, int first_line, int first_column,
- int last_line, int last_column)
+ public SourceComment (string content, Format format, SourceFile file,
+ int first_line, int first_column,
+ int last_line, int last_column)
{
this.first_column = first_column;
this.last_column = last_column;
this.first_line = first_line;
this.last_line = last_line;
this.content = content;
+ this.format = format;
this.file = file;
}
}
Api.GirSourceComment gir_comment = (Api.GirSourceComment) comment;
GirMetaData metadata = get_metadata_for_comment (gir_comment);
- if (metadata.is_docbook) {
+ //TODO Handle more documentation formats
+ if (metadata.is_docbook || comment.format == Api.SourceComment.Format.GTK_DOC_DOCBOOK) {
Comment doc_comment = gtkdoc_parser.parse (element, gir_comment, metadata, id_registrar);
return doc_comment;
} else {
private Vala.SourceLocation begin;
private Vala.SourceLocation end;
private Vala.MarkupReader reader;
+ private Api.SourceComment.Format documentation_format;
private DocumentationParser parser;
private Api.SourceFile file;
parse_package ();
} else if (reader.name == "c:include") {
parse_c_include ();
+ } else if (reader.name == "doc:format") {
+ parse_doc_format ();
} else {
// error
error ("unknown child element `%s' in `repository'".printf (reader.name));
end_element ("c:include");
}
+ private void parse_doc_format () {
+ start_element ("doc:format");
+ var format_name = reader.get_attribute ("name");
+ if (format_name != null) {
+ documentation_format = Api.SourceComment.Format.from_string (format_name);
+
+ if (documentation_format == Api.SourceComment.Format.UNKNOWN && format_name != "unknown") {
+ warning ("Unknown documentation format `%s'".printf (format_name));
+ }
+ }
+
+ next ();
+ end_element ("doc:format");
+ }
+
private void skip_element () {
next ();
next ();
if (current_token == Vala.MarkupTokenType.TEXT) {
- comment = new Api.GirSourceComment (reader.content, file, begin.line,
+ comment = new Api.GirSourceComment (reader.content, documentation_format, file, begin.line,
begin.column, end.line, end.column);
next ();
}
Api.SourceComment? comment = null;
if (current_token == Vala.MarkupTokenType.TEXT) {
- comment = new Api.SourceComment (reader.content, file, begin.line,
+ comment = new Api.SourceComment (reader.content, documentation_format, file, begin.line,
begin.column, end.line, end.column);
next ();
}
parse_return_value (out return_comment, out array_length_ret);
if (return_comment != null) {
if (comment == null) {
- comment = new Api.GirSourceComment ("", file, begin.line, begin.column,
+ comment = new Api.GirSourceComment ("", documentation_format, file, begin.line, begin.column,
end.line, end.column);
}
comment.return_comment = return_comment;
if (param_comment != null) {
if (comment == null) {
- comment = new Api.GirSourceComment ("", file, begin.line, begin.column,
+ comment = new Api.GirSourceComment ("", documentation_format, file, begin.line, begin.column,
end.line, end.column);
}
if (param_comment != null) {
if (comment == null) {
- comment = new Api.GirSourceComment ("", file, begin.line, begin.column,
+ comment = new Api.GirSourceComment ("", documentation_format, file, begin.line, begin.column,
end.line, end.column);
}
Vala.SourceReference pos = c.source_reference;
if (c is Vala.GirComment) {
comment = new GirSourceComment (c.content,
+ Api.SourceComment.Format.UNKNOWN,
file,
pos.begin.line,
pos.begin.column,
pos.end.column);
} else {
comment = new SourceComment (c.content,
+ Api.SourceComment.Format.UNKNOWN,
file,
pos.begin.line,
pos.begin.column,
SourceFile file = files.get (pos.file);
if (comment is Vala.GirComment) {
var tmp = new GirSourceComment (comment.content,
+ Api.SourceComment.Format.UNKNOWN,
file,
pos.begin.line,
pos.begin.column,
if (((Vala.GirComment) comment).return_content != null) {
Vala.SourceReference return_pos = ((Vala.GirComment) comment).return_content.source_reference;
tmp.return_comment = new SourceComment (((Vala.GirComment) comment).return_content.content,
+ Api.SourceComment.Format.UNKNOWN,
file,
return_pos.begin.line,
return_pos.begin.column,
Vala.Comment vala_param = it.get_value ();
Vala.SourceReference param_pos = vala_param.source_reference;
var param_comment = new SourceComment (vala_param.content,
+ Api.SourceComment.Format.UNKNOWN,
file,
param_pos.begin.line,
param_pos.begin.column,
return tmp;
} else {
return new SourceComment (comment.content,
+ Api.SourceComment.Format.UNKNOWN,
file,
pos.begin.line,
pos.begin.column,