      
class TestParser: Object {
    const MarkupParser parser = {start, end, text, null, null};
    MarkupParseContext context;
    
    int indent = 0;
    
    construct
    {
        context = new MarkupParseContext(parser, 0, this, null);
    }

    void print_indent()
    {
        for(var i=0; i< indent; i++)
            print("\t");
    }

    public bool parse(string content) throws MarkupError
    {
        return context.parse(content, -1);
    }
    
    void start(MarkupParseContext context, string name, string[] attr_names, string[] attr_values) throws MarkupError
    {
        print_indent();
        print("begin %s {", name);
		for (int i = 0; i < attr_names.length; i++) {
			print("%s: %s", attr_names[i], attr_values[i]);
		}
		print("}\n");
        indent ++;
    }

    void end(MarkupParseContext context, string name) throws MarkupError
    {
        indent --;
        print_indent();
        print("end %s\n", name);
    }

    void text(MarkupParseContext context, string text, size_t text_len) throws MarkupError
    {
        print_indent();
        print("%s\n", text);
    }
}

void main()
{
    var parser = new TestParser();
    try {
        parser.parse("<elm1 attrib = 'hello'><elm2/><elm3>muhehehe</elm3></elm1>");
    }
    catch(Error e) {
        print("%s\n", e.message);
    }
}
