@@ 18-58 (lines=41) @@ | ||
15 | /** |
|
16 | * Class Boundary. |
|
17 | */ |
|
18 | final class Boundary |
|
19 | { |
|
20 | /** |
|
21 | * @param Tokenizer $tokenizer |
|
22 | * @param string $string |
|
23 | * @param array $matches |
|
24 | */ |
|
25 | public static function isBoundary(Tokenizer $tokenizer, $string, array &$matches) |
|
26 | { |
|
27 | if (!$tokenizer->getNextToken() && |
|
28 | self::isBoundaryCharacter($string, $matches, $tokenizer->getRegexBoundaries()) |
|
29 | ) { |
|
30 | $tokenizer->setNextToken(self::getBoundaryCharacter($matches)); |
|
31 | } |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * @param string $string |
|
36 | * @param array $matches |
|
37 | * @param string $regexBoundaries |
|
38 | * |
|
39 | * @return bool |
|
40 | */ |
|
41 | protected static function isBoundaryCharacter($string, array &$matches, $regexBoundaries) |
|
42 | { |
|
43 | return (1 == \preg_match('/^('.$regexBoundaries.')/', $string, $matches)); |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * @param array $matches |
|
48 | * |
|
49 | * @return array |
|
50 | */ |
|
51 | protected static function getBoundaryCharacter(array &$matches) |
|
52 | { |
|
53 | return [ |
|
54 | Tokenizer::TOKEN_VALUE => $matches[1], |
|
55 | Tokenizer::TOKEN_TYPE => Tokenizer::TOKEN_TYPE_BOUNDARY, |
|
56 | ]; |
|
57 | } |
|
58 | } |
|
59 |
@@ 18-59 (lines=42) @@ | ||
15 | /** |
|
16 | * Class Numeral. |
|
17 | */ |
|
18 | final class Numeral |
|
19 | { |
|
20 | /** |
|
21 | * @param Tokenizer $tokenizer |
|
22 | * @param string $string |
|
23 | * @param array $matches |
|
24 | * |
|
25 | * @return array |
|
26 | */ |
|
27 | public static function isNumeral(Tokenizer $tokenizer, $string, array &$matches) |
|
28 | { |
|
29 | if (!$tokenizer->getNextToken() && self::isNumeralString($string, $matches, $tokenizer->getRegexBoundaries())) { |
|
30 | $tokenizer->setNextToken(self::getNumeralString($matches)); |
|
31 | } |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * @param string $string |
|
36 | * @param array $matches |
|
37 | * @param string $regexBoundaries |
|
38 | * |
|
39 | * @return bool |
|
40 | */ |
|
41 | protected static function isNumeralString($string, array &$matches, $regexBoundaries) |
|
42 | { |
|
43 | return (1 == \preg_match( |
|
44 | '/^([0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+)($|\s|"\'`|'.$regexBoundaries.')/', |
|
45 | $string, |
|
46 | $matches |
|
47 | )); |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * @param array $matches |
|
52 | * |
|
53 | * @return array |
|
54 | */ |
|
55 | protected static function getNumeralString(array &$matches) |
|
56 | { |
|
57 | return [Tokenizer::TOKEN_VALUE => $matches[1], Tokenizer::TOKEN_TYPE => Tokenizer::TOKEN_TYPE_NUMBER]; |
|
58 | } |
|
59 | } |
|
60 |