Re: alternative gmarkup parser



On 10/23/00 Havoc Pennington wrote:
> Paolo Molaro <lupus lettere unipd it> writes: 
> > Maybe G_MARKUP_SKIP_WHITE_SPACE could be useful to skip white
[...]
> As far as I can tell the correct behavior is to dump whitespace below
> an element <foo> if there is no non-whitespace text below element
> <foo>, only other elements. The old non-incremental gmarkup parser did
> that, but you can't do it "on the fly" (you only know there was no
> non-whitespace text after you end the element <foo>).

Uhm, I can't find a reference now, but what I actually find useful is that
the parser strips the whitespace between tags:
	<tag>
		<nested>blah </nested>
	</tag>
becomes equivalent to:
	<tag><nested>blah </nested></tag>

Processing is done this way:
	start_tag_cb("tag");
	text = eat_plain_text();
	if (skip_ws_option && is_ws(text))
		; /* nothing */
	else
		text_cb(text);
	start_tag_cb("nested");
	...

You get the idea. This is easy to do.

<dream>
Once all (or most) of the things you can do now with a gtk_widgetname*() 
function could be done setting a GtkArg (uh, sorry, GParam), and Glade
outputs the corresponding .xml file, libglade will reduce to a couple 
hundred lines of code and could be included in gtk+.
</dream>

> > Why not expose the GMarkupAttribute GSList here? There is no reason
> > to copy things that way all the time.
> 
> Copying the strings is easy to avoid, there's a FIXME in there about
> it. I don't want to expose the GSList; I think it's a relatively
> fragile/inconvenient data structure to export. Creating the array
> (g_malloc (sizeof(char*)*n_attributes)) is no big performance hit.

Why not use an array as the implementation in the first place, then?
Using a list is handy, but the code to maintain an array with
g_realloc() is far less than the conversion function you wrote:-)
Note also that you wouldn't need to recreate the array each time
a tag with attributes is seen, just keep it handy in the context.

> > Also, what about a callback for entities? It could be:
> > 
> > 	gchar* (*entity)       (GMarkupParseContext *context,
> > 	                        gchar               *enitity,
> > 							GError              *error,
> > 							gpointer             user_data);
> > 
> > This will be called for non-standard entities and will return the
> > text to substitute in the xml stream (the text will need to be g_free()d).
> > If the callback is not set, issue an error as you do now.
> > 
> 
> I don't want to support user-added entities, it complicates things and
> isn't really useful for the purpose GMarkup is intended to
> serve.

If we allow only entities without tags it's just a conditional
after the strcmp()s for the standard entities:

	if (context->entity) {
		char *text = call_entity_cb(...);
		if (text)
			g_string_append(str, text)
		g_free(text);
	} else
		error_as_usual().

Also, as it seems you already support recursion of 
g_markup_parse_context_parse() to some extent, handling
more complex entities could come at little cost.

lupus

-- 
Paolo Molaro, Open Source Developer, Linuxcare, Inc.
+39.049.8043411 tel, +39.049.8043412 fax
lupus linuxcare com, http://www.linuxcare.com/
Linuxcare. Support for the revolution.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]