forked from doctrine/lexer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request doctrine#77 from greg0ire/allow-enums
- Loading branch information
Showing
5 changed files
with
93 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Common\Lexer; | ||
|
||
use Doctrine\Common\Lexer\AbstractLexer; | ||
|
||
use function in_array; | ||
use function is_numeric; | ||
use function is_string; | ||
|
||
/** @extends AbstractLexer<TokenType> */ | ||
class EnumLexer extends AbstractLexer | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function getCatchablePatterns(): array | ||
{ | ||
return [ | ||
'=|<|>', | ||
'[a-z]+', | ||
'\d+', | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function getNonCatchablePatterns(): array | ||
{ | ||
return [ | ||
'\s+', | ||
'(.)', | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function getType(&$value): TokenType | ||
{ | ||
if (is_numeric($value)) { | ||
$value = (int) $value; | ||
|
||
return TokenType::INT; | ||
} | ||
|
||
if (in_array($value, ['=', '<', '>'])) { | ||
return TokenType::OPERATOR; | ||
} | ||
|
||
if (is_string($value)) { | ||
return TokenType::STRING; | ||
} | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Common\Lexer; | ||
|
||
enum TokenType | ||
{ | ||
case INT; | ||
case OPERATOR; | ||
case STRING; | ||
} |