t/probing.xs

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