NAME
GraphViz2::Marpa::Lexer::DFA - A Perl lexer for Graphviz dot files
Synopsis
This module is called from GraphViz2::Marpa::Lexer.
Description
GraphViz2::Marpa::Lexer::DFA provides a Set:FA::Element-based lexer for Graphviz (dot) graph definitions.
Demo lexer/parser output: http://savage.net.au/Perl-modules/html/graphviz2.marpa/index.html.
State Transition Table: http://savage.net.au/Perl-modules/html/graphviz2.marpa/default.stt.html.
Command line options and object attributes: http://savage.net.au/Perl-modules/html/graphviz2.marpa/code.attributes.html.
My article on this set of modules: http://www.perl.com/pub/2012/10/an-overview-of-lexing-and-parsing.html.
The Marpa grammar as an image: http://savage.net.au/Ron/html/graphviz2.marpa/Marpa.Grammar.svg. This image was created with Graphviz via GraphViz2.
Installation
Install GraphViz2::Marpa as you would for any Perl
module:
Run:
cpanm GraphViz2::Marpa
or run:
sudo cpan GraphViz2::Marpa
or unpack the distro, and then either:
perl Build.PL
./Build
./Build test
sudo ./Build install
or:
perl Makefile.PL
make (or dmake or nmake)
make test
make install
Constructor and Initialization
new()
is called as my($dfa) = GraphViz2::Marpa::Lexer::DFA -> new(k1 => v1, k2 => v2, ...)
.
It returns a new object of type GraphViz2::Marpa::Lexer::DFA
.
Key-value pairs accepted in the parameter list (see corresponding methods for details [e.g. graph_text()]):
- o graph_text => $string
-
Specify a string for the Graphviz (dot) graph definition.
Default: ''.
- o logger => $logger
-
Specify a logger object to use.
Default: ''.
- o report_stt => $Boolean
-
Log the State Transition Table.
Default: 0.
- o start => $start_state_name
-
Specify the name of the start state.
There is no default. The code dies if a value is not supplied.
- o state => $state_hashref
-
Specify the State Transition Table.
There is no default. The code dies if a value is not supplied.
- o verbose => $Boolean
-
Specify the verbosity level in the call to Set::FA::Element.
The value is only used by the latter module when a logger is not passed to it from the current module.
Default: 0.
Methods
graph_text([$graph])
The [] indicate an optional parameter.
Get or set the Graphviz (dot) graph definition.
'graph_text' is a parameter to "new()". See "Constructor and Initialization" for details.
items()
Returns a object of type Set::Array, which is an arrayref of items output by the DFA.
These items are not the same as the arrayref of items returned by the items() method in GraphViz2::Marpa::Parser, but they are the same as in GraphViz2::Marpa::Lexer.
Each element is a hashref with these keys:
- o count => $integer
-
Just counts the items as 1 .. N.
- o name => $string
-
Not used. Always ''.
- o type => $string
-
The type of the token.
The range of values is documented in the lexer's FAQ item: How is the lexed graph stored in RAM?.
- o value => $string
-
The value of the token from the input stream.
Usage:
my(@items) = @{$dfa -> items};
log($level, $s)
Calls $self -> logger -> $level($s) if ($self -> logger).
logger([$logger_object])
Here, the [] indicate an optional parameter.
Get or set the logger object.
new()
See "Constructor and Initialization" for details on the parameters accepted by "new()".
report_stt([$Boolean])
The [] indicate an optional parameter.
Get or set the value which determines whether or not to log the parsed state transition table (STT).
Calls "report()" in Set::FA::Element. Set min and max log levels to 'info' for this.
'report_stt' is a parameter to "new()". See "Constructor and Initialization" for details.
run()
Runs the state machine.
Afterwards, you call "items()" to retrieve the arrayref of results.
start([$start_state_name])
The [] indicate an optional parameter.
Get or set the name of the state in which the STT starts.
'start' is a parameter to "new()". See "Constructor and Initialization" for details.
state([\%state_hashref])
The [] indicate an optional parameter.
Get or set the hashref defining the STT.
'state' is a parameter to "new()". See "Constructor and Initialization" for details.
verbose([$Boolean])
The [] indicate an optional parameter.
Get or set the verbosity level when calling Set::FA::Element.
'verbose' is a parameter to "new()". See "Constructor and Initialization" for details.
Machine-Readable Change Log
The file CHANGES was converted into Changelog.ini by Module::Metadata::Changes.
Version Numbers
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
Support
Email the author, or log a bug on RT:
https://rt.cpan.org/Public/Dist/Display.html?Name=GraphViz2::Marpa.
Author
GraphViz2::Marpa was written by Ron Savage <ron@savage.net.au> in 2012.
Home page: http://savage.net.au/index.html.
Copyright
Australian copyright (c) 2012, 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, a copy of which is available at:
http://www.opensource.org/licenses/index.html