Debian Codegraph @

t/flags.xs

raw
1 /* You may distribute under the terms of either the GNU General Public License
2 * or the Artistic License (the same terms as Perl itself)
3 *
4 * (C) Paul Evans, 2021 -- [email protected]
5 */
6
7 #include "EXTERN.h"
8 #include "perl.h"
9 #include "XSUB.h"
10
11 #include "XSParseKeyword.h"
12
13 static const char hintkey[] = "t::flags/permit";
14
15 static int build_ident(pTHX_ OP **out, XSParseKeywordPiece *arg0, void *hookdata)
16 {
17 *out = newSVOP(OP_CONST, 0, arg0->sv);
18 return KEYWORD_PLUGIN_STMT;
19 }
20
21 static const struct XSParseKeywordHooks hooks_autosemi = {
22 .flags = XPK_FLAG_STMT|XPK_FLAG_AUTOSEMI,
23 .permit_hintkey = hintkey,
24
25 .piece1 = XPK_IDENT,
26 .build1 = &build_ident,
27 };
28
29 static int build_lex_ident(pTHX_ OP **out, XSParseKeywordPiece *arg0, void *hookdata)
30 {
31 SV *sv = newSVpvs("");
32 if(PL_parser->in_my)
33 sv_catpvs(sv, "my ");
34 sv_catsv(sv, arg0->sv);
35 *out = newSVOP(OP_CONST, 0, sv);
36 return KEYWORD_PLUGIN_EXPR;
37 }
38
39 static const struct XSParseKeywordHooks hooks_lex = {
40 .flags = XPK_FLAG_EXPR|XPK_FLAG_PERMIT_LEXICAL,
41 .permit_hintkey = hintkey,
42
43 .piece1 = XPK_IDENT,
44 .build1 = &build_lex_ident,
45 };
46
47 MODULE = t::flags PACKAGE = t::flags
48
49 BOOT:
50 boot_xs_parse_keyword(0);
51
52 register_xs_parse_keyword("flagautosemi", &hooks_autosemi, NULL);
53
54 register_xs_parse_keyword("flaglex", &hooks_lex, NULL);