@@ -239,6 +239,101 @@ PERLVAR(G, keyword_plugin_mutex, perl_mutex) /* Mutex for PL_keyword_plugin an
239239#endif
240240PERLVARI (G , keyword_plugin , Perl_keyword_plugin_t , Perl_keyword_plugin_standard )
241241
242+ /*
243+ =for apidoc AmnUx|Perl_infix_plugin_t|PL_infix_plugin
244+
245+ B<NOTE:> This API exists entirely for the purpose of making the CPAN module
246+ C<XS::Parse::Infix> work. It is not expected that additional modules will make
247+ use of it; rather, that they should use C<XS::Parse::Infix> to provide parsing
248+ of new infix operators.
249+
250+ Function pointer, pointing at a function used to handle extended infix
251+ operators. The function should be declared as
252+
253+ int infix_plugin_function(pTHX_
254+ char *opname, STRLEN oplen,
255+ struct Perl_custom_infix **infix_ptr)
256+
257+ The function is called from the tokenizer whenever a possible infix operator
258+ is seen. C<opname> points to the operator name in the parser's input buffer,
259+ and C<oplen> gives the I<maximum> number of bytes of it that should be
260+ consumed; it is not null-terminated. The function is expected to examine the
261+ operator name and possibly other state such as L<%^H|perlvar/%^H>, to
262+ determine whether it wants to handle the operator name.
263+
264+ As compared to the single stage of C<PL_keyword_plugin>, parsing of additional
265+ infix operators occurs in three separate stages. This is because of the more
266+ complex interactions it has with the parser, to ensure that operator
267+ precedence rules work correctly. These stages are co-ordinated by the use of
268+ an additional information structure.
269+
270+ If the function wants to handle the infix operator, it must set the variable
271+ pointed to by C<infix_ptr> to the address of a structure that provides this
272+ additional information about the subsequent parsing stages. If it does not,
273+ it should make a call to the next function in the chain.
274+
275+ This structure has the following definition:
276+
277+ struct Perl_custom_infix {
278+ enum Perl_custom_infix_precedence prec;
279+ void (*parse)(pTHX_ SV **opdata,
280+ struct Perl_custom_infix *);
281+ OP *(*build_op)(pTHX_ SV **opdata, OP *lhs, OP *rhs,
282+ struct Perl_custom_infix *);
283+ };
284+
285+ The function must then return an integer giving the number of bytes consumed
286+ by the name of this operator. In the case of an operator whose name is
287+ composed of identifier characters, this must be equal to C<oplen>. In the case
288+ of an operator named by non-identifier characters, this is permitted to be
289+ shorter than C<oplen>, and any additional characters after it will not be
290+ claimed by the infix operator but instead will be consumed by the tokenizer
291+ and parser as normal.
292+
293+ If the optional C<parse> function is provided, it is called immediately by the
294+ parser to let the operator's definition consume any additional syntax from the
295+ source code. This should I<not> be used for normal operand parsing, but it may
296+ be useful when implementing things like parametric operators or meta-operators
297+ that consume more syntax themselves. This function may use the variable
298+ pointed to by C<opdata> to provide an SV containing additional data to be
299+ passed into the C<build_op> function later on.
300+
301+ The information structure gives the operator precedence level in the C<prec>
302+ field. This is used to tell the parser how much of the surrounding syntax
303+ before and after should be considered as operands to the operator.
304+
305+ The tokenizer and parser will then continue to operate as normal until enough
306+ additional input has been parsed to form both the left- and right-hand side
307+ operands to the operator, according to the precedence level. At this point the
308+ C<build_op> function is called, being passed the left- and right-hand operands
309+ as optree fragments. It is expected to combine them into the resulting optree
310+ fragment, which it should return.
311+
312+ After the C<build_op> function has returned, if the variable pointed to by
313+ C<opdata> was set to a non-C<NULL> value, it will then be destroyed by calling
314+ C<SvREFCNT_dec()>.
315+
316+ For thread safety, modules should not set this variable directly.
317+ Instead, use the function L</wrap_infix_plugin>.
318+
319+ However, that all said, the introductory note above still applies. This
320+ variable is provided in core perl only for the benefit of the
321+ C<XS::Parse::Infix> module. That module acts as a central registry for infix
322+ operators, automatically handling things like deparse support and
323+ discovery/reflection, and these abilities only work because it knows all the
324+ registered operators. Other modules should not use this interpreter variable
325+ directly to implement them because then those central features would no longer
326+ work properly.
327+
328+ Furthermore, it is likely that this (experimental) API will be replaced in a
329+ future Perl version by a more complete API that fully implements the central
330+ registry and other semantics currently provided by C<XS::Parse::Infix>, once
331+ the module has had sufficient experimental testing time. This current
332+ mechanism exists only as an interim measure to get to that stage.
333+
334+ =cut
335+ */
336+
242337PERLVARI (G , infix_plugin , Perl_infix_plugin_t , Perl_infix_plugin_standard )
243338
244339PERLVARI (G , op_sequence , HV * , NULL ) /* dump.c */
0 commit comments