1 | <?php |
||
12 | abstract class AbstractParser |
||
13 | { |
||
14 | /** |
||
15 | * @var Parser |
||
16 | */ |
||
17 | protected $parser; |
||
18 | |||
19 | /** |
||
20 | * @var string Text being parsed |
||
21 | */ |
||
22 | protected $text; |
||
23 | |||
24 | /** |
||
25 | * @param Parser $parser |
||
26 | */ |
||
27 | public function __construct(Parser $parser) |
||
31 | |||
32 | /** |
||
33 | * Parse given text |
||
34 | * |
||
35 | * @param string $text |
||
36 | * @return string |
||
37 | */ |
||
38 | public function parse($text) |
||
49 | |||
50 | /** |
||
51 | * Execute this parser on stored text |
||
52 | * |
||
53 | * @return void |
||
54 | */ |
||
55 | abstract protected function execute(); |
||
56 | |||
57 | /** |
||
58 | * Test whether given position is preceded by whitespace |
||
59 | * |
||
60 | * @param integer $pos |
||
61 | * @return bool |
||
62 | */ |
||
63 | protected function isAfterWhitespace($pos) |
||
67 | |||
68 | /** |
||
69 | * Test whether given character is alphanumeric |
||
70 | * |
||
71 | * @param string $chr |
||
72 | * @return bool |
||
73 | */ |
||
74 | protected function isAlnum($chr) |
||
78 | |||
79 | /** |
||
80 | * Test whether given position is followed by whitespace |
||
81 | * |
||
82 | * @param integer $pos |
||
83 | * @return bool |
||
84 | */ |
||
85 | protected function isBeforeWhitespace($pos) |
||
89 | |||
90 | /** |
||
91 | * Test whether a length of text is surrounded by alphanumeric characters |
||
92 | * |
||
93 | * @param integer $matchPos Start of the text |
||
94 | * @param integer $matchLen Length of the text |
||
95 | * @return bool |
||
96 | */ |
||
97 | protected function isSurroundedByAlnum($matchPos, $matchLen) |
||
101 | |||
102 | /** |
||
103 | * Test whether given character is an ASCII whitespace character |
||
104 | * |
||
105 | * NOTE: newlines are normalized to LF before parsing so we don't have to check for CR |
||
106 | * |
||
107 | * @param string $chr |
||
108 | * @return bool |
||
109 | */ |
||
110 | protected function isWhitespace($chr) |
||
114 | |||
115 | /** |
||
116 | * Overwrite part of the text with substitution characters ^Z (0x1A) |
||
117 | * |
||
118 | * @param integer $pos Start of the range |
||
119 | * @param integer $len Length of text to overwrite |
||
120 | * @return void |
||
121 | */ |
||
122 | protected function overwrite($pos, $len) |
||
129 | } |