```{index} single: XS::Parse::Keyword::FromPerl ``` # XS::Parse::Keyword::FromPerl ```{pperl-module-badges} XS::Parse::Keyword::FromPerl ``` New keywords written in Perl: `register_xs_parse_keyword` gives a keyword its syntax as a list of pieces (`XPK_BLOCK`, `XPK_TERMEXPR`, `XPK_PARENS(...)` and the others the module exports) and a `build` sub, which gets the parsed pieces and returns the optree the keyword compiles to, made with Optree::Generate. The keyword is active where its `permit_hintkey` is set in `%^H`, or where its `permit` sub says. This is a native implementation of XS-Parse-Keyword-FromPerl 0.10's `FromPerl.xs` over the XS::Parse::Keyword engine; its `XS/Parse/Keyword/FromPerl.pm` is used unchanged. ## Synopsis ```perl use XS::Parse::Keyword::FromPerl qw(register_xs_parse_keyword KEYWORD_PLUGIN_EXPR); use Optree::Generate qw(newSVOP OP_CONST); BEGIN { register_xs_parse_keyword(hello => permit_hintkey => "main/hello", build => sub { my ($outref) = @_; $$outref = newSVOP(OP_CONST, 0, "Hello, world"); return KEYWORD_PLUGIN_EXPR; }, ); } BEGIN { $^H{"main/hello"}++ } print hello, "\n"; ``` It binds the engine as XS consumers do, by `boot_xs_parse_keyword`. ## Modules - [`XS::Parse::Keyword::FromPerl::_Arg`](FromPerl/_Arg) - [`XS::Parse::Keyword::FromPerl::_Piece`](FromPerl/_Piece) ## Functions ### Keywords #### `register_xs_parse_keyword` `register_xs_parse_keyword($name, %args)`: make `$name` a keyword. The arguments are `pieces` (an array reference of `XPK_*` pieces), `flags` (`XPK_FLAG_EXPR`, `XPK_FLAG_STMT`, `XPK_FLAG_AUTOSEMI`, `XPK_FLAG_BLOCKSCOPE`), `permit_hintkey` and `permit` (where the keyword is active; at least one is needed), `check` (called before parsing), `build` (required: gets a reference to set to the optree, the parsed pieces and `hookdata`, and returns `KEYWORD_PLUGIN_EXPR` or `KEYWORD_PLUGIN_STMT`) and `hookdata`, passed to every hook. ```{toctree} :hidden: :maxdepth: 1 FromPerl/_Arg FromPerl/_Piece ```