Graph::Easy::Marpa::Lexer - A Set::FA::Element-based lexer for Graph::Easy
See "Data and Script Interaction" in Graph::Easy::Marpa.
Graph::Easy::Marpa::Lexer provides a Set:FA::Element-based lexer for Graph::Easy-style graph definitions.
Install Graph::Easy::Marpa as you would for any Perl module:
Perl
Run:
cpanm Graph::Easy::Marpa
or run:
sudo cpan Graph::Easy::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
new() is called as my($parser) = Graph::Easy::Marpa::Lexer -> new(k1 => v1, k2 => v2, ...).
new()
my($parser) = Graph::Easy::Marpa::Lexer -> new(k1 => v1, k2 => v2, ...)
It returns a new object of type Graph::Easy::Marpa::Lexer.
Graph::Easy::Marpa::Lexer
Key-value pairs accepted in the parameter list (see corresponding methods for details [e.g. graph()]):
This is the name of the file to write containing the tokens (items) output from Graph::Easy::Marpa::Lexer.
This file can be input to Graph::Easy::Marpa::Parser.
Specify a string for the graph definition.
You are strongly encouraged to surround this string with '...' to protect it from your shell.
See also the 'input_file' key to read the graph from a file.
The 'description' key takes precedence over the 'input_file' key.
Read the graph definition from this file.
See also the 'graph' key to read the graph from the command line.
The whole file is slurped in as 1 graph.
The first lines of the file can start with /^\s*#/, and will be discarded as comments.
Specify a logger object.
To disable logging, just set logger to the empty string.
The default value is an object of type Log::Handler.
This logger is passed to Graph::Easy::Marpa::Lexer::DFA.
This option is only used if Graph::Easy::Marpa:::Lexer or Graph::Easy::Marpa::Parser create an object of type Log::Handler. See Log::Handler::Levels.
The default 'maxlevel' is 'info'. A typical value is 'debug'.
The default 'minlevel' is 'error'.
No lower levels are used.
Calls "report()" to report, via the log, the items recognized by the state machine.
Calls Set::FA::Element.report(). Set min and max log levels to 'info' for this.
Specify which file contains the state transition table.
Default: ''.
The default value means the STT is read from the source code of Graph::Easy::Marpa::Lexer.
Candidate files are '', 'data/default.stt.csv' and 'data/default.stt.ods'.
The type of this file must be specified by the 'type' key.
Note: If you use stt_file => your.stt.ods and type => 'ods', Module::Load's load() will be used to load OpenOffice::OODoc. This module is no longer listed in Build.PL and Makefile.PL as a pre-req, so you will need to install it manually.
Specify the type of the stt_file: '' for internal, csv for CSV, or ods for Open Office Calc spreadsheet.
Default is ''.
This option must be used with the 'stt_file' key.
The [] indicate an optional parameter.
Get or set the name of the CSV file to write containing the tokens which can be parsed by Graph::Easy::Marpa::Parser.
Get or set the name of the file the graph will be read from.
See "get_graph_from_file()".
If the caller has requested a graph be parsed from the command line, with the graph option to new(), get it now.
Called as appropriate by run().
If the caller has requested a graph be parsed from a file, with the file option to new(), get it now.
Get or set the value of the Graph::Easy graph definition string.
Here, the [] indicate an optional parameter.
Get or set the name of the file to read the graph definition from.
See also the description() method.
The value supplied to the description() method takes precedence over the value read from the input file.
Returns a object of type Set::Array, which is an arrayref of items output by the state machine.
See the "FAQ" for details.
Calls $self -> logger -> $level($s).
Get or set the logger object.
Get or set the value used by the logger object.
Read the named CSV file into an arrayref of hashrefs.
Report, via the log, the list of items recognized by the state machine.
Get or set the value which determines whether or not to report the items recognised by the state machine.
Get or set the value which determines whether or not to report the parsed state transition table (STT).
This is the only method the caller needs to call. All parameters are supplied to new().
Returns 0 for success and 1 for failure.
Get or set the name of the file containing the state transition table.
This option is used in conjunction with the type() option.
Get or set the timeout for how long to run the DFA.
Returns an arrayref of cooked tokens. Each element of this arrayref is an arrayref of 2 elements:
If you provide an output file by using the cooked_file option to new(), or the cooked_file() method, the tokens written to that file are exactly the same as the tokens returned by tokens().
E.g.: If the cooked file looks like:
"key","value" left_bracket , [ node_name_id , 'Murrumbeena' right_bracket , ] left_brace , { attribute_name_id , 'color' colon , : attribute_value_id , 'blue' semi_colon , ; right_brace , } ...
then the arrayref will contain:
['left_bracket', '['] ['node_name_id', 'Murrumbeena'] ['right_bracket', ']'] ['left_brace', '{'] ['attribute_name_id', 'color'] ['colon', ':'] ['attribute_value_id', 'blue'] ['semi_colon', ';'] ['right_brace', '}'] ...
If you look at the source code for the run() method in Graph::Easy::Marpa, you'll see this arrayref can be passed directly as the value of the tokens key in the call to Graph::Easy::Marpa::Parser's new().
Get or set the value which determines what type of stt_file is read.
In Graph::Easy::Marpa::Lexer::DFA.
Items are stored in an arrayref. This arrayref is available via the "items()" method.
These items are the same as the arrayref of items returned by the items() method in Graph::Easy::Marpa::Parser, and the same as in Graph::Easy::Marpa::Lexer::DFA.
Each element in the array is a hashref, listed here in alphabetical order by type.
Note: Items are numbered from 1 up.
The attribute name must match /^[a-z][a-z0-9_]*$/.
The attribute value is everything up to the next ';' or '}'.
The name and value are separated by a ':'.
An attribute can belong to a graph, node or an edge. An attribute definition of '{color: red;}' would produce a hashref of:
{ count => $n, name => 'color', type => 'attribute', value => 'red', }
An attribute definition of '{color: red; shape: circle;}' will produce 2 hashrefs, i.e. 2 sequential elements in the arrayref:
{ count => $n, name => 'color', type => 'attribute', value => 'red', } { count => $n, name => 'shape', type => 'attribute', value => 'circle', }
Attribute hashrefs appear in the arrayref immediately after the item (edge, group, node) to which they belong. For groups, this means they appear straight after the hashref whose type is 'pop_subgraph'.
These notes apply to the 4 class names, /^(?:edge|graph|group|node)$/, and all their subclasses.
Note: It does not make sense for a class of 'graph' to have any subclasses.
A class definition of 'edge {color: white}' would produce 2 hashrefs:
{ count => $n, name => 'edge', type => 'class_name', value => '', } { count => $n, name => 'color', type => 'attribute', value => 'white', }
A class definition of 'node.green {color: green; shape: square}' would produce 3 hashrefs:
{ count => $n, name => 'node.green', type => 'class_name', value => '', } { count => $n, name => 'color', type => 'attribute', value => 'green', } { count => $n, name => 'shape', type => 'attribute', value => 'square', }
Class and class attribute hashrefs always appear at the start of the arrayref of items.
An edge definition of '->' would produce a hashref of:
{ count => $n, name => '->', type => 'edge', value => '', }
A node definition of '[Name]' would produce a hashref of:
{ count => $n, name => 'Name', type => 'node', value => '', }
A node can have a definition of '[]', which means it has no name. Such node are called anonymous (or invisible) because while they take up space in the output stream, they have no printable or visible characters in the output stream. See Graph::Easy for details.
Each anonymous node will have at least these 2 attributes:
{ count => $n, name => 'color', type => 'attribute', value => 'invis', } { count => $n, name => 'label', type => 'attribute', value => '', }
You can of course give your anonymous nodes any attributes, but they will be forced to have these 2 attributes.
Node names are case-sensitive.
A group produces 2 hashrefs, one at the start of the group, and one at the end.
A group defnition of '(Solar system: [Mercury] -> [Neptune])' would produce a hashref like this at the start, i.e. when the '(' - just before 'Solar' - is detected in the input stream:
{ count => $n, name => 'Solar system', type => 'push_subgraph', value => '', }
and a hashref like this at the end, i.e. when the ')' - just after '[Neptune]' - is detected:
{ count => $n, name => 'Solar system', type => 'pop_subgraph', value => '', }
The file CHANGES was converted into Changelog.ini by Module::Metadata::Changes.
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
Email the author, or log a bug on RT:
https://rt.cpan.org/Public/Dist/Display.html?Name=Graph::Easy::Marpa.
Graph::Easy::Marpa was written by Ron Savage <ron@savage.net.au> in 2011.
Home page: http://savage.net.au/index.html.
Australian copyright (c) 2011, 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
To install Graph::Easy::Marpa, copy and paste the appropriate command in to your terminal.
cpanm
CPAN shell
perl -MCPAN -e shell install Graph::Easy::Marpa
For more information on module installation, please visit the detailed CPAN module installation guide.