View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Greg London > Parse-Gnaw > Parse::Gnaw::Blocks::Letter



Annotate this POD

View/Report Bugs
Module Version: 0.001   Source  


Parse::Gnaw::Blocks::Letter - a linked list element that holds a single scalar payload.


This is the constructor for a letter object, which is part of a LinkedListObject

        Parse::Gnaw::Blocks::Letter->new($linkedlist, $lettervalue, $letterlocation);

Linkedlist is the linkedlist object that contains this letter. Lettervalue is probably a single character like 'b'. Letterlocation is a string that describes where the letter originaly came from (filename/linenum).


This is a subroutine. Do NOT call this as a method. This will allow it to handle undef values.

        my $retval = get_raw_address($letterobj);

Given a letter object, get the string that looks like


and return something like



print out a formatted version of letter object.


if a LETTER needs more letters, then call this and we'll have the linked list get more letters. Note that $which will be either NEXTSTART or NEXTCONN

Connections verus Next Starting Position If we want to parse a 2-D array of text, we have to step through each starting position and try to match the regular expression to the string. The regular expression can match through any connection between letters.

For example, a simple 2D list could be interconnected vertically and horizontally like this:

1---2---3 | | | | | | | | | 4---5---6 | | | | | | | | | 7---8---9

Or it could be connected on diagonals as well:

1---2---3 |\ /|\ /| | X | X | |/ \|/ \| 4---5---6 |\ /|\ /| | X | X | |/ \|/ \| 7---8---9

As we try to fit a regular expression to the linked list, we will follow the CONNECTIONS to figure out what letters are in sequential order.

As we parse, if we're at letter "3", this can connect to 2, 6, and possibly 5. But if starting from "3" does not yeild a match, then we need to move to the next starting position, which could be "4". 4 doesn't connect to 3, but it is the next starting position after 3.

simple 3D list might be connected horizontally and vertically like this:

1----2----3 |\ |\ |\ | 4--+-5--+-6 | | | | | | 7-+--8-+--9 | \| \| \| a----b----c

The "starting position" order could be 1->2->3->4->5->6->7->8->9->a->b->c

Note that 3 is not CONNECTED to 4, but if we try 3 as a starting position and it fails, then after 3 the NEXT STARTING POSITION is 4.

The NextStartingPosition and the ConnectionsBetweenLetters are two different concepts that are built into the data structures of the linked list and the letters.

And they are accessed through several methods:


We can create a connection between two letters with: link_two_letters_via_interconnection And we can get the next connection with: next_connection

Starting Positions:

We can create a link between letters for starting connections with: link_two_letters_via_next_start We can traverse from one starting position to the next with: advance_start_position



Create a link so that after $first, the next starting position is $second.


Advance (move) the starting position to the next spot.

        my $second = $first->advance_start_position();

We tried to match the regular expression starting from $first, but it didn't match. So, now we want to advance to the $second starting position and try from there.

If nextstart points to end or null or whatever, then get more letters.



Create a linkage between $first and $second so that they are INTERCONNECTED to be treated as sequential letters for parsing purposes.

The $axis defaults to 0. It represents whatever axis your linked list structure needs. For example, one axis could be the "vertical" axis. In that example, $first could be thought of as being "up" from $second. And $second could be thought of as "down" from $first.


        my $next_letter = $curr_letter->advance_to_next_connection($overalldirectionforrule);

We are at $curr_letter, trying to fit the regular expression to string. The next letter will be returned by advance_to_next_connection($axis) where axis is which index into the array to look for the connection.


return a list of possible letters to try based on parsing connections array for this letter and any other rules you want to use for your grammar.

By default, this class method will return an array of any connected letter that is not already consumed.

You can override this behaviour by redefining the method to do whatever you want. You could, for example, require that the connections only go in a straight line. Or you could, as a counter example, allow any connection, including letters that have been marked as "consumed" and allow them to be used again and again.

You might even allow the current letter to be used multiple times for multiple rules without advancing.


delete this letter and all previous letters

work your way back until we get to the first_start position.

Note: this assumes that object connections are symmetrical.

if A connects to B at dimension 3, then B connects to B at dimension 3 in the opposite direction.

syntax highlighting: