class StringLiteral
A node that represents a string literal.
@author Marco Marchiò <marco.mm89@gmail.com>
Hierarchy
- class \Peast\Syntax\Node\Node implements \Peast\Syntax\Node\JSONSerializable
- class \Peast\Syntax\Node\Literal extends \Peast\Syntax\Node\Node implements \Peast\Syntax\Node\Expression
- class \Peast\Syntax\Node\StringLiteral extends \Peast\Syntax\Node\Literal
- class \Peast\Syntax\Node\Literal extends \Peast\Syntax\Node\Node implements \Peast\Syntax\Node\Expression
Expanded class hierarchy of StringLiteral
6 string references to 'StringLiteral'
- ExportAllDeclaration::setExported in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ ExportAllDeclaration.php - Sets the exported name W
- ExportSpecifier::setExported in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ ExportSpecifier.php - Sets the exported identifier
- ImportSpecifier::setImported in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ ImportSpecifier.php - Sets the imported identifier
- ModuleSpecifier::setLocal in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ ModuleSpecifier.php - Sets the local identifier
- Parser::parseJSXAttribute in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ JSX/ Parser.php - Parses a jsx spread attribute
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ StringLiteral.php, line 19
Namespace
Peast\Syntax\NodeView source
class StringLiteral extends Literal {
/**
* Map of node properties
*
* @var array
*/
protected $propertiesMap = array(
"format" => false,
);
//Format constants
/**
* Double quoted string
*/
const DOUBLE_QUOTED = "double";
/**
* Single quoted string
*/
const SINGLE_QUOTED = "single";
/**
* String format
*
* @var string
*/
protected $format = self::DOUBLE_QUOTED;
/**
* Sets node's value
*
* @param string $value Value
*
* @return $this
*/
public function setValue($value) {
$this->value = (string) $value;
//Force recalculation of the raw value
return $this->setFormat($this->format);
}
/**
* Sets node's raw value
*
* @param mixed $raw Raw value
*
* @return $this
*
* @throws \Exception
*/
public function setRaw($raw) {
if (!is_string($raw) || strlen($raw) < 2) {
throw new \Exception("Invalid string");
}
$startQuote = $raw[0];
$endQuote = substr($raw, -1);
if ($startQuote !== "'" && $startQuote !== '"' || $startQuote !== $endQuote) {
throw new \Exception("Invalid string");
}
$this->value = Utils::unquoteLiteralString($raw);
$this->setFormat($raw[0] === "'" ? self::SINGLE_QUOTED : self::DOUBLE_QUOTED);
$this->raw = $raw;
return $this;
}
/**
* Returns string format
*
* @return string
*/
public function getFormat() {
return $this->format;
}
/**
* Sets string format
*
* @param string $format Format, one of the format constants
*
* @return $this
*/
public function setFormat($format) {
$this->format = $format;
$quote = $format === self::SINGLE_QUOTED ? "'" : '"';
$this->raw = Utils::quoteLiteralString($this->value, $quote);
return $this;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Literal::$raw | protected | property | Node's raw value | 1 | |
Literal::$value | protected | property | Node's value | 1 | |
Literal::getRaw | public | function | Return node's raw value | 1 | |
Literal::getType | public | function | Returns node's type | Overrides Node::getType | 1 |
Literal::getValue | public | function | Returns node's value | 1 | |
Node::$leadingComments | protected | property | Leading comments array | ||
Node::$location | public | property | Node location in the source code | ||
Node::$trailingComments | protected | property | Trailing comments array | ||
Node::assertArrayOf | protected | function | Asserts that the given value is an array of defined type | ||
Node::assertType | protected | function | Asserts that the given value respects the defined type | ||
Node::getLeadingComments | public | function | Returns leading comments array | ||
Node::getLocation | public | function | Returns node location in the source code | ||
Node::getTrailingComments | public | function | Returns trailing comments array | ||
Node::jsonSerialize | public | function | Returns a serializable version of the node | 2 | |
Node::render | public | function | Renders the current node | ||
Node::setEndPosition | public | function | Sets the end position of the node in the source code | ||
Node::setLeadingComments | public | function | Sets leading comments array | 1 | |
Node::setStartPosition | public | function | Sets the start position of the node in the source code | ||
Node::setTrailingComments | public | function | Sets trailing comments array | 1 | |
Node::traverse | public | function | Traverses the current node and all its child nodes using the given function |
||
Node::typeError | protected | function | Throws an error if the defined type is not supported b | ||
Node::__construct | public | function | Class constructor | ||
StringLiteral::$format | protected | property | String format | ||
StringLiteral::$propertiesMap | protected | property | Map of node properties | Overrides Literal::$propertiesMap | |
StringLiteral::DOUBLE_QUOTED | constant | Double quoted string | |||
StringLiteral::getFormat | public | function | Returns string format | ||
StringLiteral::setFormat | public | function | Sets string format | ||
StringLiteral::setRaw | public | function | Sets node's raw value | Overrides Literal::setRaw | |
StringLiteral::setValue | public | function | Sets node's value | Overrides Literal::setValue | |
StringLiteral::SINGLE_QUOTED | constant | Single quoted string |