Debian Codegraph @

README

raw
1 NAME
2
3 XS::Parse::Keyword - XS functions to assist in parsing keyword syntax
4
5 DESCRIPTION
6
7 This module provides some XS functions to assist in writing syntax
8 modules that provide new perl-visible syntax, primarily for authors of
9 keyword plugins using the PL_keyword_plugin hook mechanism. It is
10 unlikely to be of much use to anyone else; and highly unlikely to be
11 any use when writing perl code using these. Unless you are writing a
12 keyword plugin using XS, this module is not for you.
13
14 This module is also currently experimental, and the design is still
15 evolving and subject to change. Later versions may break ABI
16 compatibility, requiring changes or at least a rebuild of any module
17 that depends on it.
18
19 XS FUNCTIONS
20
21 boot_xs_parse_keyword
22
23 void boot_xs_parse_keyword(double ver);
24
25 Call this function from your BOOT section in order to initialise the
26 module and parsing hooks.
27
28 ver should either be 0 or a decimal number for the module version
29 requirement; e.g.
30
31 boot_xs_parse_keyword(0.14);
32
33 register_xs_parse_keyword
34
35 void register_xs_parse_keyword(const char *keyword,
36 const struct XSParseKeywordHooks *hooks, void *hookdata);
37
38 This function installs a set of parsing hooks to be associated with the
39 given keyword. Such a keyword will then be handled automatically by a
40 keyword parser installed by XS::Parse::Keyword itself.
41
42 PARSE HOOKS
43
44 The XSParseKeywordHooks structure provides the following hook stages,
45 which are invoked in the given order.
46
47 flags
48
49 The following flags are defined:
50
51 XPK_FLAG_EXPR
52
53 The parse or build function is expected to return
54 KEYWORD_PLUGIN_EXPR.
55
56 XPK_FLAG_STMT
57
58 The parse or build function is expected to return
59 KEYWORD_PLUGIN_STMT.
60
61 These two flags are largely for the benefit of giving static
62 information at registration time to assist static parsing or other
63 related tasks to know what kind of grammatical element this keyword
64 will produce.
65
66 XPK_FLAG_AUTOSEMI
67
68 The syntax forms a complete statement, which should be followed by a
69 statement separator semicolon (;). This semicolon is optional at the
70 end of a block.
71
72 The semicolon, if present, will be consumed automatically.
73
74 XPK_FLAG_BLOCKSCOPE
75
76 The entire parse and build process will be wrapped in a pair of
77 block_start() and block_end() calls. This ensures that, for example,
78 any newly-introduced lexical variables do not escape from the scope
79 of the syntax created by the keyword.
80
81 XPK_FLAG_PERMIT_LEXICAL
82
83 The keyword permits a prefixed my, for the author to indicate that it
84 should have lexical effect. Typically this would only make sense for
85 keywords that declare some new named entity, where normally that
86 keyword's entity is named in the symbol table instead.
87
88 At parse and build time, this fact will be indicated by
89 PL_parser->in_my being set to the KEY_my value, rather than its usual
90 zero.
91
92 This flag is silently ignored on versions of Perl before 5.16,
93 because on earlier versions the my prefix-detecting workaround causes
94 seemingly-unrelated parse failures in utf8.pm.
95
96 The permit Stage
97
98 const char *permit_hintkey;
99 bool (*permit) (pTHX_ void *hookdata);
100
101 Called by the installed keyword parser hook which is used to handle
102 keywords registered by "register_xs_parse_keyword".
103
104 As a shortcut for the common case, the permit_hintkey may point to a
105 string to look up from the hints hash. If the given key name is not
106 found in the hints hash then the keyword is not permitted. If the key
107 is present then the permit function is invoked as normal.
108
109 If not rejected by a hint key that was not found in the hints hash, the
110 function part of the stage is called next and should inspect whether
111 the keyword is permitted at this time perhaps by inspecting other
112 lexical clues, and return true only if the keyword is permitted.
113
114 Both the string and the function are optional. Either or both may be
115 present. If neither is present then the keyword is always permitted -
116 which is likely not what you wanted to do.
117
118 The check Stage
119
120 void (*check)(pTHX_ void *hookdata);
121
122 Invoked once the keyword has been permitted. If present, this hook
123 function can check the surrounding lexical context, state, or other
124 information and throw an exception if it is unhappy that the keyword
125 should apply in this position.
126
127 The parse Stage
128
129 This stage is invoked once the keyword has been checked, and actually
130 parses the incoming text into an optree. It is implemented by calling
131 the first of the following function pointers which is not NULL. The
132 invoked function may optionally build an optree to represent the parsed
133 syntax, and place it into the variable addressed by out. If it does
134 not, then a simple OP_NULL will be constructed in its place.
135
136 lex_read_space() is called both before and after this stage is invoked,
137 so in many simple cases the hook function itself does not need to
138 bother with it.
139
140 int (*parse)(pTHX_ OP **out, void *hookdata);
141
142 If present, this should consume text from the parser buffer by invoking
143 lex_* or parse_* functions and eventually return a KEYWORD_PLUGIN_*
144 result value.
145
146 This is the most generic and powerful of the options, but requires the
147 most amount of implementation work.
148
149 int (*build)(pTHX_ OP **out, XSParseKeywordPiece *args[], size_t nargs, void *hookdata);
150
151 If parse is not present, this is called instead after parsing a
152 sequence of arguments, of types given by the pieces field; which should
153 be a zero- terminated array of piece types.
154
155 This alternative is somewhat less generic and powerful than providing
156 parse yourself, but involves much less parsing work and is shorter and
157 easier to implement.
158
159 int (*build1)(pTHX_ OP **out, XSParseKeywordPiece *arg0, void *hookdata);
160
161 If neither parse nor build are present, this is called as a simpler
162 variant of build when only a single argument is required. It takes its
163 type from the piece1 field instead.
164
165 PIECES AND PIECE TYPES
166
167 When using the build or build1 alternatives for the parse phase, the
168 actual syntax is parsed automatically by this module, according to the
169 specification given by the pieces or piece1 field. The result of that
170 parsing step is placed into the args or arg0 parameter to the invoked
171 function, using a struct type consisting of the following fields:
172
173 typedef struct {
174 union {
175 OP *op;
176 CV *cv;
177 SV *sv;
178 int i;
179 struct {
180 SV *name;
181 SV *value;
182 } attr;
183 PADOFFSET padix;
184 struct XSParseInfixInfo *infix;
185 };
186 int line;
187 } XSParseKeywordPiece;
188
189 Which field of the anonymous union is set depends on the type of the
190 piece. The line field contains the line number of the source file where
191 parsing of that piece began.
192
193 Some piece types are "atomic", whose definition is self-contained.
194 Others are structural, defined in terms of inner pieces. Together these
195 form an entire tree-shaped definition of the syntax that the keyword
196 expects to find.
197
198 Atomic types generally provide exactly one argument into the list of
199 args (with the exception of literal matches, which do not provide
200 anything). Structural types may provide an initial argument themselves,
201 followed by a list of the values of each sub-piece they contained
202 inside them. Thus, while the data structure defining the syntax shape
203 is a tree, the argument values it parses into is passed as a flat array
204 to the build function.
205
206 Some structural types need to be able to determine whether or not
207 syntax relating some optional part of them is present in the incoming
208 source text. In this case, the pieces relating to those optional parts
209 must support "probing". This ability is also noted below.
210
211 Many of the atomic piece types have a variant which is optional; if the
212 given input does not look like the expected syntax for the piece type
213 then an _OPT-suffixed version of the type will instead yield NULL in
214 its result pointer.
215
216 The type of each piece should be one of the following macro values.
217
218 XPK_BLOCK
219
220 atomic, can probe, emits op.
221
222 XPK_BLOCK
223
224 A brace-delimited block of code is expected, passed as an optree in the
225 op field. This will be parsed as a block within the current function
226 scope.
227
228 This can be probed by checking for the presence of an open-brace ({)
229 character.
230
231 Be careful defining grammars with this because an open-brace is also a
232 valid character to start a term expression, for example. Given a choice
233 between XPK_BLOCK and XPK_TERMEXPR, either of them could try to consume
234 such code as
235
236 { 123, 456 }
237
238 XPK_BLOCK_VOIDCTX, XPK_BLOCK_SCALARCTX, XPK_BLOCK_LISTCTX
239
240 Variants of XPK_BLOCK which wrap a void, scalar or list-context scope
241 around the block.
242
243 XPK_PREFIXED_BLOCK
244
245 structural, emits op.
246
247 XPK_PREFIXED_BLOCK(pieces ...)
248
249 Some pieces are expected, followed by a brace-delimited block of code,
250 which is passed as an optree in the op field. The prefix pieces are
251 parsed first, and their results are passed before the block itself.
252
253 The entire sequence, including the prefix items, is contained within a
254 pair of block_start() / block_end() calls. This permits the prefix
255 pieces to introduce new items into the lexical scope of the block - for
256 example by the use of XPK_LEXVAR_MY.
257
258 A call to intro_my() is automatically made at the end of the prefix
259 pieces, before the block itself is parsed, ensuring any new lexical
260 variables are now visible.
261
262 In addition, the following extra piece types are recognised here:
263
264 XPK_SETUP
265
266 void setup(pTHX_ void *hookdata);
267
268 XPK_SETUP(&setup)
269
270 atomic, emits nothing.
271
272 This piece type runs a function given by pointer. Typically this
273 function may be used to introduce new lexical state into the parser,
274 or in some other way have some side-effect on the parsing context of
275 the block to be parsed.
276
277 XPK_PREFIXED_BLOCK_ENTERLEAVE
278
279 A variant of XPK_PREFIXED_BLOCK which additionally wraps the entire
280 parsing operation, including the block_start(), block_end() and any
281 calls to XPK_SETUP functions, within a ENTER/LEAVE pair.
282
283 This should not make a difference to the standard parser pieces
284 provided here, but may be useful behaviour for the code in the setup
285 function, especially if it wishes to modify parser state and use the
286 savestack to ensure it is restored again when parsing has finished.
287
288 XPK_ANONSUB
289
290 atomic, emits cv.
291
292 A brace-delimited block of code is expected, and assembled into the
293 body of a new anonymous subroutine. This will be passed as a protosub
294 CV in the cv field.
295
296 XPK_STAGED_ANONSUB
297
298 XPK_STAGED_ANONSUB(stages ...)
299
300 structural, emits cv.
301
302 A variant of XPK_ANONSUB which accepts additional function pointers to
303 be invoked at various points during parsing and compilation. These can
304 be used to interrupt the normal parsing in a manner similar to
305 XS::Parse::Sublike, though currently somewhat less flexibly.
306
307 The stages list may contain elements of the following types. Not every
308 stage must be present, but any that are present must be in the
309 following order. Multiple copies of each stage are permitted; they are
310 invoked in the written order, with parser code happening inbetween.
311
312 XPK_ANONSUB_PREPARE
313
314 XPK_ANONSUB_PREPARE(&callback)
315
316 atomic, emits nothing.
317
318 Invokes the callback before start_subparse().
319
320 XPK_ANONSUB_START
321
322 XPK_ANONSUB_START(&callback)
323
324 atomic, emits nothing.
325
326 Invokes the callback after block_start() but before parsing the
327 actual block contents.
328
329 XPK_ANONSUB_END
330
331 OP *op_wrapper_callback(pTHX_ OP *o, void *hookdata);
332
333 XPK_ANONSUB_END(&op_wrapper_callback)
334
335 atomic, emits nothing.
336
337 Invokes the callback after parsing the block contents but before
338 calling block_end(). The callback may modify the optree if required
339 and return a new one.
340
341 XPK_ANONSUB_WRAP
342
343 XPK_ANONSUB_WRAP(&op_wrapper_callback)
344
345 atomic, emits nothing.
346
347 Invokes the callback after block_end() but before passing the optree
348 to newATTRSUB(). The callback may modify the optree if required and
349 return a new one.
350
351 XPK_ARITHEXPR. XPK_ARITHEXPR_OPT
352
353 atomic, emits op.
354
355 XPK_ARITHEXPR
356
357 An arithmetic expression is expected, parsed using parse_arithexpr(),
358 and passed as an optree in the op field.
359
360 XPK_ARITHEXPR_VOIDCTX, XPK_ARITHEXPR_OPT
361
362 XPK_ARITHEXPR_SCALARCTX, XPK_ARITHEXPR_SCALARCTX_OPT
363
364 Variants of XPK_ARITHEXPR which puts the expression in void or scalar
365 context.
366
367 XPK_TERMEXPR, XPK_TERMEXPR_OPT
368
369 atomic, emits op.
370
371 XPK_TERMEXPR
372
373 A term expression is expected, parsed using parse_termexpr(), and
374 passed as an optree in the op field.
375
376 XPK_TERMEXPR_VOIDCTX, XPK_TERMEXPR_VOIDCTX
377
378 XPK_TERMEXPR_SCALARCTX, XPK_TERMEXPR_SCALARCTX_OPT
379
380 Variants of XPK_TERMEXPR which puts the expression in void or scalar
381 context.
382
383 XPK_LISTEXPR, XPK_LISTEXPR_OPT
384
385 atomic, emits op.
386
387 XPK_LISTEXPR
388
389 A list expression is expected, parsed using parse_listexpr(), and
390 passed as an optree in the op field.
391
392 XPK_LISTEXPR_LISTCTX, XPK_LISTEXPR_LISTCTX_OPT
393
394 Variant of XPK_LISTEXPR which puts the expression in list context.
395
396 XPK_PREFIXED_TERMEXPR_ENTERLEAVE, XPK_PREFIXED_LISTEXPR_ENTERLEAVE
397
398 XPK_PREFIXED_TERMEXPR_ENTERLEAVE(pieces ...)
399 XPK_PREFIXED_LISTEXPR_ENTERLEAVE(pieces ...)
400
401 Variants of XPK_TERMEXPR or XPK_LISTEXPR which expect a sequence pieces
402 first before it parses a term expression, similar to how
403 XPK_PREFIXED_BLOCK_ENTERLEAVE works. The entire operation is wrapped in
404 an ENTER/LEAVE pair.
405
406 These are intended just for use of XPK_SETUP pieces as prefixes. Any
407 other pieces which actually parse real input are likely to cause
408 overly-complex, subtle, or outright ambiguous grammars, and should be
409 avoided.
410
411 XPK_IDENT, XPK_IDENT_OPT
412
413 atomic, can probe, emits sv.
414
415 A bareword identifier name is expected, and passed as an SV containing
416 a PV in the sv field. An identifier is not permitted to contain a
417 double colon (::).
418
419 XPK_PACKAGENAME, XPK_PACKAGENAME_OPT
420
421 atomic, can probe, emits sv.
422
423 A bareword package name is expected, and passed as an SV containing a
424 PV in the sv field. A package name is similar to an identifier, except
425 it permits double colons in the middle.
426
427 XPK_LEXVARNAME
428
429 atomic, emits sv.
430
431 XPK_LEXVARNAME(kind)
432
433 A lexical variable name is expected, and passed as an SV containing a
434 PV in the sv field. The kind argument specifies what kinds of variable
435 are permitted, and should be a bitmask of one or more bits from
436 XPK_LEXVAR_SCALAR, XPK_LEXVAR_ARRAY and XPK_LEXVAR_HASH. A convenient
437 shortcut XPK_LEXVAR_ANY permits all three.
438
439 XPK_ATTRIBUTES
440
441 atomic, emits i followed by more args.
442
443 A list of :-prefixed attributes is expected, in the same format as sub
444 or variable attributes. An optional leading : indicates the presence of
445 attributes, then one or more of them are parsed. Attributes may be
446 optionally separated by additional :s, but this is not required.
447
448 Each attribute is expected to be an identifier name, followed by an
449 optional value wrapped in parentheses. Whitespace is NOT permitted
450 between the name and value, as per standard Perl parsing rules.
451
452 :attrname
453 :attrname(value)
454
455 The i field indicates how many attributes were found. That number of
456 additional arguments are then passed, each containing two SVs in the
457 attr.name and attr.value fields. This number may be zero.
458
459 It is not an error for there to be no attributes present, or for the
460 optional colon to be missing. In this case i will be set to zero.
461
462 XPK_VSTRING, XPK_VSTRING_OPT
463
464 atomic, can probe, emits sv.
465
466 A version string is expected, of the form v1.234 including the leading
467 v character. It is passed as a version SV object in the sv field.
468
469 XPK_LEXVAR
470
471 atomic, emits padix.
472
473 XPK_LEXVAR(kind)
474
475 A lexical variable name is expected and looked up from the current pad.
476 The resulting pad index is passed in the padix field. No error happens
477 if the variable is not found; the value NOT_IN_PAD is passed instead.
478
479 The kind argument specifies what kinds of variable are permitted, as
480 per XPK_LEXVARNAME.
481
482 XPK_LEXVAR_MY
483
484 atomic, emits padix.
485
486 XPK_LEXVAR_MY(kind)
487
488 A lexical variable name is expected, added to the current pad as if
489 specified in a my expression, and passed as the pad index in the padix
490 field.
491
492 The kind argument specifies what kinds of variable are permitted, as
493 per XPK_LEXVARNAME.
494
495 XPK_COMMA, XPK_COLON, XPK_EQUALS
496
497 atomic, can probe, emits nothing.
498
499 A literal character (,, : or =) is expected. No argument value is
500 passed.
501
502 XPK_AUTOSEMI
503
504 atomic, emits nothing.
505
506 A literal semicolon (;) as a statement terminator is optionally
507 expected. If the next token is a closing brace to indicate the end of a
508 block, then a semicolon is not required. If anything else is
509 encountered an error will be raised.
510
511 This piece type is the same as specifying the XPK_FLAG_AUTOSEMI. It is
512 useful to put at the end of a sequence that forms part of a choice of
513 syntax, where some forms indicate a statement ending in a semicolon,
514 whereas others may end in a full block that does not need one.
515
516 XPK_INFIX_*
517
518 atomic, can probe, emits infix.
519
520 An infix operator as recognised by XS::Parse::Infix. The returned
521 pointer points to a structure allocated by XS::Parse::Infix describing
522 the operator.
523
524 Various versions of the macro are provided, each using a different
525 selection filter to choose certain available infix operators:
526
527 XPK_INFIX_RELATION // any relational operator
528 XPK_INFIX_EQUALITY // an equality operator like `==` or `eq`
529 XPK_INFIX_MATCH_NOSMART // any sort of "match"-like operator, except smartmatch
530 XPK_INFIX_MATCH_SMART // XPK_INFIX_MATCH_NOSMART plus smartmatch
531
532 XPK_LITERAL
533
534 atomic, can probe, emits nothing.
535
536 XPK_LITERAL("literal")
537
538 A literal string match is expected. No argument value is passed.
539
540 This form should generally be avoided if at all possible, because it is
541 very easy to abuse to make syntaxes which confuse humans and code tools
542 alike. Generally it is best reserved just for the first component of a
543 XPK_OPTIONAL or XPK_REPEATED sequence, to provide a "secondary keyword"
544 that such a repeated item can look out for.
545
546 XPK_KEYWORD
547
548 atomic, can probe, emits nothing.
549
550 XPK_KEYWORD("keyword")
551
552 A literal string match is expected. No argument value is passed.
553
554 This is similar to XPK_LITERAL except that it additionally checks that
555 the following character is not an identifier character. This ensures
556 that the expected keyword-like behaviour is preserved. For example,
557 given the input "keyword", the piece XPK_LITERAL("key") would match it,
558 whereas XPK_KEYWORD("key") would not because of the subsequent "w"
559 character.
560
561 XPK_INTRO_MY
562
563 atomic, emits nothing.
564
565 Calls the core perl intro_my() function immediately. No input is
566 consumed and no output value is generated. This is often useful after
567 XPK_LEXVAR_MY.
568
569 XPK_WARNING
570
571 atomic, emits nothing.
572
573 XPK_WARNING("message here")
574
575 Emits a warning by calling the core perl warn() function on the given
576 string literal. This is equivalent to simply calling warn() from the
577 build function, except that it is emitted immediately at parse time, so
578 line numbering will be more accurate. Also, by placing it as part of an
579 optional or choice sequence, the warning will only be emitted
580 conditionally if that part of the grammar structure is encountered.
581
582 XPK_WARNING_...
583
584 Several variants of XPK_WARNING exist that are conditional on
585 particular warning categories being enabled. These are ones that are
586 likely to be useful at parse time:
587
588 XPK_WARNING_AMBIGUOUS
589 XPK_WARNING_DEPRECATED
590 XPK_WARNING_EXPERIMENTAL
591 XPK_WARNING_PRECEDENCE
592 XPK_WARNING_SYNTAX
593
594 XPK_SEQUENCE
595
596 structural, might support probe, emits nothing.
597
598 XPK_SEQUENCE(pieces ...)
599
600 A structural type which contains a number of pieces. This is normally
601 equivalent to simply placing the pieces in sequence inside their own
602 container, but it is useful inside XPK_CHOICE or XPK_TAGGEDCHOICE.
603
604 An XPK_SEQUENCE supports probe if its first contained piece does; i.e.
605 is transparent to probing.
606
607 XPK_OPTIONAL
608
609 structural, emits i.
610
611 XPK_OPTIONAL(pieces ...)
612
613 A structural type which may expects to find its contained pieces, or is
614 happy not to. This will pass an argument whose i field contains either
615 1 or 0, depending whether the contents were found. The first piece type
616 within must support probe.
617
618 XPK_REPEATED
619
620 structural, emits i.
621
622 XPK_REPEATED(pieces ...)
623
624 A structural type which expects to find zero or more repeats of its
625 contained pieces. This will pass an argument whose i field contains the
626 count of the number of repeats it found. The first piece type within
627 must support probe.
628
629 XPK_CHOICE
630
631 structural, can probe, emits i.
632
633 XPK_CHOICE(options ...)
634
635 A structural type which expects to find one of a number of alternative
636 options. An ordered list of types is provided, all of which must
637 support probe. This will pass an argument whose i field gives the index
638 of the first choice that was accepted. The first option takes the value
639 0.
640
641 As each of the options is interpreted as an alternative, not a
642 sequence, you should use XPK_SEQUENCE if a sequence of multiple items
643 should be considered as a single alternative.
644
645 It is not an error if no choice matches. At that point, the i field
646 will be set to -1.
647
648 If you require a failure message in this case, set the final choice to
649 be of type XPK_FAILURE. This will cause an error message to be printed
650 instead.
651
652 XPK_FAILURE("message string")
653
654 XPK_TAGGEDCHOICE
655
656 structural, can probe, emits i.
657
658 XPK_TAGGEDCHOICE(choice, tag, ...)
659
660 A structural type similar to XPK_CHOICE, except that each choice type
661 is followed by an element of type XPK_TAG which gives an integer. It is
662 that integer value, rather than the positional index of the choice
663 within the list, which is passed in the i field.
664
665 XPK_TAG(value)
666
667 As each of the options is interpreted as an alternative, not a
668 sequence, you should use XPK_SEQUENCE if a sequence of multiple items
669 should be considered as a single alternative.
670
671 XPK_COMMALIST
672
673 structural, might support probe, emits i.
674
675 XPK_COMMALIST(pieces ...)
676
677 A structural type which expects to find one or more repeats of its
678 contained pieces, separated by literal comma (,) characters. This is
679 somewhat similar to XPK_REPEATED, except that it needs at least one
680 copy, needs commas between its items, but does not require that the
681 first contained piece support probe (the comma itself is sufficient to
682 indicate a repeat).
683
684 An XPK_COMMALIST supports probe if its first contained piece does; i.e.
685 is transparent to probing.
686
687 XPK_PARENS
688
689 structural, can probe, emits nothing.
690
691 XPK_PARENS(pieces ...)
692
693 A structural type which expects to find a sequence of pieces, all
694 contained in parentheses as ( ... ). This will pass no extra arguments.
695
696 XPK_ARGS
697
698 structural, emits nothing.
699
700 XPK_ARGS(pieces ...)
701
702 A structural type similar to XPK_PARENS, except that the parentheses
703 themselves are optional; much like Perl's parsing of calls to known
704 functions.
705
706 If parentheses are encountered in the input, they will be consumed by
707 this piece and it will behave identically to XPK_PARENS. If there is no
708 open parenthesis, this piece will behave like XPK_SEQUENCE and consume
709 all the pieces inside it, without expecting a closing parenthesis.
710
711 XPK_BRACKETS
712
713 structural, can probe, emits nothing.
714
715 XPK_BRACKETS(pieces ...)
716
717 A structural type which expects to find a sequence of pieces, all
718 contained in square brackets as [ ... ]. This will pass no extra
719 arguments.
720
721 XPK_BRACES
722
723 structural, can probe, emits nothing.
724
725 XPK_BRACES(pieces ...)
726
727 A structural type which expects to find a sequence of pieces, all
728 contained in braces as { ... }. This will pass no extra arguments.
729
730 Note that this is not necessary to use with XPK_BLOCK or XPK_ANONSUB;
731 those will already consume a set of braces. This is intended for
732 special constrained syntax that should not just accept an arbitrary
733 block.
734
735 XPK_CHEVRONS
736
737 structural, can probe, emits nothing.
738
739 XPK_CHEVRONS(pieces ...)
740
741 A structural type which expects to find a sequence of pieces, all
742 contained in angle brackets as < ... >. This will pass no extra
743 arguments.
744
745 Remember that expressions like a > b are valid term expressions, so the
746 contents of this scope shouldn't allow arbitrary expressions or the
747 closing bracket will be ambiguous.
748
749 XPK_PARENS_OPT, XPK_BRACKETS_OPT, XPK_BRACES_OPT, XPK_CHEVRONS_OPT
750
751 structural, can probe, emits i.
752
753 XPK_PARENS_OPT(pieces ...)
754 XPK_BRACKETS_OPT(pieces ...)
755 XPK_BRACES_OPT(pieces ...)
756 XPK_CHEVERONS_OPT(pieces ...)
757
758 Each of the four contained structure macros above has an optional
759 variant, whose name is suffixed by _OPT. These pass an argument whose i
760 field is either true or false, indicating whether the scope was found,
761 followed by the values from the scope itself.
762
763 This is a convenient shortcut to nesting the scope within a
764 XPK_OPTIONAL macro.
765
766 XPK_..._pieces
767
768 XPK_SEQUENCE_pieces(ptr)
769 XPK_OPTIONAL_pieces(ptr)
770 ...
771
772 For each of the XPK_... macros that takes a variable-length list of
773 pieces, there is a variant whose name ends with ..._pieces, taking a
774 single pointer argument directly. This must point at a const
775 XSParseKeywordPieceType [] array whose final element is the zero
776 element.
777
778 Normally hand-written C code of a fixed grammar would be unlikely to
779 use these forms, but they may be useful in dynamically-generated cases.
780
781 AUTHOR
782
783 Paul Evans <[email protected]>
784