-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
157 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
/composer.lock | ||
/phpunit.xml | ||
/.phpunit.result.cache | ||
/phpcs.xml | ||
/.phpcs-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Common\Lexer; | ||
|
||
use ReflectionClass; | ||
use const PREG_SPLIT_DELIM_CAPTURE; | ||
use const PREG_SPLIT_NO_EMPTY; | ||
use const PREG_SPLIT_OFFSET_CAPTURE; | ||
use function implode; | ||
use function in_array; | ||
use function preg_split; | ||
use function sprintf; | ||
use function substr; | ||
|
||
/** | ||
* Base class for writing simple lexers, i.e. for creating small DSLs. | ||
* | ||
* @since 2.0 | ||
* @author Guilherme Blanco <[email protected]> | ||
* @author Jonathan Wage <[email protected]> | ||
* @author Roman Borschel <[email protected]> | ||
*/ | ||
abstract class AbstractLexer | ||
{ | ||
|
@@ -47,19 +37,19 @@ abstract class AbstractLexer | |
* | ||
* @var array | ||
*/ | ||
private $tokens = array(); | ||
private $tokens = []; | ||
|
||
/** | ||
* Current lexer position in input string. | ||
* | ||
* @var integer | ||
* @var int | ||
*/ | ||
private $position = 0; | ||
|
||
/** | ||
* Current peek of current lexer position. | ||
* | ||
* @var integer | ||
* @var int | ||
*/ | ||
private $peek = 0; | ||
|
||
|
@@ -90,7 +80,7 @@ abstract class AbstractLexer | |
public function setInput($input) | ||
{ | ||
$this->input = $input; | ||
$this->tokens = array(); | ||
$this->tokens = []; | ||
|
||
$this->reset(); | ||
$this->scan($input); | ||
|
@@ -104,9 +94,9 @@ public function setInput($input) | |
public function reset() | ||
{ | ||
$this->lookahead = null; | ||
$this->token = null; | ||
$this->peek = 0; | ||
$this->position = 0; | ||
$this->token = null; | ||
$this->peek = 0; | ||
$this->position = 0; | ||
} | ||
|
||
/** | ||
|
@@ -122,7 +112,7 @@ public function resetPeek() | |
/** | ||
* Resets the lexer position on the input to the given position. | ||
* | ||
* @param integer $position Position to place the lexical scanner. | ||
* @param int $position Position to place the lexical scanner. | ||
* | ||
* @return void | ||
*/ | ||
|
@@ -134,7 +124,7 @@ public function resetPosition($position = 0) | |
/** | ||
* Retrieve the original lexer's input until a given position. | ||
* | ||
* @param integer $position | ||
* @param int $position | ||
* | ||
* @return string | ||
*/ | ||
|
@@ -146,37 +136,37 @@ public function getInputUntilPosition($position) | |
/** | ||
* Checks whether a given token matches the current lookahead. | ||
* | ||
* @param integer|string $token | ||
* @param int|string $token | ||
* | ||
* @return boolean | ||
* @return bool | ||
*/ | ||
public function isNextToken($token) | ||
{ | ||
return null !== $this->lookahead && $this->lookahead['type'] === $token; | ||
return $this->lookahead !== null && $this->lookahead['type'] === $token; | ||
} | ||
|
||
/** | ||
* Checks whether any of the given tokens matches the current lookahead. | ||
* | ||
* @param array $tokens | ||
* | ||
* @return boolean | ||
* @return bool | ||
*/ | ||
public function isNextTokenAny(array $tokens) | ||
{ | ||
return null !== $this->lookahead && in_array($this->lookahead['type'], $tokens, true); | ||
return $this->lookahead !== null && in_array($this->lookahead['type'], $tokens, true); | ||
} | ||
|
||
/** | ||
* Moves to the next token in the input string. | ||
* | ||
* @return boolean | ||
* @return bool | ||
*/ | ||
public function moveNext() | ||
{ | ||
$this->peek = 0; | ||
$this->token = $this->lookahead; | ||
$this->lookahead = (isset($this->tokens[$this->position])) | ||
$this->peek = 0; | ||
$this->token = $this->lookahead; | ||
$this->lookahead = isset($this->tokens[$this->position]) | ||
? $this->tokens[$this->position++] : null; | ||
|
||
return $this->lookahead !== null; | ||
|
@@ -199,10 +189,10 @@ public function skipUntil($type) | |
/** | ||
* Checks if given value is identical to the given token. | ||
* | ||
* @param mixed $value | ||
* @param integer|string $token | ||
* @param mixed $value | ||
* @param int|string $token | ||
* | ||
* @return boolean | ||
* @return bool | ||
*/ | ||
public function isA($value, $token) | ||
{ | ||
|
@@ -218,9 +208,9 @@ public function peek() | |
{ | ||
if (isset($this->tokens[$this->position + $this->peek])) { | ||
return $this->tokens[$this->position + $this->peek++]; | ||
} else { | ||
return null; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
|
@@ -230,8 +220,9 @@ public function peek() | |
*/ | ||
public function glimpse() | ||
{ | ||
$peek = $this->peek(); | ||
$peek = $this->peek(); | ||
$this->peek = 0; | ||
|
||
return $peek; | ||
} | ||
|
||
|
@@ -246,7 +237,7 @@ protected function scan($input) | |
{ | ||
static $regex; | ||
|
||
if ( ! isset($regex)) { | ||
if (! isset($regex)) { | ||
$regex = sprintf( | ||
'/(%s)|%s/%s', | ||
implode(')|(', $this->getCatchablePatterns()), | ||
|
@@ -255,37 +246,37 @@ protected function scan($input) | |
); | ||
} | ||
|
||
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE; | ||
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE; | ||
$matches = preg_split($regex, $input, -1, $flags); | ||
|
||
if (false === $matches) { | ||
if ($matches === false) { | ||
// Work around https://bugs.php.net/78122 | ||
$matches = array(array($input, 0)); | ||
$matches = [[$input, 0]]; | ||
} | ||
|
||
foreach ($matches as $match) { | ||
// Must remain before 'value' assignment since it can change content | ||
$type = $this->getType($match[0]); | ||
|
||
$this->tokens[] = array( | ||
$this->tokens[] = [ | ||
'value' => $match[0], | ||
'type' => $type, | ||
'position' => $match[1], | ||
); | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the literal for a given token. | ||
* | ||
* @param integer|string $token | ||
* @param int|string $token | ||
* | ||
* @return integer|string | ||
* @return int|string | ||
*/ | ||
public function getLiteral($token) | ||
{ | ||
$className = get_class($this); | ||
$reflClass = new \ReflectionClass($className); | ||
$className = static::class; | ||
$reflClass = new ReflectionClass($className); | ||
$constants = $reflClass->getConstants(); | ||
|
||
foreach ($constants as $name => $value) { | ||
|
@@ -326,7 +317,7 @@ abstract protected function getNonCatchablePatterns(); | |
* | ||
* @param string $value | ||
* | ||
* @return integer|string|null | ||
* @return int|string|null | ||
*/ | ||
abstract protected function getType(&$value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0"?> | ||
<ruleset> | ||
<arg name="basepath" value="."/> | ||
<arg name="extensions" value="php"/> | ||
<arg name="parallel" value="80"/> | ||
<arg name="cache" value=".phpcs-cache"/> | ||
<arg name="colors" /> | ||
|
||
<!-- Ignore warnings and show progress of the run --> | ||
<arg value="np"/> | ||
|
||
<file>lib</file> | ||
<file>tests</file> | ||
|
||
<rule ref="Doctrine"> | ||
<!-- Traversable type hints often end up as mixed[], so we skip them for now --> | ||
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification" /> | ||
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification" /> | ||
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification" /> | ||
|
||
<!-- Will cause BC breaks to method signatures - disabled for now --> | ||
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" /> | ||
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" /> | ||
|
||
<!-- Disabled to avoid class renaming - to be handled in a separate PR --> | ||
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming" /> | ||
</rule> | ||
</ruleset> |
Oops, something went wrong.