MarpaX::Languages::SVG::Parser::SAXHandler - A nested SVG parser, using XML::SAX and Marpa::R2


See "Synopsis" in MarpaX::Languages::SVG::Parser.


Basically just utility routines for MarpaX::Languages::SVG::Parser. Only used indirectly by XML::SAX.

Specifically, parses an SVG file, and also runs Marpa::R2 to parse the attribute value of some tag/attribute combinations. Each such attribute value has its own Marpa-style BNF.

Outputs to a stack managed by Set::Array. See "items()".


See "Installation" in MarpaX::Languages::SVG::Parser.

Constructor and Initialization

new() is called as my($handler) = MarpaX::Languages::SVG::Parser::SAXHandler -> new(k1 => v1, k2 => v2, ...).

It returns a new object of type MarpaX::Languages::SVG::Parser::SAXHandler.

Key-value pairs accepted in the parameter list (see also the corresponding methods [e.g. "logger([$log_object])"]):

o logger => aLog::HandlerObject

By default, an object of type Log::Handler is created which prints to STDOUT, but given the default, nothing is actually printed.

Default: undef.



Here, the [] indicate an optional parameter.

Get or set the action object.

It is always an instance of MarpaX::Languages::SVG::Parser::Actions.


A callback used to accumulate character text within XML tags.

See "text($str)".


Replaces certain instances of 0 and 1 within $str with 'zero' and 'one' repectively.

This is to stop the integer parser detecting them. Later, the original digits are restored.

Returns $str.


A callback used to log the closing of a tag.


Here, the [] indicate an optional parameter.

Get or set the grammar object.

It is always an instance of Marpa::R2::Scanless::G.


Initialize Marpa using the BNF named with the 'attribute' key in %args, which must be one of the attributes' names handled specially.

Called by "run_marpa(%args)".


Here, the [] indicate an optional parameter.

Get or set the counter used to populate the count key in the hashref in the array of parsed tokens.


Returns the instance of Set::Array which manages the array of hashrefs holding the parsed tokens.

Note: $object -> items -> print returns an array ref.

See "Synopsis" in MarpaX::Languages::SVG::Parser for sample code.

See also "new_item($type, $name, $value)".

log($level, $s)

Calls $self -> logger -> log($level => $s) if ($self -> logger).


Here, the [] indicate an optional parameter.

Get or set the log object.

$log_object must be a Log::Handler-compatible object.

To disable logging, just set logger to the empty string.

Note: logger is a parameter to new().


This method is auto-generated by Moo.

new_item($type, $name, $value)

Pushes another hashref onto the stack managed by $self -> items.


Here, the [] indicate an optional parameter.

Get or set the recognizer object.

It is always an instance of Marpa::R2::Scanless::R.


Run's the instance of Marpa created in the call to "init_marpa(%args)".

%args is a hash of these (key => value) pairs:

o attibute => $string

See the docs for "init_marpa(%args)" above for valid values.

o value => $string

The string to be parsed, using the grammar named with (attribute => $string).


Used as a way of initializing global variables in the action class.


A callback used to log the opening of a tag.

It also checks the names of all the tags attributes, and if there is one which is being treated specially (which is the whole point of this distro), it loads the appropriate Marpa BNF and parses the value of the attribute.

The result of this Marpa-based parse is a set of items pushed onto the stack managed by "items()".


Accumulates the text belonging to the most recently opened tag.

See "characters($characters)".


Manages a stack of text-per-tag, since the text within a tag can be split when the tag contains nested tags. With a stack, the inner tags can all have their own text.


The method decode_result($result) is a re-worked version of MarpaX::Languages::C::AST::Util::Data::Find's process() method.


MarpaX::Languages::SVG::Parser was written by Ron Savage <> in 2013.

Home page:


Australian copyright (c) 2013, Ron Savage.

        All Programs of mine are 'OSI Certified Open Source Software';
        you can redistribute them and/or modify them under the terms of
        The Artistic License 2.0, a copy of which is available at: