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

XS::Parse::Infix::FromPerl - drive XS::Parse::Infix directly from Perl

DESCRIPTION

This module provides a Perl-visible API wrapping (some of) the functionality provided by XS::Parse::Infix, allowing extension infix operators to be added to the Perl language by writing code in Perl itself.

It provides a thin wrapping layer over the XS functions provided by XPI itself. No real attempt is made here to provide further abstractions on top of the API already provided by Perl and XPI, so users will have to be familiar with the overall concepts there as well.

This module is currently experimental, on top of the already-experimental nature of XS::Parse::Infix itself.

FUNCTIONS

register_xs_parse_infix

   register_xs_parse_infix "name" => %args;

Registers a new extension infix operator into the XS::Parse::Infix registry, defined using the given name and arguments.

Takes the following named arguments:

cls => INT

The classification for the operator, which is used both as a filter for the various XS::Parse::Keyword selection macros, and a hint to the Perl parser on the precedence level given to the operator. This should be one of the XPI_CLS_* constants.

wrapper_func_name => STRING

Optional. A string value to use for the "wrapper_func_name".

permit_hintkey => STRING

Optional. A string value to use for the "permit_hintkey".

permit => CODE

Optional. Callback function for the "permit" phase of parsing.

   $ok = $permit->( $hookdata );

When invoked, it is passed a single arugment containing the (optional) hookdata value, and its result should be a boolean scalar.

At least one of permit_hintkey or permit must be provided.

new_op => CODE

Callback function for the "new_op" phase of parsing.

   $op = $new_op->( $flags, $lhs, $rhs, $parsedata, $hookdata );

When invoked, it is passed a flags value, the left-hand and right-hand side operand optree fragments as B::OP references, the parse data (though this will always be undef currently), and the optional hookdata value.

Its result should be the overall optree fragment, again as a B::OP reference, to represent the entire invocation sequence for the operator.

hookdata => SCALAR

Optional. If present, this scalar value is stored by the operator definition and passed into each of the phase callbacks when invoked. If not present then undef will be passed to the callbacks instead.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>