1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/* You may distribute under the terms of either the GNU General Public License
* or the Artistic License (the same terms as Perl itself)
*
* (C) Paul Evans, 2021 -- leonerd@leonerd.org.uk
*/
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "XSParseKeyword.h"
#include "perl-backcompat.c.inc"
static const char hintkey[] = "t::probing/permit";
static int build_constbool(pTHX_ OP **out, XSParseKeywordPiece *args[], size_t nargs, void *hookdata)
{
*out = newSVOP(OP_CONST, 0, boolSV(args[0]->i));
return KEYWORD_PLUGIN_EXPR;
}
static int build_repeatcount(pTHX_ OP **out, XSParseKeywordPiece *args[], size_t nargs, void *hookdata)
{
*out = newSVOP(OP_CONST, 0, newSViv(args[0]->i ? args[1]->i : 0));
return KEYWORD_PLUGIN_EXPR;
}
static const struct XSParseKeywordHooks hooks_colon = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_COLON ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_literal = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_LITERAL("literal") ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_block = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_BLOCK ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_ident = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_IDENT ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_packagename = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_PACKAGENAME ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_vstring = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_VSTRING ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_choice = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_CHOICE(
XPK_LITERAL("x"),
XPK_LITERAL("z")
) ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_taggedchoice = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_TAGGEDCHOICE(
XPK_LITERAL("x"), XPK_TAG('x'),
XPK_LITERAL("z"), XPK_TAG('z')
) ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_commalist = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []) {
XPK_OPTIONAL( XPK_COMMALIST( XPK_IDENT ) ),
{0},
},
.build = &build_repeatcount,
};
static const struct XSParseKeywordHooks hooks_parens = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_PARENS( XPK_TERMEXPR ) ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_brackets = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_BRACKETS( XPK_TERMEXPR ) ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_braces = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_BRACES( XPK_TERMEXPR ) ),
{0}
},
.build = &build_constbool,
};
static const struct XSParseKeywordHooks hooks_chevrons = {
.permit_hintkey = hintkey,
.pieces = (const struct XSParseKeywordPieceType []){
XPK_OPTIONAL( XPK_CHEVRONS( XPK_IDENT ) ),
{0}
},
.build = &build_constbool,
};
MODULE = t::probing PACKAGE = t::probing
BOOT:
boot_xs_parse_keyword(0);
register_xs_parse_keyword("probecolon", &hooks_colon, NULL);
register_xs_parse_keyword("probeliteral", &hooks_literal, NULL);
register_xs_parse_keyword("probeblock", &hooks_block, NULL);
register_xs_parse_keyword("probeident", &hooks_ident, NULL);
register_xs_parse_keyword("probepackagename", &hooks_packagename, NULL);
register_xs_parse_keyword("probevstring", &hooks_vstring, NULL);
register_xs_parse_keyword("probechoice", &hooks_choice, NULL);
register_xs_parse_keyword("probetaggedchoice", &hooks_taggedchoice, NULL);
register_xs_parse_keyword("probecommalist", &hooks_commalist, NULL);
register_xs_parse_keyword("probeparens", &hooks_parens, NULL);
register_xs_parse_keyword("probebrackets", &hooks_brackets, NULL);
register_xs_parse_keyword("probebraces", &hooks_braces, NULL);
register_xs_parse_keyword("probechevrons", &hooks_chevrons, NULL);
|