1 modulezua.pattern;
2 importstd.bitmanip;
3 4 /** Denotes an error occurring at any point during the execution of a pattern */5 finalclassPatternError : Exception {
6 /** Create a new PatternError */7 this(stringmsg) {
8 super(msg);
9 }
10 }
11 12 /** A pattern */13 finalclassPattern {
14 /** Whether or not to anchor this pattern to the start of the subject string */15 boolstartAnchor;
16 17 /** Whether or not to anchor this pattern to the end of the subject string */18 boolendAnchor;
19 20 /** The items that comprise this pattern */21 PatternItem[] items;
22 }
23 24 /** An abstract pattern item */25 abstractclassPatternItem {}
26 27 /** A capture */28 finalclassCapture : PatternItem {
29 /** The items to match in this capture */30 PatternItem[] items;
31 }
32 33 /** The type of sequence to match*/34 enumSequenceType {
35 Greedy0, /// *36 Greedy1, /// +37 NonGreedy1, /// -38 Maybe, /// ?39 }
40 41 /** Matches a sequence */42 finalclassSequenceMatch : PatternItem {
43 /** The type of sequence to match */44 SequenceTypetype;
45 46 /** The character class to match */47 CharClasscharClass;
48 }
49 50 /** Matches a pattern that has been previously captured */51 finalclassCaptureMatch : PatternItem {
52 /** The 0-based index of the capture to match */53 intindex;
54 }
55 56 /** Matches a balanced string */57 finalclassBalancedMatch : PatternItem {
58 /** The left character */59 charleft;
60 61 /** The right character */62 charright;
63 }
64 65 /** An abstract character class */66 abstractclassCharClass : PatternItem {}
67 68 /** A literal character class */69 finalclassLiteralChar : CharClass {
70 /** The character value to match */71 charvalue;
72 }
73 74 /** Represents a character set */75 finalclassSetClass : CharClass {
76 /** Holds the contents of this set class */77 BitArrayset;
78 79 /** Create a new SetClass */80 this() {
81 set.length = 256;
82 }
83 84 /** Create a new SetClass, including the given characters in the set */85 this(stringstr) {
86 this();
87 foreach (c; str) {
88 set[cast(ubyte)c] = true;
89 }
90 }
91 }