| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "TAP::Parser::Grammar 3perl" |
| 58 |
.TH TAP::Parser::Grammar 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
TAP::Parser::Grammar \- A grammar for the Test Anything Protocol. |
| 65 |
.SH VERSION |
| 66 |
.IX Header "VERSION" |
| 67 |
Version 3.48 |
| 68 |
.SH SYNOPSIS |
| 69 |
.IX Header "SYNOPSIS" |
| 70 |
.Vb 6 |
| 71 |
\& use TAP::Parser::Grammar; |
| 72 |
\& my $grammar = $self\->make_grammar({ |
| 73 |
\& iterator => $tap_parser_iterator, |
| 74 |
\& parser => $tap_parser, |
| 75 |
\& version => 12, |
| 76 |
\& }); |
| 77 |
\& |
| 78 |
\& my $result = $grammar\->tokenize; |
| 79 |
.Ve |
| 80 |
.SH DESCRIPTION |
| 81 |
.IX Header "DESCRIPTION" |
| 82 |
\&\f(CW\*(C`TAP::Parser::Grammar\*(C'\fR tokenizes lines from a TAP::Parser::Iterator and |
| 83 |
constructs TAP::Parser::Result subclasses to represent the tokens. |
| 84 |
.PP |
| 85 |
Do not attempt to use this class directly. It won't make sense. It's mainly |
| 86 |
here to ensure that we will be able to have pluggable grammars when TAP is |
| 87 |
expanded at some future date (plus, this stuff was really cluttering the |
| 88 |
parser). |
| 89 |
.SH METHODS |
| 90 |
.IX Header "METHODS" |
| 91 |
.SS "Class Methods" |
| 92 |
.IX Subsection "Class Methods" |
| 93 |
\fR\f(CI\*(C`new\*(C'\fR\fI\fR |
| 94 |
.IX Subsection "new" |
| 95 |
.PP |
| 96 |
.Vb 5 |
| 97 |
\& my $grammar = TAP::Parser::Grammar\->new({ |
| 98 |
\& iterator => $iterator, |
| 99 |
\& parser => $parser, |
| 100 |
\& version => $version, |
| 101 |
\& }); |
| 102 |
.Ve |
| 103 |
.PP |
| 104 |
Returns TAP::Parser grammar object that will parse the TAP stream from the |
| 105 |
specified iterator. Both \f(CW\*(C`iterator\*(C'\fR and \f(CW\*(C`parser\*(C'\fR are required arguments. |
| 106 |
If \f(CW\*(C`version\*(C'\fR is not set it defaults to \f(CW12\fR (see "set_version" for more |
| 107 |
details). |
| 108 |
.SS "Instance Methods" |
| 109 |
.IX Subsection "Instance Methods" |
| 110 |
\fR\f(CI\*(C`set_version\*(C'\fR\fI\fR |
| 111 |
.IX Subsection "set_version" |
| 112 |
.PP |
| 113 |
.Vb 1 |
| 114 |
\& $grammar\->set_version(13); |
| 115 |
.Ve |
| 116 |
.PP |
| 117 |
Tell the grammar which TAP syntax version to support. The lowest |
| 118 |
supported version is 12. Although 'TAP version' isn't valid version 12 |
| 119 |
syntax it is accepted so that higher version numbers may be parsed. |
| 120 |
.PP |
| 121 |
\fR\f(CI\*(C`tokenize\*(C'\fR\fI\fR |
| 122 |
.IX Subsection "tokenize" |
| 123 |
.PP |
| 124 |
.Vb 1 |
| 125 |
\& my $token = $grammar\->tokenize; |
| 126 |
.Ve |
| 127 |
.PP |
| 128 |
This method will return a TAP::Parser::Result object representing the |
| 129 |
current line of TAP. |
| 130 |
.PP |
| 131 |
\fR\f(CI\*(C`token_types\*(C'\fR\fI\fR |
| 132 |
.IX Subsection "token_types" |
| 133 |
.PP |
| 134 |
.Vb 1 |
| 135 |
\& my @types = $grammar\->token_types; |
| 136 |
.Ve |
| 137 |
.PP |
| 138 |
Returns the different types of tokens which this grammar can parse. |
| 139 |
.PP |
| 140 |
\fR\f(CI\*(C`syntax_for\*(C'\fR\fI\fR |
| 141 |
.IX Subsection "syntax_for" |
| 142 |
.PP |
| 143 |
.Vb 1 |
| 144 |
\& my $syntax = $grammar\->syntax_for($token_type); |
| 145 |
.Ve |
| 146 |
.PP |
| 147 |
Returns a pre-compiled regular expression which will match a chunk of TAP |
| 148 |
corresponding to the token type. For example (not that you should really pay |
| 149 |
attention to this, \f(CW\*(C`$grammar\->syntax_for(\*(Aqcomment\*(Aq)\*(C'\fR will return |
| 150 |
\&\f(CW\*(C`qr/^#(.*)/\*(C'\fR. |
| 151 |
.PP |
| 152 |
\fR\f(CI\*(C`handler_for\*(C'\fR\fI\fR |
| 153 |
.IX Subsection "handler_for" |
| 154 |
.PP |
| 155 |
.Vb 1 |
| 156 |
\& my $handler = $grammar\->handler_for($token_type); |
| 157 |
.Ve |
| 158 |
.PP |
| 159 |
Returns a code reference which, when passed an appropriate line of TAP, |
| 160 |
returns the lexed token corresponding to that line. As a result, the basic |
| 161 |
TAP parsing loop looks similar to the following: |
| 162 |
.PP |
| 163 |
.Vb 10 |
| 164 |
\& my @tokens; |
| 165 |
\& my $grammar = TAP::Grammar\->new; |
| 166 |
\& LINE: while ( defined( my $line = $parser\->_next_chunk_of_tap ) ) { |
| 167 |
\& for my $type ( $grammar\->token_types ) { |
| 168 |
\& my $syntax = $grammar\->syntax_for($type); |
| 169 |
\& if ( $line =~ $syntax ) { |
| 170 |
\& my $handler = $grammar\->handler_for($type); |
| 171 |
\& push @tokens => $grammar\->$handler($line); |
| 172 |
\& next LINE; |
| 173 |
\& } |
| 174 |
\& } |
| 175 |
\& push @tokens => $grammar\->_make_unknown_token($line); |
| 176 |
\& } |
| 177 |
.Ve |
| 178 |
.SH "TAP GRAMMAR" |
| 179 |
.IX Header "TAP GRAMMAR" |
| 180 |
\&\fBNOTE:\fR This grammar is slightly out of date. There's still some discussion |
| 181 |
about it and a new one will be provided when we have things better defined. |
| 182 |
.PP |
| 183 |
The TAP::Parser does not use a formal grammar because TAP is essentially a |
| 184 |
stream-based protocol. In fact, it's quite legal to have an infinite stream. |
| 185 |
For the same reason that we don't apply regexes to streams, we're not using a |
| 186 |
formal grammar here. Instead, we parse the TAP in lines. |
| 187 |
.PP |
| 188 |
For purposes for forward compatibility, any result which does not match the |
| 189 |
following grammar is currently referred to as |
| 190 |
TAP::Parser::Result::Unknown. It is \fInot\fR a parse error. |
| 191 |
.PP |
| 192 |
A formal grammar would look similar to the following: |
| 193 |
.PP |
| 194 |
.Vb 4 |
| 195 |
\& (* |
| 196 |
\& For the time being, I\*(Aqm cheating on the EBNF by allowing |
| 197 |
\& certain terms to be defined by POSIX character classes by |
| 198 |
\& using the following syntax: |
| 199 |
\& |
| 200 |
\& digit ::= [:digit:] |
| 201 |
\& |
| 202 |
\& As far as I am aware, that\*(Aqs not valid EBNF. Sue me. I |
| 203 |
\& didn\*(Aqt know how to write "char" otherwise (Unicode issues). |
| 204 |
\& Suggestions welcome. |
| 205 |
\& *) |
| 206 |
\& |
| 207 |
\& tap ::= version? { comment | unknown } leading_plan lines |
| 208 |
\& | |
| 209 |
\& lines trailing_plan {comment} |
| 210 |
\& |
| 211 |
\& version ::= \*(AqTAP version \*(Aq positiveInteger {positiveInteger} "\en" |
| 212 |
\& |
| 213 |
\& leading_plan ::= plan skip_directive? "\en" |
| 214 |
\& |
| 215 |
\& trailing_plan ::= plan "\en" |
| 216 |
\& |
| 217 |
\& plan ::= \*(Aq1..\*(Aq nonNegativeInteger |
| 218 |
\& |
| 219 |
\& lines ::= line {line} |
| 220 |
\& |
| 221 |
\& line ::= (comment | test | unknown | bailout ) "\en" |
| 222 |
\& |
| 223 |
\& test ::= status positiveInteger? description? directive? |
| 224 |
\& |
| 225 |
\& status ::= \*(Aqnot \*(Aq? \*(Aqok \*(Aq |
| 226 |
\& |
| 227 |
\& description ::= (character \- (digit | \*(Aq#\*(Aq)) {character \- \*(Aq#\*(Aq} |
| 228 |
\& |
| 229 |
\& directive ::= todo_directive | skip_directive |
| 230 |
\& |
| 231 |
\& todo_directive ::= hash_mark \*(AqTODO\*(Aq \*(Aq \*(Aq {character} |
| 232 |
\& |
| 233 |
\& skip_directive ::= hash_mark \*(AqSKIP\*(Aq \*(Aq \*(Aq {character} |
| 234 |
\& |
| 235 |
\& comment ::= hash_mark {character} |
| 236 |
\& |
| 237 |
\& hash_mark ::= \*(Aq#\*(Aq {\*(Aq \*(Aq} |
| 238 |
\& |
| 239 |
\& bailout ::= \*(AqBail out!\*(Aq {character} |
| 240 |
\& |
| 241 |
\& unknown ::= { (character \- "\en") } |
| 242 |
\& |
| 243 |
\& (* POSIX character classes and other terminals *) |
| 244 |
\& |
| 245 |
\& digit ::= [:digit:] |
| 246 |
\& character ::= ([:print:] \- "\en") |
| 247 |
\& positiveInteger ::= ( digit \- \*(Aq0\*(Aq ) {digit} |
| 248 |
\& nonNegativeInteger ::= digit {digit} |
| 249 |
.Ve |
| 250 |
.SH SUBCLASSING |
| 251 |
.IX Header "SUBCLASSING" |
| 252 |
Please see "SUBCLASSING" in TAP::Parser for a subclassing overview. |
| 253 |
.PP |
| 254 |
If you \fIreally\fR want to subclass TAP::Parser's grammar the best thing to |
| 255 |
do is read through the code. There's no easy way of summarizing it here. |
| 256 |
.SH "SEE ALSO" |
| 257 |
.IX Header "SEE ALSO" |
| 258 |
TAP::Object, |
| 259 |
TAP::Parser, |
| 260 |
TAP::Parser::Iterator, |
| 261 |
TAP::Parser::Result, |