This is more in response to Uri's badgering   ;)
than anything else, but for anyone who wanted
to know exactly what the Parse::Nibbler module
returns when it is done successfully parsing,
here's an example.

the test directory contains a grammar that
defines the "McCoy" grammar. when you run the
bones.t test, the last thing it does is Data::Dumper
the parser object.

This is what it looks like. the key point is to 
notice the nesting of rules is reflected in the
nesting of arrays, and each array is blessed with
the name of the corresponding rule
(so you know what the heck it is)

The first rule is "McCoy" which contains everything.
The second rule is "DeclareProfession", which is
a single sentence of Dr. McCoy telling someone that
he's a doctor.
The third rule is "Name", which in this case is the
lexical, "Jim".

This is the data structure that would be returned
by a successful parsing. The idea is that the blessing
is used to indicate what the thing actually is,
and to give a structure to locate methods that
further process the structure, such as "Dump"
or "Format" or whatever you want to do with the text.

The actual sentence parsed was this:
'Dammit Jim, Ima doctor not a Bricklayer!',

Here's the object returned by the parser:

$VAR1 = bless( [
[
  [
    bless( [
      bless( [
        bless( [
                      'Identifier',
                      'Dammit',
                      1,
                      0
                    ], 'Lexical' ),
          bless( [
            bless( [
                               'Identifier',
                               'Jim',
                               1,
                               7
                             ], 'Lexical' )
                   ], 'MyGrammar::Name' ),
          bless( [
                      ',',
                      ',',
                      1,
                      10
                    ], 'Lexical' ),
          bless( [
                      'Identifier',
                      'Ima',
                      1,
                      12
                    ], 'Lexical' ),
          bless( [
                      'Identifier',
                      'doctor',
                      1,
                      16
                    ], 'Lexical' ),
          bless( [
                      'Identifier',
                      'not',
                      1,
                      23
                    ], 'Lexical' ),
          bless( [
                      'Identifier',
                      'a',
                      1,
                      27
                    ], 'Lexical' ),
          bless( [
                      'Identifier',
                      'Bricklayer',
                      1,
                      29
                    ], 'Lexical' ),
          bless( [
                      '!',
                      '!',
                      1,
                      39
                 ], 'Lexical' )
               ], 'MyGrammar::DeclareProfession' )
             ], 'MyGrammar::McCoy' )
           ],



Greg

Reply via email to