MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Lexer.php
Ir para a documentação deste ficheiro.
1
<?php
2
/*
3
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
*
15
* This software consists of voluntary contributions made by many individuals
16
* and is licensed under the LGPL. For more information, see
17
* <http://www.doctrine-project.org>.
18
*/
19
20
namespace
Doctrine\Common
;
21
31
abstract
class
Lexer
32
{
36
private
$tokens = array();
37
41
private
$position = 0;
42
46
private
$peek = 0;
47
51
public
$lookahead
;
52
56
public
$token
;
57
66
public
function
setInput
($input)
67
{
68
$this->tokens = array();
69
$this->
reset
();
70
$this->
scan
($input);
71
}
72
76
public
function
reset
()
77
{
78
$this->lookahead =
null
;
79
$this->token =
null
;
80
$this->
peek
= 0;
81
$this->position = 0;
82
}
83
87
public
function
resetPeek
()
88
{
89
$this->
peek
= 0;
90
}
91
97
public
function
resetPosition
($position = 0)
98
{
99
$this->position = $position;
100
}
101
108
public
function
isNextToken
(
$token
)
109
{
110
return
$this->lookahead[
'type'
] ===
$token
;
111
}
112
124
public
function
moveNext
()
125
{
126
$this->
peek
= 0;
127
$this->token =
$this->lookahead
;
128
$this->lookahead = (isset($this->tokens[$this->position]))
129
? $this->tokens[$this->position++] :
null
;
130
131
return
$this->lookahead !==
null
;
132
}
133
139
public
function
skipUntil
($type)
140
{
141
while
($this->lookahead !==
null
&& $this->lookahead[
'type'
] !== $type) {
142
$this->
moveNext
();
143
}
144
}
145
153
public
function
isA
($value,
$token
)
154
{
155
return
$this->
getType
($value) ===
$token
;
156
}
157
163
public
function
peek
()
164
{
165
if
(isset($this->tokens[$this->position + $this->
peek
])) {
166
return
$this->tokens[$this->position + $this->
peek
++];
167
}
else
{
168
return
null
;
169
}
170
}
171
177
public
function
glimpse
()
178
{
179
$peek = $this->
peek
();
180
$this->
peek
= 0;
181
return
$peek;
182
}
183
189
protected
function
scan
($input)
190
{
191
static
$regex;
192
193
if
( ! isset($regex)) {
194
$regex =
'/('
. implode(
')|('
, $this->
getCatchablePatterns
()) .
')|'
195
. implode(
'|'
, $this->
getNonCatchablePatterns
()) .
'/i'
;
196
}
197
198
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
199
$matches = preg_split($regex, $input, -1, $flags);
200
201
foreach
($matches as $match) {
202
// Must remain before 'value' assignment since it can change content
203
$type = $this->
getType
($match[0]);
204
205
$this->tokens[] = array(
206
'value'
=> $match[0],
207
'type'
=> $type,
208
'position'
=> $match[1],
209
);
210
}
211
}
212
219
public
function
getLiteral
(
$token
)
220
{
221
$className = get_class($this);
222
$reflClass = new \ReflectionClass($className);
223
$constants = $reflClass->getConstants();
224
225
foreach
($constants as $name => $value) {
226
if
($value ===
$token
) {
227
return
$className .
'::'
. $name;
228
}
229
}
230
231
return
$token
;
232
}
233
239
abstract
protected
function
getCatchablePatterns
();
240
246
abstract
protected
function
getNonCatchablePatterns
();
247
254
abstract
protected
function
getType
(&$value);
255
}
Doctrine\Common\Lexer
Definição
Lexer.php:32
Doctrine\Common\Lexer\$token
$token
Definição
Lexer.php:56
Doctrine\Common\Lexer\resetPeek
resetPeek()
Definição
Lexer.php:87
Doctrine\Common\Lexer\moveNext
moveNext()
Definição
Lexer.php:124
Doctrine\Common\Lexer\reset
reset()
Definição
Lexer.php:76
Doctrine\Common\Lexer\skipUntil
skipUntil($type)
Definição
Lexer.php:139
Doctrine\Common\Lexer\isA
isA($value, $token)
Definição
Lexer.php:153
Doctrine\Common\Lexer\getNonCatchablePatterns
getNonCatchablePatterns()
Doctrine\Common\Lexer\isNextToken
isNextToken($token)
Definição
Lexer.php:108
Doctrine\Common\Lexer\getType
getType(&$value)
Doctrine\Common\Lexer\resetPosition
resetPosition($position=0)
Definição
Lexer.php:97
Doctrine\Common\Lexer\getLiteral
getLiteral($token)
Definição
Lexer.php:219
Doctrine\Common\Lexer\scan
scan($input)
Definição
Lexer.php:189
Doctrine\Common\Lexer\$lookahead
$lookahead
Definição
Lexer.php:51
Doctrine\Common\Lexer\setInput
setInput($input)
Definição
Lexer.php:66
Doctrine\Common\Lexer\getCatchablePatterns
getCatchablePatterns()
Doctrine\Common\Lexer\glimpse
glimpse()
Definição
Lexer.php:177
Doctrine\Common\Lexer\peek
peek()
Definição
Lexer.php:163
Doctrine\Common
classes
extensions
doctrine-dbal
Doctrine
Common
Lexer.php
Gerado por
1.10.0