diff options
Diffstat (limited to 'vendor/nikic/php-parser/lib/PhpParser/Node/Scalar')
14 files changed, 506 insertions, 0 deletions
diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php new file mode 100644 index 000000000..29ce0dd40 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php @@ -0,0 +1,70 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar; + +use PhpParser\Node\Scalar; + +class DNumber extends Scalar +{ + /** @var float Number value */ + public $value; + + /** + * Constructs a float number scalar node. + * + * @param float $value Value of the number + * @param array $attributes Additional attributes + */ + public function __construct(float $value, array $attributes = []) { + $this->attributes = $attributes; + $this->value = $value; + } + + public function getSubNodeNames() : array { + return ['value']; + } + + /** + * @internal + * + * Parses a DNUMBER token like PHP would. + * + * @param string $str A string number + * + * @return float The parsed number + */ + public static function parse(string $str) : float { + $str = str_replace('_', '', $str); + + // if string contains any of .eE just cast it to float + if (false !== strpbrk($str, '.eE')) { + return (float) $str; + } + + // otherwise it's an integer notation that overflowed into a float + // if it starts with 0 it's one of the special integer notations + if ('0' === $str[0]) { + // hex + if ('x' === $str[1] || 'X' === $str[1]) { + return hexdec($str); + } + + // bin + if ('b' === $str[1] || 'B' === $str[1]) { + return bindec($str); + } + + // oct + // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9) + // so that only the digits before that are used + return octdec(substr($str, 0, strcspn($str, '89'))); + } + + // dec + return (float) $str; + } + + public function getType() : string { + return 'Scalar_DNumber'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php new file mode 100644 index 000000000..fa5d2e268 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php @@ -0,0 +1,31 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar; + +use PhpParser\Node\Expr; +use PhpParser\Node\Scalar; + +class Encapsed extends Scalar +{ + /** @var Expr[] list of string parts */ + public $parts; + + /** + * Constructs an encapsed string node. + * + * @param Expr[] $parts Encaps list + * @param array $attributes Additional attributes + */ + public function __construct(array $parts, array $attributes = []) { + $this->attributes = $attributes; + $this->parts = $parts; + } + + public function getSubNodeNames() : array { + return ['parts']; + } + + public function getType() : string { + return 'Scalar_Encapsed'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php new file mode 100644 index 000000000..bb3194c1d --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php @@ -0,0 +1,30 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar; + +use PhpParser\Node\Scalar; + +class EncapsedStringPart extends Scalar +{ + /** @var string String value */ + public $value; + + /** + * Constructs a node representing a string part of an encapsed string. + * + * @param string $value String value + * @param array $attributes Additional attributes + */ + public function __construct(string $value, array $attributes = []) { + $this->attributes = $attributes; + $this->value = $value; + } + + public function getSubNodeNames() : array { + return ['value']; + } + + public function getType() : string { + return 'Scalar_EncapsedStringPart'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/LNumber.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/LNumber.php new file mode 100644 index 000000000..f17dd1f8a --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/LNumber.php @@ -0,0 +1,78 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar; + +use PhpParser\Error; +use PhpParser\Node\Scalar; + +class LNumber extends Scalar +{ + /* For use in "kind" attribute */ + const KIND_BIN = 2; + const KIND_OCT = 8; + const KIND_DEC = 10; + const KIND_HEX = 16; + + /** @var int Number value */ + public $value; + + /** + * Constructs an integer number scalar node. + * + * @param int $value Value of the number + * @param array $attributes Additional attributes + */ + public function __construct(int $value, array $attributes = []) { + $this->attributes = $attributes; + $this->value = $value; + } + + public function getSubNodeNames() : array { + return ['value']; + } + + /** + * Constructs an LNumber node from a string number literal. + * + * @param string $str String number literal (decimal, octal, hex or binary) + * @param array $attributes Additional attributes + * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) + * + * @return LNumber The constructed LNumber, including kind attribute + */ + public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { + $str = str_replace('_', '', $str); + + if ('0' !== $str[0] || '0' === $str) { + $attributes['kind'] = LNumber::KIND_DEC; + return new LNumber((int) $str, $attributes); + } + + if ('x' === $str[1] || 'X' === $str[1]) { + $attributes['kind'] = LNumber::KIND_HEX; + return new LNumber(hexdec($str), $attributes); + } + + if ('b' === $str[1] || 'B' === $str[1]) { + $attributes['kind'] = LNumber::KIND_BIN; + return new LNumber(bindec($str), $attributes); + } + + if (!$allowInvalidOctal && strpbrk($str, '89')) { + throw new Error('Invalid numeric literal', $attributes); + } + + // Strip optional explicit octal prefix. + if ('o' === $str[1] || 'O' === $str[1]) { + $str = substr($str, 2); + } + + // use intval instead of octdec to get proper cutting behavior with malformed numbers + $attributes['kind'] = LNumber::KIND_OCT; + return new LNumber(intval($str, 8), $attributes); + } + + public function getType() : string { + return 'Scalar_LNumber'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst.php new file mode 100644 index 000000000..941f0c762 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst.php @@ -0,0 +1,28 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar; + +use PhpParser\Node\Scalar; + +abstract class MagicConst extends Scalar +{ + /** + * Constructs a magic constant node. + * + * @param array $attributes Additional attributes + */ + public function __construct(array $attributes = []) { + $this->attributes = $attributes; + } + + public function getSubNodeNames() : array { + return []; + } + + /** + * Get name of magic constant. + * + * @return string Name of magic constant + */ + abstract public function getName() : string; +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php new file mode 100644 index 000000000..244328476 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php @@ -0,0 +1,16 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar\MagicConst; + +use PhpParser\Node\Scalar\MagicConst; + +class Class_ extends MagicConst +{ + public function getName() : string { + return '__CLASS__'; + } + + public function getType() : string { + return 'Scalar_MagicConst_Class'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php new file mode 100644 index 000000000..2b618473e --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php @@ -0,0 +1,16 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar\MagicConst; + +use PhpParser\Node\Scalar\MagicConst; + +class Dir extends MagicConst +{ + public function getName() : string { + return '__DIR__'; + } + + public function getType() : string { + return 'Scalar_MagicConst_Dir'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php new file mode 100644 index 000000000..3422db069 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php @@ -0,0 +1,16 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar\MagicConst; + +use PhpParser\Node\Scalar\MagicConst; + +class File extends MagicConst +{ + public function getName() : string { + return '__FILE__'; + } + + public function getType() : string { + return 'Scalar_MagicConst_File'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Function_.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Function_.php new file mode 100644 index 000000000..1db65a151 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Function_.php @@ -0,0 +1,16 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar\MagicConst; + +use PhpParser\Node\Scalar\MagicConst; + +class Function_ extends MagicConst +{ + public function getName() : string { + return '__FUNCTION__'; + } + + public function getType() : string { + return 'Scalar_MagicConst_Function'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php new file mode 100644 index 000000000..25d3de57c --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php @@ -0,0 +1,16 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar\MagicConst; + +use PhpParser\Node\Scalar\MagicConst; + +class Line extends MagicConst +{ + public function getName() : string { + return '__LINE__'; + } + + public function getType() : string { + return 'Scalar_MagicConst_Line'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php new file mode 100644 index 000000000..d168d56f1 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php @@ -0,0 +1,16 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar\MagicConst; + +use PhpParser\Node\Scalar\MagicConst; + +class Method extends MagicConst +{ + public function getName() : string { + return '__METHOD__'; + } + + public function getType() : string { + return 'Scalar_MagicConst_Method'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php new file mode 100644 index 000000000..4fabb751a --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php @@ -0,0 +1,16 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar\MagicConst; + +use PhpParser\Node\Scalar\MagicConst; + +class Namespace_ extends MagicConst +{ + public function getName() : string { + return '__NAMESPACE__'; + } + + public function getType() : string { + return 'Scalar_MagicConst_Namespace'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php new file mode 100644 index 000000000..5ee7e40a3 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php @@ -0,0 +1,16 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar\MagicConst; + +use PhpParser\Node\Scalar\MagicConst; + +class Trait_ extends MagicConst +{ + public function getName() : string { + return '__TRAIT__'; + } + + public function getType() : string { + return 'Scalar_MagicConst_Trait'; + } +} diff --git a/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php new file mode 100644 index 000000000..8a6d93a47 --- /dev/null +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php @@ -0,0 +1,141 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Node\Scalar; + +use PhpParser\Error; +use PhpParser\Node\Scalar; + +class String_ extends Scalar +{ + /* For use in "kind" attribute */ + const KIND_SINGLE_QUOTED = 1; + const KIND_DOUBLE_QUOTED = 2; + const KIND_HEREDOC = 3; + const KIND_NOWDOC = 4; + + /** @var string String value */ + public $value; + + protected static $replacements = [ + '\\' => '\\', + '$' => '$', + 'n' => "\n", + 'r' => "\r", + 't' => "\t", + 'f' => "\f", + 'v' => "\v", + 'e' => "\x1B", + ]; + + /** + * Constructs a string scalar node. + * + * @param string $value Value of the string + * @param array $attributes Additional attributes + */ + public function __construct(string $value, array $attributes = []) { + $this->attributes = $attributes; + $this->value = $value; + } + + public function getSubNodeNames() : array { + return ['value']; + } + + /** + * @internal + * + * Parses a string token. + * + * @param string $str String token content + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes + * + * @return string The parsed string + */ + public static function parse(string $str, bool $parseUnicodeEscape = true) : string { + $bLength = 0; + if ('b' === $str[0] || 'B' === $str[0]) { + $bLength = 1; + } + + if ('\'' === $str[$bLength]) { + return str_replace( + ['\\\\', '\\\''], + ['\\', '\''], + substr($str, $bLength + 1, -1) + ); + } else { + return self::parseEscapeSequences( + substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape + ); + } + } + + /** + * @internal + * + * Parses escape sequences in strings (all string types apart from single quoted). + * + * @param string $str String without quotes + * @param null|string $quote Quote type + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes + * + * @return string String with escape sequences parsed + */ + public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string { + if (null !== $quote) { + $str = str_replace('\\' . $quote, $quote, $str); + } + + $extra = ''; + if ($parseUnicodeEscape) { + $extra = '|u\{([0-9a-fA-F]+)\}'; + } + + return preg_replace_callback( + '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', + function($matches) { + $str = $matches[1]; + + if (isset(self::$replacements[$str])) { + return self::$replacements[$str]; + } elseif ('x' === $str[0] || 'X' === $str[0]) { + return chr(hexdec(substr($str, 1))); + } elseif ('u' === $str[0]) { + return self::codePointToUtf8(hexdec($matches[2])); + } else { + return chr(octdec($str)); + } + }, + $str + ); + } + + /** + * Converts a Unicode code point to its UTF-8 encoded representation. + * + * @param int $num Code point + * + * @return string UTF-8 representation of code point + */ + private static function codePointToUtf8(int $num) : string { + if ($num <= 0x7F) { + return chr($num); + } + if ($num <= 0x7FF) { + return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); + } + if ($num <= 0xFFFF) { + return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); + } + if ($num <= 0x1FFFFF) { + return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80) + . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); + } + throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); + } + + public function getType() : string { + return 'Scalar_String'; + } +} |