5 public enum DocTagTitle
50 errordomain DocTagException {
58 public class DocTag : Object
61 public DocTagTitle title = DocTagTitle.NO_VALUE;
62 public string type = ""; // eg.. boolean / string etc..., may be xxxx|bbbb - eg. optional types
63 public string name = ""; // eg. "title" << a property name etc...
64 public bool isOptional = false;
65 public string defaultValue = "";
66 public string desc = "";
67 public Gee.ArrayList<string> optvalues;
68 public string memberOf = ""; // set by add addMember..
70 public string asString()
72 return "DocTag: title=%s name=%s type=%s desc=%s".printf(
73 this.title.to_string(),
84 public DocTag (string in_src)
87 GLib.debug("Parsing Tag: %s", in_src);
92 this.optvalues = new Gee.ArrayList<string>();
97 src = this.nibbleTitle(src);
99 src = this.nibbleType(src);
102 // only some tags are allowed to have names.
104 this.title == DocTagTitle.PARAM ||
105 this.title == DocTagTitle.PROPERTY ||
106 this.title == DocTagTitle.CFG) { // @config is deprecated
107 src = this.nibbleName(src);
110 catch(DocTagException e) {
111 GLib.debug("Failed to parse tag: '%s' = error = %s", in_src, e.message);
112 // only throw if in 'strict'??
117 // if type == @cfg, and matches (|....|...)
123 if (this.title == DocTagTitle.CFG && /^\([^)]+\)/.match_all(src, 0, out mi )) {
124 var ms = mi.fetch(0);
125 ms = ms.substring(1,ms.length-2);
126 if (ms.contains("|")) {
127 var ar = ms.split("|");
128 for (var i =0 ; i < ar.length;i++) {
129 optvalues.add(ar[i].strip());
131 src = src.substring(ms.length, src.length - ms.length);
138 this.desc = src; // whatever is left
140 // example tags need to have whitespace preserved
141 if (this.title != DocTagTitle.EXAMPLE) {
142 this.desc = this.desc.strip();
153 Find and shift off the title of a tag.
157 private string nibbleTitle (string src) throws DocTagException
159 //GLib.debug("nibbleTitle: %s", src);
162 if(! /^\s*(\S+)\s*(?:\s([\s\S]*))?$/.match_full(src, src.length, 0, 0, out mi) ||
163 mi.get_match_count() < 2) {
164 throw new DocTagException.NO_TITLE("missing title");
168 //GLib.debug("nibbleTitle: regexmatches %d : %s",
169 // mi.get_match_count(),
170 // mi.fetch(1).up());
172 EnumClass enumc = (EnumClass) typeof (DocTagTitle).class_ref ();
174 unowned EnumValue? eval = enumc.get_value_by_name ( "JSDOC_DOC_TAG_TITLE_"+ mi.fetch(1).up());
176 throw new DocTagException.INVALID_TITLE("title not supported ??");
179 this.title = (DocTagTitle) eval.value;
180 return mi.get_match_count() > 2 ? mi.fetch(2) : "";
185 Find and shift off the type of a tag.
186 @requires frame/String.js
190 private string nibbleType(string src)
193 if(! /^\s*\{/.match_all(src, 0, out mi)) {
199 this.balance(src,'{', '}', out start, out stop);
200 //GLib.debug("nibble type: %s %d, %d", src, start,stop);
202 throw new DocTagException.INVALID_TYPE("Malformed comment tag ignored. Tag type requires an opening { and a closing }: ") ;
205 this.type = src.substring(start+1,stop-1).strip();
206 this.type = this.type.replace(",", "|"); // multiples can be separated by , or |
207 return src.substring(stop+1, -1);
214 Find and shift off the name of a tag.
215 @requires frame/String.js
219 private string nibbleName( string in_src) throws DocTagException
223 var src = in_src.strip();
224 //GLib.debug("nibbleName: %s", in_src);
227 if (src.get(0) == '[') {
229 this.balance(src,'[', ']', out start, out stop);
231 throw new DocTagException.INVALID_NAME("Malformed comment tag ignored. Tag optional name requires an opening [ and a closing ]: ");
234 this.name = src.substring(start+1, stop).strip();
235 this.isOptional = true;
237 src = src.substring(stop+1);
239 // has default value?
240 var nameAndValue = this.name.split("=");
241 if (nameAndValue.length > 1) {
242 var oname = this.name;
243 this.name = nameAndValue[0].strip();
245 this.defaultValue = oname.substring( nameAndValue[0].length + 1 , nameAndValue[0].length + 1 - oname.length); /// what about
247 GLib.debug("got name %s", this.name);
248 return src.substring(stop+1, stop+1-src.length);
250 // not encased with [ ]
254 if (/^(\S+)(?:\s([\s\S]*))?$/.match_full(src, src.length, 0, 0, out mi)) {
255 this.name = mi.fetch(1);
256 GLib.debug("got name %s", this.name);
257 return mi.get_match_count() > 2 ? mi.fetch(2) : "";
265 private void balance(string str, char open, char close, out int start, out int stop) {
268 while (str.get(start) != open) {
269 if (start == str.length) {
277 while (stop < str.length) {
278 if (str.get(stop) == open) balance++;
279 if (str.get(stop) == close) balance--;
280 if (balance == 0) break;
282 if (stop == str.length) {
291 public Json.Array optvalue_as_json_array()
293 var ret = new Json.Array();
294 foreach (var str in this.optvalues ) {
295 ret.add_string_element(str);