[Vala] [Genie] Using MarkupParser



I've been trying to learn Genie and it's going OK for the moment. However, I was
trying to translate a Vala example using MarkupParser in GLib and I was coming
unstuck on how to define multiple anonymous functions in a comma-separated
parameter list.

In the Vala example, the code looked like this:

    MarkupParser parser = { 
        // Callback to invoke when the opening tag of an element is seen.
        (ctx, elem, attribute_names, attribute_values) => {
            stdout.printf ("start |%s|\n", elem);
            for (int i = 0; i < attribute_names.length; i++) {
                stdout.printf ("Attribute name: %s, value: %s\n",
                               attribute_names[i], attribute_values[i]);
            }
        },
        // Callback to invoke when the closing tag of an element is seen.
        (ctx, elem) => {
            stdout.printf ("end |%s|\n", elem);
        },
        // Callback to invoke when some text is seen (text is always inside an
element).
        (ctx, text, text_len) => {
            stdout.printf ("text %ld |%s|\n", (long) text_len, text); 
        },
        null, // Callback to invoke for comments, processing instructions and
doctype declarations.
        null  // Callback to invoke when an error occurs.
    };

I attempted with:

    parser : MarkupParser = { def (ctx, elem, attribute_names, attribute_values)
        print("start |%s|\n", elem)
        for i : int = 0 to attribute_names.length
            print("Attribute name: %s, value: %s\n", attribute_names[i],
attribute_values[i]), \
        def (ctx, elem)
            print("end |%s|\n", elem), \
        def (ctx, text, text_len)
            print("text %ld |%s|\n", (long)text_len, text), \
        null, null }

This unfortunately wouldn't compile. I would have been surprised if it did to be
honest. Has anyone done something like this using Genie that could give me some
pointers?

Many thanks in advance,
Patrick




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