The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

TAPx::Parser::Grammar - A grammar for the original TAP version.

VERSION

Version 0.50_01

DESCRIPTION

TAPx::Parser::Gramamr is actually just a means for identifying individual chunks (usually lines) of TAP. Many of the actual grammar rules are embedded in TAPx::Parser.

Do not attempt to use this class directly. It won't make sense. It's mainly here to ensure that we will be able to have pluggable grammars when TAP is expanded at some future date (plus, this stuff was really cluttering the parser).

If you're looking for an EBNF grammar, see TAPx::Parser.

Class Methods

new

  my $grammar = TAPx::Grammar->new;

Returns TAP grammar object. Future versions may accept a version number.

Instance methods

token_types

  my @types = $grammar->token_types;

Returns the different types of tokens which this grammar can parse.

syntax_for

  my $syntax = $grammar->syntax_for($token_type);

Returns a pre-compiled regular expression which will match a chunk of TAP corresponding to the token type. For example (not that you should really pay attention to this, $grammar->syntax_for('comment') will return qr/^#(.*)/.

handler_for

  my $handler = $grammar->handler_for($token_type);

Returns a code reference which, when passed an appropriate line of TAP, returns the lexed token corresponding to that line. As a result, the basic TAP parsing loop looks similar to the following:

 my @tokens;
 my $grammar = TAPx::Grammar->new;
 LINE: while ( defined( my $line = $parser->_next_chunk_of_tap ) ) {
     foreach my $type ( $grammar->token_types ) {
         my $syntax  = $grammar->syntax_for($type);
         if ( $line =~ $syntax ) {
             my $handler = $grammar->handler_for($type);
             push @tokens => $grammar->$handler($line);
             next LINE;
         }
     }
     push @tokens => $grammar->_make_unknown_token($line);
 }