|
| 1 | +=begin pod |
| 2 | +
|
| 3 | + class Match is Capture is Cool { ... } |
| 4 | +
|
| 5 | +C<Match> objects are the result of a regex match. They store |
| 6 | +a reference to the original string (C<.orig>), positional and |
| 7 | +named captures, the start and end of the match in the original |
| 8 | +string, and a payload refered to as I<AST> (abstract syntax tree), |
| 9 | +which can be used to build data structures from complex regexes |
| 10 | +and gramamrs. |
| 11 | +
|
| 12 | +Submatches are also C<Match> objects (or lists of C<Match> objects, |
| 13 | +if the corresponding regex was quantified), so each match object |
| 14 | +can be seen as the root of a tree of match objects. |
| 15 | +
|
| 16 | +=head2 Methods |
| 17 | +
|
| 18 | +=head3 orig |
| 19 | +
|
| 20 | +Returns the original string that the regex was matched against. |
| 21 | +
|
| 22 | +=head3 from |
| 23 | +
|
| 24 | +Returns the index of the starting position of the match. |
| 25 | +
|
| 26 | +=head3 to |
| 27 | +
|
| 28 | +Returns the index of the end position of the match. |
| 29 | +
|
| 30 | +=head3 ast |
| 31 | +
|
| 32 | +Returns the AST (ie payload). |
| 33 | +
|
| 34 | +=head3 Str |
| 35 | +
|
| 36 | +Returns the matched text. |
| 37 | +
|
| 38 | +=head3 caps |
| 39 | +
|
| 40 | +Returns a list of pairs, with the index or submatch name as key and |
| 41 | +the submatches as values. The list is ordered by starting position |
| 42 | +of the submatches. |
| 43 | +
|
| 44 | +=head3 chunks |
| 45 | +
|
| 46 | +Returns a list of pairs, with the index or submatch name as key and |
| 47 | +the submatches as values. The list is ordered by starting position |
| 48 | +of the submatches. |
| 49 | +
|
| 50 | +Those parts of the string that were not matched by submatches are |
| 51 | +interleaved with the other pairs, with the string C<~> as key. |
| 52 | +
|
| 53 | +=head3 list |
| 54 | +
|
| 55 | +Returns a list of positional submatches. |
| 56 | +
|
| 57 | +=head3 hash |
| 58 | +
|
| 59 | +Returns a hash of named submatches. |
| 60 | +
|
| 61 | +=head3 prematch |
| 62 | +
|
| 63 | +Returns the part of the original string in front of the match. |
| 64 | +
|
| 65 | +=head3 postmatch |
| 66 | +
|
| 67 | +Returns the part of the original string behind the match. |
| 68 | +
|
| 69 | +=head3 make |
| 70 | +
|
| 71 | + method make(Match:D: Mu $ast) |
| 72 | +
|
| 73 | +Sets the AST to C<$ast>, and returns it. |
| 74 | +
|
| 75 | +=end pod |
0 commit comments