The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

Synopsis

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

Description

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()".

Installation

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.

Methods

actions([$action_object])

Here, the [] indicate an optional parameter.

Get or set the action object.

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

characters($characters)

A callback used to accumulate character text within XML tags.

See "text($str)".

encode_booleans($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.

end_element($element)

A callback used to log the closing of a tag.

grammar([$grammar_object])

Here, the [] indicate an optional parameter.

Get or set the grammar object.

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

init_marpa(%args)

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)".

item_count([$new_value])

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.

items()

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).

logger([$log_object])

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().

new()

This method is auto-generated by Moo.

new_item($type, $name, $value)

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

recce([$recognizer_object])

Here, the [] indicate an optional parameter.

Get or set the recognizer object.

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

run_marpa(%args)

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).

start_document()

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

start_element($element)

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()".

text($str)

Accumulates the text belonging to the most recently opened tag.

See "characters($characters)".

test_stack([$text])

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.

Credits

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

Author

MarpaX::Languages::SVG::Parser was written by Ron Savage <ron@savage.net.au> in 2013.

Home page: http://savage.net.au/.

Copyright

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:
        http://www.opensource.org/licenses/index.html