Debian Codegraph @

upstream/opensuse-tumbleweed/man3/TAP::Parser::Grammar.3pm

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