基础代码
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an array literal.
|
||||
* For example: [a, b, c]
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ArrayExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"elements" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Array elements
|
||||
*
|
||||
* @var Expression[]|SpreadElement[]
|
||||
*/
|
||||
protected $elements = array();
|
||||
|
||||
/**
|
||||
* Returns array elements
|
||||
*
|
||||
* @return Expression[]|SpreadElement[]
|
||||
*/
|
||||
public function getElements()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets array elements
|
||||
*
|
||||
* @param Expression[]|SpreadElement[] $elements Array elements to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setElements($elements)
|
||||
{
|
||||
$this->assertArrayOf(
|
||||
$elements,
|
||||
array("Expression", "SpreadElement"),
|
||||
true
|
||||
);
|
||||
$this->elements = $elements;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an array binding pattern.
|
||||
* For example: [a, b, c] = d
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ArrayPattern extends Node implements Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"elements" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Array elements
|
||||
*
|
||||
* @var Pattern[]
|
||||
*/
|
||||
protected $elements = array();
|
||||
|
||||
/**
|
||||
* Returns array elements
|
||||
*
|
||||
* @return Pattern[]
|
||||
*/
|
||||
public function getElements()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets array elements
|
||||
*
|
||||
* @param Pattern[] $elements Array elements to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setElements($elements)
|
||||
{
|
||||
$this->assertArrayOf($elements, "Pattern", true);
|
||||
$this->elements = $elements;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an arrow function.
|
||||
* For example: var fn = (a, b) => console.log(a, b)
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ArrowFunctionExpression extends Function_ implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* This flag is true when function body is wrapped in curly braces
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $expression = false;
|
||||
|
||||
/**
|
||||
* Sets the function body
|
||||
*
|
||||
* @param BlockStatement|Expression $body Function body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertType($body, array("BlockStatement", "Expression"));
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression flag
|
||||
*
|
||||
* @param bool $expression Expression flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression($expression)
|
||||
{
|
||||
$this->expression = (bool) $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an assignment expression.
|
||||
* For example: a = b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class AssignmentExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"operator" => false,
|
||||
"right" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The assignment operator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* The left node of the assignment
|
||||
*
|
||||
* @var Pattern|Expression
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* The right node of the assignment
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Returns the assignment operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the assignment operator
|
||||
*
|
||||
* @param string $operator Assignment operator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the left node of the assignment
|
||||
*
|
||||
* @return Pattern|Expression
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left node of the assignment
|
||||
*
|
||||
* @param Pattern|Expression $left The node to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft($left)
|
||||
{
|
||||
$this->assertType($left, array("Pattern", "Expression"));
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the right node of the assignment
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right node of the assignment
|
||||
*
|
||||
* @param Expression $right The node to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an assignment in a binding context.
|
||||
* For example "a = b" in: var {a = b} = c
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class AssignmentPattern extends Node implements Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"right" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The left node of the assignment
|
||||
*
|
||||
* @var Pattern
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* The right node of the assignment
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Returns the left node of the assignment
|
||||
*
|
||||
* @return Pattern
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left node of the assignment
|
||||
*
|
||||
* @param Pattern $left Left node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft(Pattern $left)
|
||||
{
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the right node of the assignment
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right node of the assignment
|
||||
*
|
||||
* @param Expression $right Right node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a property in an object binding pattern.
|
||||
* For example "a" in: var {a} = b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class AssignmentProperty extends Property
|
||||
{
|
||||
/**
|
||||
* Returns node's type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return "Property";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the propery value
|
||||
*
|
||||
* @param Pattern $value Property value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->assertType($value, "Pattern");
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property kind that is one of the kind constants
|
||||
*
|
||||
* @param string $kind Property kind
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setKind($kind)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property method flag that is true when the property is a method
|
||||
*
|
||||
* @param bool $method Method flag
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an await expression.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class AwaitExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"argument" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Expression's argument
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $argument;
|
||||
|
||||
/**
|
||||
* Returns the expression's argument
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's argument
|
||||
*
|
||||
* @param Expression $argument Argument
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArgument(Expression $argument)
|
||||
{
|
||||
$this->argument = $argument;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a BigInt literal.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BigIntLiteral extends Literal
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"bigint" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Node's value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $bigint;
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param float $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
//Value, Raw and Bigint are always the same value
|
||||
$this->value = $this->raw = $this->bigint = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node's value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBigint()
|
||||
{
|
||||
return $this->bigint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param string $bigint Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBigint($bigint)
|
||||
{
|
||||
return $this->setValue($bigint);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a binary expression.
|
||||
* For example: a + b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BinaryExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"operator" => false,
|
||||
"right" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Operator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* Left expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* Right expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Returns the operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operator
|
||||
*
|
||||
* @param string $operator Operator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the left expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left expression
|
||||
*
|
||||
* @param Expression $left Left expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft(Expression $left)
|
||||
{
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the right expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right expression
|
||||
*
|
||||
* @param Expression $right Right expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a block of code wrapped in curly braces.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BlockStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Block's body
|
||||
*
|
||||
* @var Statement[]
|
||||
*/
|
||||
protected $body = array();
|
||||
|
||||
/**
|
||||
* Returns block's body
|
||||
*
|
||||
* @return Statement[]
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets block's body
|
||||
*
|
||||
* @param Statement[] $body Array of Statements that are the body of the
|
||||
* block
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertArrayOf($body, "Statement");
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a boolean literal.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BooleanLiteral extends Literal
|
||||
{
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
if ($value === "true") {
|
||||
$this->value = true;
|
||||
} elseif ($value === "false") {
|
||||
$this->value = false;
|
||||
} else {
|
||||
$this->value = (bool) $value;
|
||||
}
|
||||
$this->raw = $this->value ? "true" : "false";
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the "break" statement inside loops.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class BreakStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"label" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The optional label of the break statement
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* Returns the node's label
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the node's label
|
||||
*
|
||||
* @param Identifier $label Node's label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->assertType($label, "Identifier", true);
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a call expression.
|
||||
* For example: test()
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class CallExpression extends ChainElement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"callee" => true,
|
||||
"arguments" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The callee expression
|
||||
*
|
||||
* @var Expression|Super
|
||||
*/
|
||||
protected $callee;
|
||||
|
||||
/**
|
||||
* The arguments array
|
||||
*
|
||||
* @var Expression[]|SpreadElement[]
|
||||
*/
|
||||
protected $arguments = array();
|
||||
|
||||
/**
|
||||
* Returns the callee expression
|
||||
*
|
||||
* @return Expression|Super
|
||||
*/
|
||||
public function getCallee()
|
||||
{
|
||||
return $this->callee;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callee expression
|
||||
*
|
||||
* @param Expression|Super $callee Callee expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCallee($callee)
|
||||
{
|
||||
$this->assertType($callee, array("Expression", "Super"));
|
||||
$this->callee = $callee;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the arguments array
|
||||
*
|
||||
* @return Expression[]|SpreadElement[]
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the arguments array
|
||||
*
|
||||
* @param Expression[]|SpreadElement[] $arguments Arguments array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArguments($arguments)
|
||||
{
|
||||
$this->assertArrayOf($arguments, array("Expression", "SpreadElement"));
|
||||
$this->arguments = $arguments;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the catch clause in a try-catch statement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class CatchClause extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"param" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The catch clause parameter
|
||||
*
|
||||
* @var Pattern
|
||||
*/
|
||||
protected $param;
|
||||
|
||||
/**
|
||||
* The body of the catch clause
|
||||
*
|
||||
* @var BlockStatement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns the catch clause parameter
|
||||
*
|
||||
* @return Pattern
|
||||
*/
|
||||
public function getParam()
|
||||
{
|
||||
return $this->param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the catch clause parameter
|
||||
*
|
||||
* @param Pattern $param Catch clause parameter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParam($param)
|
||||
{
|
||||
$this->assertType($param, "Pattern", true);
|
||||
$this->param = $param;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body of the catch clause
|
||||
*
|
||||
* @return BlockStatement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the body of the catch clause
|
||||
*
|
||||
* @param BlockStatement $body The block of code inside the catch clause
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(BlockStatement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a chain element.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
abstract class ChainElement extends Node implements Expression
|
||||
{
|
||||
protected $propertiesMap = array(
|
||||
"optional" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Optional flag that is true if the node is in the optional
|
||||
* part of a chain expression
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $optional = false;
|
||||
|
||||
/**
|
||||
* Returns the optional flag that is true if the node is in
|
||||
* the optional part of a chain expression
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getOptional()
|
||||
{
|
||||
return $this->optional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optional flag that is true if the node is in
|
||||
* the optional part of a chain expression
|
||||
*
|
||||
* @param bool $optional Optional flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptional($optional)
|
||||
{
|
||||
$this->optional = (bool) $optional;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a chain expression.
|
||||
* For example: test?.test?.()
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ChainExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The wrapped expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $expression;
|
||||
|
||||
/**
|
||||
* Returns the wrapped expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapped expression
|
||||
*
|
||||
* @param Expression $expression Wrapped expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression(Expression $expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a class body.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ClassBody extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Class methods
|
||||
*
|
||||
* @var MethodDefinition[]
|
||||
*/
|
||||
protected $body = array();
|
||||
|
||||
/**
|
||||
* Returns class methods
|
||||
*
|
||||
* @return MethodDefinition[]
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets class methods
|
||||
*
|
||||
* @param MethodDefinition[] $body Class methods array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertArrayOf($body, "MethodDefinition");
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a class declaration.
|
||||
* For example: class test {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ClassDeclaration extends Class_ implements Declaration
|
||||
{
|
||||
/**
|
||||
* Sets the class identifier
|
||||
*
|
||||
* @param Identifier $id Class identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->assertType($id, "Identifier");
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a class expression
|
||||
* For example: test = class {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ClassExpression extends Class_ implements Expression
|
||||
{
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Abstract class for classes.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
abstract class Class_ extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"id" => true,
|
||||
"superClass" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Class name
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Extended class
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $superClass;
|
||||
|
||||
/**
|
||||
* Class body
|
||||
*
|
||||
* @var ClassBody
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns class name
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets class name
|
||||
*
|
||||
* @param Identifier $id Class name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->assertType($id, "Identifier", true);
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extended class
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getSuperClass()
|
||||
{
|
||||
return $this->superClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extended class
|
||||
*
|
||||
* @param Expression $superClass Extended class
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSuperClass($superClass)
|
||||
{
|
||||
$this->assertType($superClass, "Expression", true);
|
||||
$this->superClass = $superClass;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns class body
|
||||
*
|
||||
* @return ClassBody
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets class body
|
||||
*
|
||||
* @param ClassBody $body Class body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertType($body, "ClassBody");
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a comment.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Comment extends Node
|
||||
{
|
||||
//Comment kind constants
|
||||
/**
|
||||
* Inline comment
|
||||
*/
|
||||
const KIND_INLINE = "inline";
|
||||
|
||||
/**
|
||||
* Multiline comment
|
||||
*/
|
||||
const KIND_MULTILINE = "multiline";
|
||||
|
||||
/**
|
||||
* Html open comment
|
||||
*/
|
||||
const KIND_HTML_OPEN = "html-open";
|
||||
|
||||
/**
|
||||
* Html close comment
|
||||
*/
|
||||
const KIND_HTML_CLOSE = "html-close";
|
||||
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"kind" => false,
|
||||
"text" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* The comment kind
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $kind;
|
||||
|
||||
/**
|
||||
* The comment text
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $text;
|
||||
|
||||
/**
|
||||
* Returns the comment kind
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKind()
|
||||
{
|
||||
return $this->kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment kind
|
||||
*
|
||||
* @param string $kind Comment kind
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKind($kind)
|
||||
{
|
||||
$this->kind = $kind;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getText()
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment text
|
||||
*
|
||||
* @param string $text Comment text
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setText($text)
|
||||
{
|
||||
$this->text = $text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment raw text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawText()
|
||||
{
|
||||
$text = $this->getText();
|
||||
$kind = $this->getKind();
|
||||
|
||||
if ($kind === self::KIND_INLINE) {
|
||||
return "//" . $text;
|
||||
} elseif ($kind === self::KIND_HTML_OPEN) {
|
||||
return "<!--" . $text;
|
||||
} elseif ($kind === self::KIND_HTML_CLOSE) {
|
||||
return "-->" . $text;
|
||||
} else {
|
||||
return "/*" . $text . "*/";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment raw text
|
||||
*
|
||||
* @param string $rawText Comment raw text
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRawText($rawText)
|
||||
{
|
||||
$start = substr($rawText, 0, 2);
|
||||
if ($start === "//") {
|
||||
$kind = self::KIND_INLINE;
|
||||
$text = substr($rawText, 2);
|
||||
} elseif ($start === "/*" && substr($rawText, -2) === "*/") {
|
||||
$kind = self::KIND_MULTILINE;
|
||||
$text = substr($rawText, 2, -2);
|
||||
} elseif ($start === "<!" && substr($rawText, 2, 2) === "--") {
|
||||
$kind = self::KIND_HTML_OPEN;
|
||||
$text = substr($rawText, 4);
|
||||
} elseif ($start === "--" && substr($rawText, 2, 1) === ">") {
|
||||
$kind = self::KIND_HTML_CLOSE;
|
||||
$text = substr($rawText, 3);
|
||||
} else {
|
||||
throw new \Exception("Invalid comment");
|
||||
}
|
||||
return $this->setKind($kind)->setText($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets leading comments array
|
||||
*
|
||||
* @param Comments[] $comments Comments array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeadingComments($comments)
|
||||
{
|
||||
//Comments cannot be attached to other comments
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets trailing comments array
|
||||
*
|
||||
* @param Comments[] $comments Comments array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTrailingComments($comments)
|
||||
{
|
||||
//Comments cannot be attached to other comments
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a serializable version of the node
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$ret = parent::jsonSerialize();
|
||||
unset($ret["leadingComments"]);
|
||||
unset($ret["trailingComments"]);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a conditional expression.
|
||||
* For example: test() ? ok() : fail()
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ConditionalExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"test" => true,
|
||||
"consequent" => true,
|
||||
"alternate" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The test expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* The consequent expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $consequent;
|
||||
|
||||
/**
|
||||
* The alternate expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $alternate;
|
||||
|
||||
/**
|
||||
* Returns the test expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test expression
|
||||
*
|
||||
* @param Expression $test Test expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest(Expression $test)
|
||||
{
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the consequent expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getConsequent()
|
||||
{
|
||||
return $this->consequent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the consequent expression
|
||||
*
|
||||
* @param Expression $consequent Consequent expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConsequent(Expression $consequent)
|
||||
{
|
||||
$this->consequent = $consequent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alternate expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getAlternate()
|
||||
{
|
||||
return $this->alternate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the alternate expression
|
||||
*
|
||||
* @param Expression $alternate Alternate expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAlternate(Expression $alternate)
|
||||
{
|
||||
$this->alternate = $alternate;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the "continue" statement inside loops.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ContinueStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"label" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The optional label of the continue statement
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* Returns the node's label
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the node's label
|
||||
*
|
||||
* @param Identifier $label Node's label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->assertType($label, "Identifier", true);
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a debugger statement.
|
||||
* For example: debugger;
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class DebuggerStatement extends Node implements Statement
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Interface that every declaration node must implement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
interface Declaration extends Statement
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a do-while loop.
|
||||
* For example: do {} while (test)
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class DoWhileStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"body" => true,
|
||||
"test" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The loop body
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* The loop condition
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* Returns the loop body
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop body
|
||||
*
|
||||
* @param Statement $body Loop body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(Statement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loop condition
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop condition
|
||||
*
|
||||
* @param Expression $test Loop
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest(Expression $test)
|
||||
{
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an empty statement (;).
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class EmptyStatement extends Node implements Statement
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an "export all" declaration.
|
||||
* For example: export * from "test"
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExportAllDeclaration extends Node implements ModuleDeclaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"source" => true,
|
||||
"exported" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The export source
|
||||
*
|
||||
* @var Literal
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* The exported name
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $exported;
|
||||
|
||||
/**
|
||||
* Returns the export source
|
||||
*
|
||||
* @return Literal
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export source
|
||||
*
|
||||
* @param Literal $source Export source
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource(Literal $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported name
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getExported()
|
||||
{
|
||||
return $this->exported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported name
|
||||
*W
|
||||
* @param Identifier $exported Exported name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExported($exported)
|
||||
{
|
||||
$this->assertType($exported, "Identifier", true);
|
||||
$this->exported = $exported;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the export default declaration.
|
||||
* For example: export default a
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExportDefaultDeclaration extends Node implements ModuleDeclaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"declaration" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The exported declaration
|
||||
*
|
||||
* @var Declaration|Expression
|
||||
*/
|
||||
protected $declaration;
|
||||
|
||||
/**
|
||||
* Returns the exported declaration
|
||||
*
|
||||
* @return Declaration|Expression
|
||||
*/
|
||||
public function getDeclaration()
|
||||
{
|
||||
return $this->declaration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported declaration
|
||||
*
|
||||
* @param type $declaration The exported declaration
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeclaration($declaration)
|
||||
{
|
||||
$this->assertType($declaration, array("Declaration", "Expression"));
|
||||
$this->declaration = $declaration;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an export named declaration.
|
||||
* For example: export {foo} from "bar"
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExportNamedDeclaration extends Node implements ModuleDeclaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"declaration" => true,
|
||||
"specifiers" => true,
|
||||
"source" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Exported declaration
|
||||
*
|
||||
* @var Declaration
|
||||
*/
|
||||
protected $declaration;
|
||||
|
||||
/**
|
||||
* Exported specifiers
|
||||
*
|
||||
* @var ExportSpecifier[]
|
||||
*/
|
||||
protected $specifiers = array();
|
||||
|
||||
/**
|
||||
* The export source
|
||||
*
|
||||
* @var Literal
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Returns the exported declaration
|
||||
*
|
||||
* @return Declaration
|
||||
*/
|
||||
public function getDeclaration()
|
||||
{
|
||||
return $this->declaration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported declaration
|
||||
*
|
||||
* @param Declaration $declaration Exported declaration
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeclaration($declaration)
|
||||
{
|
||||
$this->assertType($declaration, "Declaration", true);
|
||||
$this->declaration = $declaration;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the exported specifiers
|
||||
*
|
||||
* @return ExportSpecifier[]
|
||||
*/
|
||||
public function getSpecifiers()
|
||||
{
|
||||
return $this->specifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported specifiers
|
||||
*
|
||||
* @param ExportSpecifier[] $specifiers Exported specifiers
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSpecifiers($specifiers)
|
||||
{
|
||||
$this->assertArrayOf($specifiers, "ExportSpecifier");
|
||||
$this->specifiers = $specifiers;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the export source
|
||||
*
|
||||
* @return Literal
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export source
|
||||
*
|
||||
* @param Literal $source Export source
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource($source)
|
||||
{
|
||||
$this->assertType($source, "Literal", true);
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a specifier in an export declaration.
|
||||
* For example "{a}" in: export {a}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExportSpecifier extends ModuleSpecifier
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"exported" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Exported identifier
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $exported;
|
||||
|
||||
/**
|
||||
* Returns the exported identifier
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getExported()
|
||||
{
|
||||
return $this->exported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exported identifier
|
||||
*
|
||||
* @param Identifier $exported Exported identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExported(Identifier $exported)
|
||||
{
|
||||
$this->exported = $exported;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Interface that every expression node must implement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
interface Expression
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an expression statement and wraps another expression.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ExpressionStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Wrapped expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $expression;
|
||||
|
||||
/**
|
||||
* Returns the wrapped expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapped expression
|
||||
*
|
||||
* @param Expression $expression Wrapped expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression(Expression $expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a for-in statement.
|
||||
* For example: for (var a in b) {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ForInStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"right" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Iteration variable
|
||||
*
|
||||
* @var VariableDeclaration|Expression|Pattern
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* Iterated object
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Loop body
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns the iteration variable
|
||||
*
|
||||
* @return VariableDeclaration|Expression|Pattern
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the iteration variable
|
||||
*
|
||||
* @param VariableDeclaration|Expression|Pattern $left Iteration variable
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft($left)
|
||||
{
|
||||
$this->assertType(
|
||||
$left, array("VariableDeclaration", "Expression", "Pattern")
|
||||
);
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the iterated object
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the iterated object
|
||||
*
|
||||
* @param Expression $right Iterated object
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loop body
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop body
|
||||
*
|
||||
* @param Statement $body Loop body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(Statement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the "for...of" statement.
|
||||
* For example: for (var a of b) {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ForOfStatement extends ForInStatement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"right" => true,
|
||||
"body" => true,
|
||||
"await" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Async iteration flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $await = false;
|
||||
|
||||
/**
|
||||
* Returns the async iteration flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getAwait()
|
||||
{
|
||||
return $this->await;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the async iteration flag
|
||||
*
|
||||
* @param bool $await Async iteration flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAwait($await)
|
||||
{
|
||||
$this->await = (bool) $await;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a for statement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ForStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"init" => true,
|
||||
"test" => true,
|
||||
"update" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Initializer
|
||||
*
|
||||
* @var VariableDeclaration|Expression
|
||||
*/
|
||||
protected $init;
|
||||
|
||||
/**
|
||||
* Test expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* Update expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $update;
|
||||
|
||||
/**
|
||||
* Loop body
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns the initializer
|
||||
*
|
||||
* @return VariableDeclaration|Expression
|
||||
*/
|
||||
public function getInit()
|
||||
{
|
||||
return $this->init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initializer
|
||||
*
|
||||
* @param VariableDeclaration|Expression $init Initializer
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setInit($init)
|
||||
{
|
||||
$this->assertType(
|
||||
$init,
|
||||
array("VariableDeclaration", "Expression"),
|
||||
true
|
||||
);
|
||||
$this->init = $init;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test expression
|
||||
*
|
||||
* @param Expression $test Test expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest($test)
|
||||
{
|
||||
$this->assertType($test, "Expression", true);
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the update expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getUpdate()
|
||||
{
|
||||
return $this->update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the update expression
|
||||
*
|
||||
* @param Expression $update Update expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUpdate($update)
|
||||
{
|
||||
$this->assertType($update, "Expression", true);
|
||||
$this->update = $update;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loop body
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loop body
|
||||
*
|
||||
* @param Statement $body Loop body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(Statement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a function declaration
|
||||
* For example: function test () {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class FunctionDeclaration extends Function_ implements Declaration
|
||||
{
|
||||
/**
|
||||
* Sets the function identifier
|
||||
*
|
||||
* @param Identifier $id Function identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->assertType($id, "Identifier");
|
||||
return $this->id = $id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a function expression
|
||||
* For example: var test = function () {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class FunctionExpression extends Function_ implements Expression
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Abstract class for functions.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
abstract class Function_ extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"id" => true,
|
||||
"params" => true,
|
||||
"body" => true,
|
||||
"generator" => false,
|
||||
"async" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Function name
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Function parameters array
|
||||
*
|
||||
* @var Pattern[]
|
||||
*/
|
||||
protected $params = array();
|
||||
|
||||
/**
|
||||
* Function body
|
||||
*
|
||||
* @var BlockStatement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Generator flag that is true when the function is a generator
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $generator = false;
|
||||
|
||||
/**
|
||||
* Async flag that is true when it is an async function
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $async = false;
|
||||
|
||||
/**
|
||||
* Returns function name
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets function name
|
||||
*
|
||||
* @param Identifier $id Function name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->assertType($id, "Identifier", true);
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns function parameters array
|
||||
*
|
||||
* @return Pattern[]
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets function parameters array
|
||||
*
|
||||
* @param Pattern[] $params Function parameters array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParams($params)
|
||||
{
|
||||
$this->assertArrayOf($params, "Pattern");
|
||||
$this->params = $params;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns function body
|
||||
*
|
||||
* @return BlockStatement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets function body
|
||||
*
|
||||
* @param BlockStatement $body Function body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertType($body, "BlockStatement");
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the generator flag that is true when the function is a generator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getGenerator()
|
||||
{
|
||||
return $this->generator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the generator flag that is true when the function is a generator
|
||||
*
|
||||
* @param bool $generator Generator flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setGenerator($generator)
|
||||
{
|
||||
$this->generator = (bool) $generator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the async flag that is true when it is an async function
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getAsync()
|
||||
{
|
||||
return $this->async;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the async flag that is true when it is an async function
|
||||
*
|
||||
* @param bool $async Async flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAsync($async)
|
||||
{
|
||||
$this->async = (bool) $async;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an identifier.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Identifier extends Node implements Expression, Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"name" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* The identifier's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Returns the identifier's name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the identifier's name
|
||||
*
|
||||
* @param string $name The name to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an if statement.
|
||||
* For example: if (test) {} else {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class IfStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"test" => true,
|
||||
"consequent" => true,
|
||||
"alternate" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The test expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* The statement that is activated if the test expression is true
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $consequent;
|
||||
|
||||
/**
|
||||
* The "else" statement
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $alternate;
|
||||
|
||||
/**
|
||||
* Returns the test expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test expression
|
||||
*
|
||||
* @param Expression $test Test expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest(Expression $test)
|
||||
{
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the statement that is activated if the test expression is true
|
||||
*
|
||||
* @return Statement|FunctionDeclaration
|
||||
*/
|
||||
public function getConsequent()
|
||||
{
|
||||
return $this->consequent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the statement that is activated if the test expression is true
|
||||
*
|
||||
* @param Statement|FunctionDeclaration $consequent The consequent expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConsequent($consequent)
|
||||
{
|
||||
$this->assertType(
|
||||
$consequent,
|
||||
array("Statement", "FunctionDeclaration"),
|
||||
true
|
||||
);
|
||||
$this->consequent = $consequent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "else" statement
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getAlternate()
|
||||
{
|
||||
return $this->alternate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "else" statement
|
||||
*
|
||||
* @param Statement|FunctionDeclaration $alternate The "else" statement
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAlternate($alternate)
|
||||
{
|
||||
$this->assertType(
|
||||
$alternate,
|
||||
array("Statement", "FunctionDeclaration"),
|
||||
true
|
||||
);
|
||||
$this->alternate = $alternate;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents in import declaration.
|
||||
* For example: import a from "mod"
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportDeclaration extends Node implements ModuleDeclaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"specifiers" => true,
|
||||
"source" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Import specifiers array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $specifiers = array();
|
||||
|
||||
/**
|
||||
* Import source
|
||||
*
|
||||
* @var Literal
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Returns the import specifiers array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSpecifiers()
|
||||
{
|
||||
return $this->specifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import specifiers array
|
||||
*
|
||||
* @param array $specifiers Import specifiers array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSpecifiers($specifiers)
|
||||
{
|
||||
$this->assertArrayOf(
|
||||
$specifiers,
|
||||
array(
|
||||
"ImportSpecifier",
|
||||
"ImportDefaultSpecifier",
|
||||
"ImportNamespaceSpecifier"
|
||||
)
|
||||
);
|
||||
$this->specifiers = $specifiers;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the import source
|
||||
*
|
||||
* @return Literal
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import source
|
||||
*
|
||||
* @param Literal $source Import source
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource(Literal $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a namespace import specifier.
|
||||
* For example "* as test" in: import * as test from "test.js".
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportDefaultSpecifier extends ModuleSpecifier
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an import expression (dynamic import).
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"source" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The catch clause parameter
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Returns the import source
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import source
|
||||
*
|
||||
* @param Expression $source Import source
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSource(Expression $source)
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a default import specifier.
|
||||
* For example "test" in: import test from "test.js".
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportNamespaceSpecifier extends ModuleSpecifier
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a specifier in an import declaration.
|
||||
* For example "{a}" in: import {a} from "test"
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ImportSpecifier extends ModuleSpecifier
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"imported" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Imported identifier
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $imported;
|
||||
|
||||
/**
|
||||
* Returns the imported identifier
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getImported()
|
||||
{
|
||||
return $this->imported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the imported identifier
|
||||
*
|
||||
* @param Identifier $imported Imported identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setImported(Identifier $imported)
|
||||
{
|
||||
$this->imported = $imported;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX attribute.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXAttribute extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"name" => true,
|
||||
"value" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Attribute name
|
||||
*
|
||||
* @var JSXIdentifier|JSXNamespacedName
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
*
|
||||
* @var Node|null
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Returns the attribute name
|
||||
*
|
||||
* @return Node
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attribute name
|
||||
*
|
||||
* @param JSXIdentifier|JSXNamespacedName $name Attribute name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->assertType($name, array("JSXIdentifier", "JSXNamespacedName"));
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attribute value
|
||||
*
|
||||
* @return Node|null
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attribute value
|
||||
*
|
||||
* @param Node|null $value Attribute value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->assertType(
|
||||
$value,
|
||||
array(
|
||||
"\Peast\Syntax\Node\Literal", "JSXExpressionContainer",
|
||||
"JSXElement", "JSXFragment"
|
||||
),
|
||||
true
|
||||
);
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A base class for boundary elements.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class JSXBoundaryElement extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"name" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Element name
|
||||
*
|
||||
* @var JSXIdentifier|JSXMemberExpression|JSXNamespacedName
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Returns the element name
|
||||
*
|
||||
* @return JSXIdentifier|JSXMemberExpression|JSXNamespacedName
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element name
|
||||
*
|
||||
* @param JSXIdentifier|JSXMemberExpression|JSXNamespacedName $name Element
|
||||
* name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->assertType(
|
||||
$name,
|
||||
array("JSXIdentifier", "JSXMemberExpression", "JSXNamespacedName")
|
||||
);
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX closing element tag.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXClosingElement extends JSXBoundaryElement
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX closing fragment tag.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXClosingFragment extends Node
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Node\Expression;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX element.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXElement extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"openingElement" => true,
|
||||
"children" => true,
|
||||
"closingElement" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Opening element node
|
||||
*
|
||||
* @var JSXOpeningElement
|
||||
*/
|
||||
protected $openingElement;
|
||||
|
||||
/**
|
||||
* Children nodes array
|
||||
*
|
||||
* @var Node[]
|
||||
*/
|
||||
protected $children = array();
|
||||
|
||||
/**
|
||||
* Closing element node
|
||||
*
|
||||
* @var JSXClosingElement|null
|
||||
*/
|
||||
protected $closingElement;
|
||||
|
||||
/**
|
||||
* Returns the opening element node
|
||||
*
|
||||
* @return JSXOpeningElement
|
||||
*/
|
||||
public function getOpeningElement()
|
||||
{
|
||||
return $this->openingElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the opening element node
|
||||
*
|
||||
* @param JSXOpeningElement $openingElement Opening element node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOpeningElement(JSXOpeningElement $openingElement)
|
||||
{
|
||||
$this->openingElement = $openingElement;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the children nodes array
|
||||
*
|
||||
* @return Node[]
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the children nodes array
|
||||
*
|
||||
* @param Node[] $children Children nodes array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setChildren($children)
|
||||
{
|
||||
$this->assertArrayOf($children, array(
|
||||
"JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement",
|
||||
"JSXFragment"
|
||||
));
|
||||
$this->children = $children;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closing element node
|
||||
*
|
||||
* @return JSXClosingElement|null
|
||||
*/
|
||||
public function getClosingElement()
|
||||
{
|
||||
return $this->closingElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the closing element node
|
||||
*
|
||||
* @param JSXClosingElement|null $closingElement Closing element node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setClosingElement($closingElement)
|
||||
{
|
||||
$this->assertType($closingElement, "JSXClosingElement", true);
|
||||
$this->closingElement = $closingElement;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX empty expression.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXEmptyExpression extends Node
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an expression container in JSX.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXExpressionContainer extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The wrapped expression
|
||||
*
|
||||
* @var \Peast\Syntax\Node\Expression|JSXEmptyExpression
|
||||
*/
|
||||
protected $expression;
|
||||
|
||||
/**
|
||||
* Returns the wrapped expression
|
||||
*
|
||||
* @return \Peast\Syntax\Node\Expression|JSXEmptyExpression
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapped expression
|
||||
*
|
||||
* @param \Peast\Syntax\Node\Expression|JSXEmptyExpression $expression Wrapped
|
||||
* expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression($expression)
|
||||
{
|
||||
$this->assertType(
|
||||
$expression,
|
||||
array("\Peast\Syntax\Node\Expression", "JSXEmptyExpression")
|
||||
);
|
||||
$this->expression = $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Node\Expression;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX fragment.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXFragment extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"openingFragment" => true,
|
||||
"children" => true,
|
||||
"closingFragment" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Opening fragment node
|
||||
*
|
||||
* @var JSXOpeningFragment
|
||||
*/
|
||||
protected $openingFragment;
|
||||
|
||||
/**
|
||||
* Children nodes array
|
||||
*
|
||||
* @var Node[]
|
||||
*/
|
||||
protected $children = array();
|
||||
|
||||
/**
|
||||
* Closing fragment node
|
||||
*
|
||||
* @var JSXClosingFragment
|
||||
*/
|
||||
protected $closingFragment;
|
||||
|
||||
/**
|
||||
* Returns the opening fragment node
|
||||
*
|
||||
* @return JSXOpeningFragment
|
||||
*/
|
||||
public function getOpeningFragment()
|
||||
{
|
||||
return $this->openingFragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the opening fragment node
|
||||
*
|
||||
* @param JSXOpeningFragment $openingFragment Opening fragment node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOpeningFragment(JSXOpeningFragment $openingFragment)
|
||||
{
|
||||
$this->openingFragment = $openingFragment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the children nodes array
|
||||
*
|
||||
* @return Node[]
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the children nodes array
|
||||
*
|
||||
* @param Node[] $children Children nodes array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setChildren($children)
|
||||
{
|
||||
$this->assertArrayOf($children, array(
|
||||
"JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement",
|
||||
"JSXFragment"
|
||||
));
|
||||
$this->children = $children;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closing fragment node
|
||||
*
|
||||
* @return JSXClosingFragment
|
||||
*/
|
||||
public function getClosingFragment()
|
||||
{
|
||||
return $this->closingFragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the closing fragment node
|
||||
*
|
||||
* @param JSXClosingFragment $closingFragment Closing fragment node
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setClosingFragment(JSXClosingFragment $closingFragment)
|
||||
{
|
||||
$this->closingFragment = $closingFragment;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Identifier;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX identifier.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXIdentifier extends Identifier
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Node\Expression;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX member expression.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXMemberExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"object" => true,
|
||||
"property" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Expression's object
|
||||
*
|
||||
* @var JSXMemberExpression|JSXIdentifier
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Expression's property
|
||||
*
|
||||
* @var JSXIdentifier
|
||||
*/
|
||||
protected $property;
|
||||
|
||||
/**
|
||||
* Returns the expression's object
|
||||
*
|
||||
* @return JSXMemberExpression|JSXIdentifier
|
||||
*/
|
||||
public function getObject()
|
||||
{
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's object
|
||||
*
|
||||
* @param JSXMemberExpression|JSXIdentifier $object Object
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setObject($object)
|
||||
{
|
||||
$this->assertType($object, array("JSXMemberExpression", "JSXIdentifier"));
|
||||
$this->object = $object;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression's property
|
||||
*
|
||||
* @return JSXIdentifier
|
||||
*/
|
||||
public function getProperty()
|
||||
{
|
||||
return $this->property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's property
|
||||
*
|
||||
* @param JSXIdentifier $property Property
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperty(JSXIdentifier $property)
|
||||
{
|
||||
$this->property = $property;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Node\Expression;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX namespaced name.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXNamespacedName extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"namespace" => false,
|
||||
"name" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Node's namespace
|
||||
*
|
||||
* @var JSXIdentifier
|
||||
*/
|
||||
protected $namespace;
|
||||
|
||||
/**
|
||||
* Node's name
|
||||
*
|
||||
* @var JSXIdentifier
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Returns node's namespace
|
||||
*
|
||||
* @return JSXIdentifier
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's namespace
|
||||
*
|
||||
* @param JSXIdentifier $namespace Namespace
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return node's name
|
||||
*
|
||||
* @return JSXIdentifier
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's name
|
||||
*
|
||||
* @param JSXIdentifier $name Name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Node\Expression;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX opening element tag.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXOpeningElement extends JSXBoundaryElement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"attributes" => true,
|
||||
"selfClosing" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Children nodes array
|
||||
*
|
||||
* @var JSXAttribute[]|JSXSpreadAttribute[]
|
||||
*/
|
||||
protected $attrributes = array();
|
||||
|
||||
/**
|
||||
* Self closing tag mode
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $selfClosing = false;
|
||||
|
||||
/**
|
||||
* Returns the children attributes array
|
||||
*
|
||||
* @return JSXAttribute[]|JSXSpreadAttribute[]
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attrributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes nodes array
|
||||
*
|
||||
* @param JSXAttribute[]|JSXSpreadAttribute[] $attrributes Attrributes nodes
|
||||
* array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttributes($attrributes)
|
||||
{
|
||||
$this->assertArrayOf($attrributes, array(
|
||||
"JSXAttribute", "JSXSpreadAttribute"
|
||||
));
|
||||
$this->attrributes = $attrributes;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the self closing tag mode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getSelfClosing()
|
||||
{
|
||||
return $this->selfClosing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the self closing tag mode
|
||||
*
|
||||
* @param bool $selfClosing Self closing tag mode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSelfClosing($selfClosing)
|
||||
{
|
||||
$this->selfClosing = (bool) $selfClosing;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX opening fragment tag.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXOpeningFragment extends Node
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\SpreadElement;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX spread attribute.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXSpreadAttribute extends SpreadElement
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
use Peast\Syntax\Node\Expression;
|
||||
|
||||
/**
|
||||
* A node that represents a spread child expression in JSX.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXSpreadChild extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The wrapped expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $expression;
|
||||
|
||||
/**
|
||||
* Returns the wrapped expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapped expression
|
||||
*
|
||||
* @param Expression $expression Wrappedexpression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression(Expression $expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node\JSX;
|
||||
|
||||
use Peast\Syntax\Node\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a JSX closing fragment tag.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class JSXText extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"value" => false,
|
||||
"raw" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Node's value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Node's raw value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $raw;
|
||||
|
||||
/**
|
||||
* Returns node's value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->raw = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return node's raw value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRaw()
|
||||
{
|
||||
return $this->raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's raw value
|
||||
*
|
||||
* @param mixed $raw Raw value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRaw($raw)
|
||||
{
|
||||
return $this->setValue($raw);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a labeled statement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class LabeledStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"label" => true,
|
||||
"body" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Label
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* Body
|
||||
*
|
||||
* @var Statement
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Returns the label
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the label
|
||||
*
|
||||
* @param Identifier $label Label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLabel(Identifier $label)
|
||||
{
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the body
|
||||
*
|
||||
* @return Statement
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the body
|
||||
*
|
||||
* @param Statement $body Body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody(Statement $body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Abstract class for literals.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
abstract class Literal extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"value" => false,
|
||||
"raw" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Node's value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Node's raw value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $raw;
|
||||
|
||||
/**
|
||||
* Returns node's type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return "Literal";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node's value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
abstract public function setValue($value);
|
||||
|
||||
/**
|
||||
* Return node's raw value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRaw()
|
||||
{
|
||||
return $this->raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's raw value
|
||||
*
|
||||
* @param mixed $raw Raw value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRaw($raw)
|
||||
{
|
||||
return $this->setValue($raw);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a logical expression.
|
||||
* For example: a && b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class LogicalExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"left" => true,
|
||||
"operator" => false,
|
||||
"right" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Operator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* Left expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $left;
|
||||
|
||||
/**
|
||||
* Right expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $right;
|
||||
|
||||
/**
|
||||
* Returns the operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operator
|
||||
*
|
||||
* @param string $operator Operator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the left expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getLeft()
|
||||
{
|
||||
return $this->left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left expression
|
||||
*
|
||||
* @param Expression $left Left expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeft(Expression $left)
|
||||
{
|
||||
$this->left = $left;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the right expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getRight()
|
||||
{
|
||||
return $this->right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right expression
|
||||
*
|
||||
* @param Expression $right Right expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRight(Expression $right)
|
||||
{
|
||||
$this->right = $right;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a member expression.
|
||||
* For example: foo.bar
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class MemberExpression extends ChainElement implements Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"object" => true,
|
||||
"property" => true,
|
||||
"computed" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Expression's object
|
||||
*
|
||||
* @var Expression|Super
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Expression's property
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $property;
|
||||
|
||||
/**
|
||||
* Computed flag that is true if the property is declared using square
|
||||
* brackets syntax
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $computed = false;
|
||||
|
||||
/**
|
||||
* Returns the expression's object
|
||||
*
|
||||
* @return Expression|Super
|
||||
*/
|
||||
public function getObject()
|
||||
{
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's object
|
||||
*
|
||||
* @param Expression|Super $object Object
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setObject($object)
|
||||
{
|
||||
$this->assertType($object, array("Expression", "Super"));
|
||||
$this->object = $object;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression's property
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getProperty()
|
||||
{
|
||||
return $this->property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's property
|
||||
*
|
||||
* @param Expression $property Property
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperty(Expression $property)
|
||||
{
|
||||
$this->property = $property;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the computed flag that is true if the property is declared
|
||||
* using square brackets syntax
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getComputed()
|
||||
{
|
||||
return $this->computed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the computed flag that is true if the property is declared
|
||||
* using square brackets syntax
|
||||
*
|
||||
* @param bool $computed Computed flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setComputed($computed)
|
||||
{
|
||||
$this->computed = (bool) $computed;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a meta property.
|
||||
* For example: new.target
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class MetaProperty extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"meta" => false,
|
||||
"property" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Subject
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $meta;
|
||||
|
||||
/**
|
||||
* Property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $property;
|
||||
|
||||
/**
|
||||
* Returns the subject
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMeta()
|
||||
{
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subject
|
||||
*
|
||||
* @param string $meta Subject
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMeta($meta)
|
||||
{
|
||||
$this->meta = $meta;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getProperty()
|
||||
{
|
||||
return $this->property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property
|
||||
*
|
||||
* @param string $property Property
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperty($property)
|
||||
{
|
||||
$this->property = $property;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a method declaration in classes and object literals.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class MethodDefinition extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"key" => true,
|
||||
"value" => true,
|
||||
"kind" => false,
|
||||
"computed" => false,
|
||||
"static" => false
|
||||
);
|
||||
|
||||
//Kind constants
|
||||
/**
|
||||
* Constructor method
|
||||
*/
|
||||
const KIND_CONSTRUCTOR = "constructor";
|
||||
|
||||
/**
|
||||
* Standard method
|
||||
*/
|
||||
const KIND_METHOD = "method";
|
||||
|
||||
/**
|
||||
* Getter method
|
||||
*/
|
||||
const KIND_GET = "get";
|
||||
|
||||
/**
|
||||
* Setter method
|
||||
*/
|
||||
const KIND_SET = "set";
|
||||
|
||||
/**
|
||||
* Method's key
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* Method's value
|
||||
*
|
||||
* @var FunctionExpression
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Method's kind that is one of the kind constants
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $kind = self::KIND_METHOD;
|
||||
|
||||
/**
|
||||
* Computed flag that is true if method's key is declared using square
|
||||
* brackets syntax
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $computed = false;
|
||||
|
||||
/**
|
||||
* Static flag that is true if the method is static
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $static = false;
|
||||
|
||||
/**
|
||||
* Returns the method's key
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method's key
|
||||
*
|
||||
* @param Expression $key Method's key
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKey(Expression $key)
|
||||
{
|
||||
$this->key = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the method's value
|
||||
*
|
||||
* @return FunctionExpression
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method's value
|
||||
*
|
||||
* @param FunctionExpression $value Method's value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue(FunctionExpression $value)
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the method's kind that is one of the kind constants
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKind()
|
||||
{
|
||||
return $this->kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method's kind that is one of the kind constants
|
||||
*
|
||||
* @param string $kind Method's kind
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKind($kind)
|
||||
{
|
||||
$this->kind = $kind;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the computed flag that is true if method's key is declared using
|
||||
* square brackets syntax
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getComputed()
|
||||
{
|
||||
return $this->computed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the computed flag that is true if method's key is declared using
|
||||
* square brackets syntax
|
||||
*
|
||||
* @param type $computed Computed flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setComputed($computed)
|
||||
{
|
||||
$this->computed = (bool) $computed;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the static flag that is true if the method is static
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getStatic()
|
||||
{
|
||||
return $this->{"static"};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the static flag that is true if the method is static
|
||||
*
|
||||
* @param bool $static Static flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatic($static)
|
||||
{
|
||||
$this->{"static"} = (bool) $static;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Common interface for function import and export nodes.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
interface ModuleDeclaration
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Abstract class that export and import specifiers nodes must extend.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class ModuleSpecifier extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"local" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Local identifier
|
||||
*
|
||||
* @var Identifier
|
||||
*/
|
||||
protected $local;
|
||||
|
||||
/**
|
||||
* Returns the local identifier
|
||||
*
|
||||
* @return Identifier
|
||||
*/
|
||||
public function getLocal()
|
||||
{
|
||||
return $this->local;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the local identifier
|
||||
*
|
||||
* @param Identifier $local Local identifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLocal(Identifier $local)
|
||||
{
|
||||
$this->local = $local;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a "new" expression.
|
||||
* For example: new test()
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class NewExpression extends CallExpression
|
||||
{
|
||||
}
|
||||
+332
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Base class for all the nodes generated by Peast.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Node implements \JSONSerializable
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"type" => false,
|
||||
"location" => false,
|
||||
"leadingComments" => false,
|
||||
"trailingComments" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Node location in the source code
|
||||
*
|
||||
* @var \Peast\Syntax\SourceLocation
|
||||
*/
|
||||
protected $location;
|
||||
|
||||
/**
|
||||
* Leading comments array
|
||||
*
|
||||
* @var Comment[]
|
||||
*/
|
||||
protected $leadingComments = array();
|
||||
|
||||
/**
|
||||
* Trailing comments array
|
||||
*
|
||||
* @var Comment[]
|
||||
*/
|
||||
protected $trailingComments = array();
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->location = new \Peast\Syntax\SourceLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
$class = explode("\\", get_class($this));
|
||||
return array_pop($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets leading comments array
|
||||
*
|
||||
* @param Comments[] $comments Comments array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLeadingComments($comments)
|
||||
{
|
||||
$this->assertArrayOf($comments, "\Peast\Syntax\Node\Comment");
|
||||
$this->leadingComments = $comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns leading comments array
|
||||
*
|
||||
* @return Comments[]
|
||||
*/
|
||||
public function getLeadingComments()
|
||||
{
|
||||
return $this->leadingComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets trailing comments array
|
||||
*
|
||||
* @param Comments[] $comments Comments array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTrailingComments($comments)
|
||||
{
|
||||
$this->assertArrayOf($comments, "\Peast\Syntax\Node\Comment");
|
||||
$this->trailingComments = $comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns trailing comments array
|
||||
*
|
||||
* @return Comments[]
|
||||
*/
|
||||
public function getTrailingComments()
|
||||
{
|
||||
return $this->trailingComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node location in the source code
|
||||
*
|
||||
* @return \Peast\Syntax\SourceLocation
|
||||
*/
|
||||
public function getLocation()
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the start position of the node in the source code
|
||||
*
|
||||
* @param \Peast\Syntax\Position $position Start position
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setStartPosition(\Peast\Syntax\Position $position)
|
||||
{
|
||||
$this->location->setStart($position);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the end position of the node in the source code
|
||||
*
|
||||
* @param \Peast\Syntax\Position $position Start position
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEndPosition(\Peast\Syntax\Position $position)
|
||||
{
|
||||
$this->location->setEnd($position);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses the current node and all its child nodes using the given
|
||||
* function
|
||||
*
|
||||
* @param callable $fn Function that will be called on each node
|
||||
* @param array $options Options array. See Traverser class
|
||||
* documentation for available options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function traverse(callable $fn, $options = array())
|
||||
{
|
||||
$traverser = new \Peast\Traverser($options);
|
||||
$traverser->addFunction($fn)->traverse($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a serializable version of the node
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$ret = array();
|
||||
$props = \Peast\Syntax\Utils::getNodeProperties($this);
|
||||
foreach ($props as $prop) {
|
||||
$ret[$prop["name"]] = $this->{$prop["getter"]}();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the current node
|
||||
*
|
||||
* @param \Peast\Formatter\Base $formatter Formatter to use for the
|
||||
* rendering
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(\Peast\Formatter\Base $formatter)
|
||||
{
|
||||
$renderer = new \Peast\Renderer();
|
||||
return $renderer->setFormatter($formatter)->render($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given value is an array of defined type
|
||||
*
|
||||
* @param mixed $params Value to check
|
||||
* @param string|array $classes Class or array of classes to check against
|
||||
* @param bool $allowNull If true, null values are allowed
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function assertArrayOf($params, $classes, $allowNull = false)
|
||||
{
|
||||
if (!is_array($classes)) {
|
||||
$classes = array($classes);
|
||||
}
|
||||
if (!is_array($params)) {
|
||||
$this->typeError($params, $classes, $allowNull, true);
|
||||
} else {
|
||||
foreach ($params as $param) {
|
||||
foreach ($classes as $class) {
|
||||
if ($param === null && $allowNull) {
|
||||
continue 2;
|
||||
} else {
|
||||
$c = $this->addNamespace($class);
|
||||
if ($param instanceof $c) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->typeError($param, $classes, $allowNull, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given value respects the defined type
|
||||
*
|
||||
* @param mixed $param Value to check
|
||||
* @param string|array $classes Class or array of classes to check against
|
||||
* @param bool $allowNull If true, null values are allowed
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function assertType($param, $classes, $allowNull = false)
|
||||
{
|
||||
if (!is_array($classes)) {
|
||||
$classes = array($classes);
|
||||
}
|
||||
if ($param === null) {
|
||||
if (!$allowNull) {
|
||||
$this->typeError($param, $classes, $allowNull);
|
||||
}
|
||||
} else {
|
||||
foreach ($classes as $class) {
|
||||
$c = $this->addNamespace($class);
|
||||
if ($param instanceof $c) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->typeError($param, $classes, $allowNull);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the namespace of the current class to the given class name
|
||||
*
|
||||
* @param string $class Class name to namespace
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function addNamespace($class)
|
||||
{
|
||||
if ($class[0] === "\\") {
|
||||
return $class;
|
||||
}
|
||||
$parts = explode("\\", get_class($this));
|
||||
$parts[count($parts) -1] = $class;
|
||||
return implode("\\", $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error if the defined type is not supported b
|
||||
*
|
||||
* @param mixed $param The value to check
|
||||
* @param mixed $allowedTypes Class or array of classes to check against
|
||||
* @param bool $allowNull If true, null values are allowed
|
||||
* @param bool $array If true, the value must be an array
|
||||
* @param bool $inArray If true, the value is an array but the content
|
||||
* does not respects the type
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \TypeError
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function typeError(
|
||||
$param, $allowedTypes, $allowNull = false, $array = false,
|
||||
$inArray = false
|
||||
) {
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
$method = $backtrace[2]["class"] . "::" . $backtrace[2]["function"];
|
||||
$msg = "Argument 0 passed to $method must be ";
|
||||
if ($array) {
|
||||
$msg .= "an array of ";
|
||||
}
|
||||
$msg .= implode(" or ", $allowedTypes);
|
||||
if ($allowNull) {
|
||||
$msg .= " or null";
|
||||
}
|
||||
if (is_object($param)) {
|
||||
$parts = explode("\\", get_class($param));
|
||||
$type = array_pop($parts);
|
||||
} else {
|
||||
$type = gettype($param);
|
||||
}
|
||||
if ($inArray) {
|
||||
$type = "array of $type";
|
||||
}
|
||||
$msg .= ", $type given";
|
||||
if (version_compare(phpversion(), '7', '>=')) {
|
||||
throw new \TypeError($msg);
|
||||
} else {
|
||||
trigger_error($msg, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a null literal.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class NullLiteral extends Literal
|
||||
{
|
||||
/**
|
||||
* Node's value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $value = null;
|
||||
|
||||
/**
|
||||
* Node's raw value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $raw = "null";
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a numeric literal.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class NumericLiteral extends Literal
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"format" => false
|
||||
);
|
||||
|
||||
//Format constants
|
||||
/**
|
||||
* Decimal number format
|
||||
*/
|
||||
const DECIMAL = "decimal";
|
||||
|
||||
/**
|
||||
* Hexadecimal number format
|
||||
*/
|
||||
const HEXADECIMAL = "hexadecimal";
|
||||
|
||||
/**
|
||||
* Octal number format
|
||||
*/
|
||||
const OCTAL = "octal";
|
||||
|
||||
/**
|
||||
* Binary number format
|
||||
*/
|
||||
const BINARY = "binary";
|
||||
|
||||
/**
|
||||
* Node's numeric format
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $format = self::DECIMAL;
|
||||
|
||||
/**
|
||||
* Numeric forms conversion rules
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $forms = array(
|
||||
"b" => array(
|
||||
"check" => "/^0b[01]+[01_]*$/i",
|
||||
"conv" => "bindec",
|
||||
"format" => self::BINARY
|
||||
),
|
||||
"o" => array(
|
||||
"check" => "/^0o[0-7]+[0-7_]*$/i",
|
||||
"conv" => "octdec",
|
||||
"format" => self::OCTAL
|
||||
),
|
||||
"x" => array(
|
||||
"check" => "/^0x[0-9a-f]+[0-9a-f_]*$/i",
|
||||
"conv" => "hexdec",
|
||||
"format" => self::HEXADECIMAL
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param float $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$value = (float) $value;
|
||||
$intValue = (int) $value;
|
||||
if ($value == $intValue) {
|
||||
$value = $intValue;
|
||||
}
|
||||
$this->value = $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)
|
||||
{
|
||||
$value = $raw;
|
||||
$format = self::DECIMAL;
|
||||
if (is_string($value) && $value !== "") {
|
||||
//Hexadecimal, binary or octal
|
||||
$startZero = $value[0] === "0";
|
||||
$form = $startZero && isset($value[1]) ? strtolower($value[1]) : null;
|
||||
//Numeric separator cannot appear at the beginning or at the end of the number
|
||||
if (preg_match("/^_|_$/", $value)) {
|
||||
throw new \Exception("Invalid numeric value");
|
||||
} elseif (isset($this->forms[$form])) {
|
||||
$formDef = $this->forms[$form];
|
||||
if (!preg_match($formDef["check"], $value)) {
|
||||
throw new \Exception("Invalid " . $formDef["format"]);
|
||||
}
|
||||
$value = str_replace("_", "", $value);
|
||||
$value = $formDef["conv"]($value);
|
||||
$format = $formDef["format"];
|
||||
} elseif ($startZero && preg_match("/^0[0-7_]+$/", $value)) {
|
||||
//Legacy octal form
|
||||
$value = str_replace("_", "", $value);
|
||||
$value = octdec($value);
|
||||
$format = self::OCTAL;
|
||||
} elseif (
|
||||
preg_match("/^([\d_]*\.?[\d_]*)(?:e[+\-]?[\d_]+)?$/i", $value, $match) &&
|
||||
$match[1] !== "" &&
|
||||
$match[1] !== "." &&
|
||||
!preg_match("/_e|e[+-]?_|_$/", $value)
|
||||
) {
|
||||
$value = str_replace("_", "", $value);
|
||||
} else {
|
||||
throw new \Exception("Invalid numeric value");
|
||||
}
|
||||
} elseif (!is_int($value) && !is_float($value)) {
|
||||
throw new \Exception("Invalid numeric value");
|
||||
}
|
||||
$value = (float) $value;
|
||||
$intValue = (int) $value;
|
||||
if ($value == $intValue) {
|
||||
$value = $intValue;
|
||||
}
|
||||
$this->format = $format;
|
||||
$this->value = $value;
|
||||
$this->raw = $raw;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node's numeric format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormat()
|
||||
{
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's numeric format
|
||||
*
|
||||
* @param string $format Format, one of the format constants
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFormat($format)
|
||||
{
|
||||
$this->format = $format;
|
||||
switch ($format) {
|
||||
case self::BINARY:
|
||||
$this->raw = "0b" . decbin($this->value);
|
||||
break;
|
||||
case self::OCTAL:
|
||||
$this->raw = "0o" . decoct($this->value);
|
||||
break;
|
||||
case self::HEXADECIMAL:
|
||||
$this->raw = "0x" . dechex($this->value);
|
||||
break;
|
||||
default:
|
||||
$this->raw = (string) $this->value;
|
||||
break;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an object literal.
|
||||
* For example: {a: 1, b: 2, c: 3}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ObjectExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"properties" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Object properties
|
||||
*
|
||||
* @var Property[]
|
||||
*/
|
||||
protected $properties = array();
|
||||
|
||||
/**
|
||||
* Returns object properties
|
||||
*
|
||||
* @return Property[]
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets object properties
|
||||
*
|
||||
* @param Property[] $properties Object properties
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperties($properties)
|
||||
{
|
||||
$this->assertArrayOf($properties, array("Property", "SpreadElement"));
|
||||
$this->properties = $properties;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an object binding pattern.
|
||||
* For example: var {a, b, c} = d
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ObjectPattern extends Node implements Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"properties" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Object properties
|
||||
*
|
||||
* @var Property[]
|
||||
*/
|
||||
protected $properties = array();
|
||||
|
||||
/**
|
||||
* Returns object properties
|
||||
*
|
||||
* @return Property[]
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets object properties
|
||||
*
|
||||
* @param Property[] $properties Object properties
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperties($properties)
|
||||
{
|
||||
$this->assertArrayOf($properties, array("AssignmentProperty", "RestElement"));
|
||||
$this->properties = $properties;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an expression wrapped in round brackets.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ParenthesizedExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expression" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The wrapped expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $expression;
|
||||
|
||||
/**
|
||||
* Returns the wrapped expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapped expression
|
||||
*
|
||||
* @param Expression $expression Wrapped expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpression(Expression $expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Interface that every pattern node must implement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
interface Pattern
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
use Peast\Query;
|
||||
use Peast\Selector;
|
||||
|
||||
/**
|
||||
* Root node for scripts and modules.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Program extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"body" => true,
|
||||
"sourceType" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Source type that is one of the source type constants in the Peast class
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $sourceType = \Peast\Peast::SOURCE_TYPE_SCRIPT;
|
||||
|
||||
/**
|
||||
* Program's body
|
||||
*
|
||||
* @var Statement[]|ModuleDeclaration[]
|
||||
*/
|
||||
protected $body = array();
|
||||
|
||||
/**
|
||||
* Returns the source type that is one of the source type constants in the
|
||||
* Peast class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSourceType()
|
||||
{
|
||||
return $this->sourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the source type that is one of the source type constants in the
|
||||
* Peast class
|
||||
*
|
||||
* @param string $sourceType Source type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSourceType($sourceType)
|
||||
{
|
||||
$this->sourceType = $sourceType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the program's body
|
||||
*
|
||||
* @return Statement[]|ModuleDeclaration[]
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the program's body
|
||||
*
|
||||
* @param Statement[]|ModuleDeclaration[] $body Program's body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->assertArrayOf($body, array("Statement", "ModuleDeclaration"));
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds nodes matching the given selector.
|
||||
*
|
||||
* @param string $selector Selector
|
||||
* @param array $options Options array. See Query class
|
||||
* documentation for available options
|
||||
*
|
||||
* @return Query
|
||||
*
|
||||
* @throws Selector\Exception
|
||||
*/
|
||||
public function query($selector, $options = array())
|
||||
{
|
||||
$query = new Query($this, $options);
|
||||
return $query->find($selector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a property in an object literal.
|
||||
* For example "b" in: a = {b: 1}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Property extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"key" => true,
|
||||
"value" => true,
|
||||
"kind" => false,
|
||||
"method" => false,
|
||||
"shorthand" => false,
|
||||
"computed" => false
|
||||
);
|
||||
|
||||
//Kind constants
|
||||
/**
|
||||
* The default kind for properties
|
||||
*/
|
||||
const KIND_INIT = "init";
|
||||
|
||||
/**
|
||||
* Getter property
|
||||
*/
|
||||
const KIND_GET = "get";
|
||||
|
||||
/**
|
||||
* Setter property
|
||||
*/
|
||||
const KIND_SET = "set";
|
||||
|
||||
/**
|
||||
* Property key
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* Property value
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Property kind that is one of the kind constants
|
||||
*
|
||||
* @var type
|
||||
*/
|
||||
protected $kind = self::KIND_INIT;
|
||||
|
||||
/**
|
||||
* Property method flag that is true when the property is a method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $method = false;
|
||||
|
||||
/**
|
||||
* Property shorthand flag that is true when the property is declared
|
||||
* using an identifier and without a value
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $shorthand = false;
|
||||
|
||||
/**
|
||||
* Property computed flag that is true when the property is declared using
|
||||
* the square brackets syntax
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $computed = false;
|
||||
|
||||
/**
|
||||
* Returns the property key
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property key
|
||||
*
|
||||
* @param Expression $key Property key
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKey(Expression $key)
|
||||
{
|
||||
$this->key = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property value
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property value
|
||||
*
|
||||
* @param Expression $value Property value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->assertType($value, "Expression");
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property kind that is one of the kind constants
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKind()
|
||||
{
|
||||
return $this->kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property kind that is one of the kind constants
|
||||
*
|
||||
* @param string $kind Property kind
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKind($kind)
|
||||
{
|
||||
$this->kind = $kind;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property method flag that is true when the property is a
|
||||
* method
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property method flag that is true when the property is a method
|
||||
*
|
||||
* @param bool $method Method flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = (bool) $method;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property shorthand flag that is true when the property
|
||||
* is declared using an identifier and without a value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getShorthand()
|
||||
{
|
||||
return $this->shorthand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property shorthand flag that is true when the property
|
||||
* is declared using an identifier and without a value
|
||||
*
|
||||
* @param bool $shorthand Property shorthand flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setShorthand($shorthand)
|
||||
{
|
||||
$this->shorthand = (bool) $shorthand;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property computed flag that is true when the property is
|
||||
* declared using the square brackets syntax
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getComputed()
|
||||
{
|
||||
return $this->computed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property computed flag that is true when the property is
|
||||
* declared using the square brackets syntax
|
||||
*
|
||||
* @param bool $computed Property computed flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setComputed($computed)
|
||||
{
|
||||
$this->computed = (bool) $computed;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a regular expression literal.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class RegExpLiteral extends Literal
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"flags" => false,
|
||||
"pattern" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Regex flags
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $flags = "";
|
||||
|
||||
/**
|
||||
* Regex pattern
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $pattern = "";
|
||||
|
||||
/**
|
||||
* Returns node's type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return "RegExpLiteral";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns regex pattern
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets regex pattern
|
||||
*
|
||||
* @param string $pattern Regex pattern
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
$this->pattern = $pattern;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns regex flags
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFlags()
|
||||
{
|
||||
return $this->flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets regex flags
|
||||
*
|
||||
* @param string $flags Regex flags
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFlags($flags)
|
||||
{
|
||||
$this->flags = $flags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node's raw value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRaw()
|
||||
{
|
||||
return "/" . $this->getPattern() . "/" . $this->getFlags();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's raw value that must include delimiters
|
||||
*
|
||||
* @param string $rawValue Raw value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRaw($rawValue)
|
||||
{
|
||||
|
||||
$parts = explode("/", substr($rawValue, 1));
|
||||
$flags = array_pop($parts);
|
||||
$this->setPattern(implode("/", $parts));
|
||||
$this->setFlags($flags);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node's value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->getRaw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this->setRaw($value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the rest element in array binding paterns or function
|
||||
* parameters.
|
||||
* For example "...rest" in: [a, ...rest] = b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class RestElement extends Node implements Pattern
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"argument" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The node's argument
|
||||
*
|
||||
* @var type
|
||||
*/
|
||||
protected $argument;
|
||||
|
||||
/**
|
||||
* Returns the node's argument
|
||||
*
|
||||
* @return Pattern
|
||||
*/
|
||||
public function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the node's argument
|
||||
*
|
||||
* @param Pattern $argument Node's argument
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArgument(Pattern $argument)
|
||||
{
|
||||
$this->argument = $argument;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the return statement inside functions.
|
||||
* For example: return a + 1
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ReturnStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"argument" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Optional expression after the return keyword
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $argument;
|
||||
|
||||
/**
|
||||
* Returns the expression after the return keyword
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression after the return keyword
|
||||
*
|
||||
* @param Expression $argument The expression to return
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArgument($argument)
|
||||
{
|
||||
$this->assertType($argument, "Expression", true);
|
||||
$this->argument = $argument;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a sequence of expressions.
|
||||
* For example: a, b
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class SequenceExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"expressions" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Expressions array
|
||||
*
|
||||
* @var Expression[]
|
||||
*/
|
||||
protected $expressions = array();
|
||||
|
||||
/**
|
||||
* Returns the expressions array
|
||||
*
|
||||
* @return Expression[]
|
||||
*/
|
||||
public function getExpressions()
|
||||
{
|
||||
return $this->expressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expressions array
|
||||
*
|
||||
* @param Expression[] $expressions Expressions array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpressions($expressions)
|
||||
{
|
||||
$this->assertArrayOf($expressions, "Expression");
|
||||
$this->expressions = $expressions;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the spread element in array literals or function
|
||||
* calls.
|
||||
* For example "...params" in: test(...params)
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class SpreadElement extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"argument" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The node's argument
|
||||
*
|
||||
* @var type
|
||||
*/
|
||||
protected $argument;
|
||||
|
||||
/**
|
||||
* Returns the node's argument
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the node's argument
|
||||
*
|
||||
* @param Expression $argument Node's argument
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArgument(Expression $argument)
|
||||
{
|
||||
$this->argument = $argument;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* Interface that every statement node must implement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
interface Statement
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
use Peast\Syntax\Utils;
|
||||
|
||||
/**
|
||||
* A node that represents a string literal.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the "super" keyword.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class Super extends Node
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a case in a switch statement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class SwitchCase extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"test" => true,
|
||||
"consequent" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Test expression that is null in the "default" case
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $test;
|
||||
|
||||
/**
|
||||
* Consequent statements array
|
||||
*
|
||||
* @var Statement[]
|
||||
*/
|
||||
protected $consequent = array();
|
||||
|
||||
/**
|
||||
* Returns the test expression that is null in the "default" case
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the test expression that is null in the "default" case
|
||||
*
|
||||
* @param Expression $test Test expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTest($test)
|
||||
{
|
||||
$this->assertType($test, "Expression", true);
|
||||
$this->test = $test;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the consequent statements array
|
||||
*
|
||||
* @return Statement[]
|
||||
*/
|
||||
public function getConsequent()
|
||||
{
|
||||
return $this->consequent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the consequent statements array
|
||||
*
|
||||
* @param Expression[] $consequent Consequent statements array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConsequent($consequent)
|
||||
{
|
||||
$this->assertArrayOf($consequent, "Statement");
|
||||
$this->consequent = $consequent;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a switch statement.
|
||||
* For example: switch (test) {}
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class SwitchStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"discriminant" => true,
|
||||
"cases" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Discriminant expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $discriminant;
|
||||
|
||||
/**
|
||||
* Cases array
|
||||
*
|
||||
* @var SwitchCase[]
|
||||
*/
|
||||
protected $cases = array();
|
||||
|
||||
/**
|
||||
* Returns the discriminant expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getDiscriminant()
|
||||
{
|
||||
return $this->discriminant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the discriminant expression
|
||||
*
|
||||
* @param Expression $discriminant Discriminant expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDiscriminant(Expression $discriminant)
|
||||
{
|
||||
$this->discriminant = $discriminant;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cases array
|
||||
*
|
||||
* @return SwitchCase[]
|
||||
*/
|
||||
public function getCases()
|
||||
{
|
||||
return $this->cases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cases array
|
||||
*
|
||||
* @param SwitchCase[] $cases Cases array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCases($cases)
|
||||
{
|
||||
$this->assertArrayOf($cases, "SwitchCase");
|
||||
$this->cases = $cases;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a tagget template expression.
|
||||
* For example: fn`template`
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class TaggedTemplateExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"tag" => true,
|
||||
"quasi" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Tag expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $tag;
|
||||
|
||||
/**
|
||||
* Template
|
||||
*
|
||||
* @var TemplateLiteral
|
||||
*/
|
||||
protected $quasi;
|
||||
|
||||
/**
|
||||
* Returns the tag expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tag expression
|
||||
*
|
||||
* @param Expression $tag Tag expression
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTag(Expression $tag)
|
||||
{
|
||||
$this->tag = $tag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template
|
||||
*
|
||||
* @return TemplateLiteral
|
||||
*/
|
||||
public function getQuasi()
|
||||
{
|
||||
return $this->quasi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the the template
|
||||
*
|
||||
* @param TemplateLiteral $quasi Template
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setQuasi(TemplateLiteral $quasi)
|
||||
{
|
||||
$this->quasi = $quasi;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
use Peast\Syntax\Utils;
|
||||
|
||||
/**
|
||||
* A node that represents a template element.
|
||||
* For example `foo` and `bar` in: `foo${exp}bar`
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class TemplateElement extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"value" => false,
|
||||
"tail" => false,
|
||||
"rawValue" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Node's value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Tail flag that is true when the element is the tail element in a template
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $tail = false;
|
||||
|
||||
/**
|
||||
* Node's raw value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rawValue;
|
||||
|
||||
/**
|
||||
* Return node's value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's value
|
||||
*
|
||||
* @param mixed $value Value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->rawValue = Utils::quoteLiteralString($value, "`");
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tail flag that is true when the element is the tail element
|
||||
* in a template
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getTail()
|
||||
{
|
||||
return $this->tail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tail flag that is true when the element is the tail element
|
||||
* in a template
|
||||
*
|
||||
* @param bool $tail Tail flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTail($tail)
|
||||
{
|
||||
$this->tail = (bool) $tail;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns node's raw value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawValue()
|
||||
{
|
||||
return $this->rawValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets node's raw value that must be wrapped in templates quotes.
|
||||
*
|
||||
* @param string $rawValue Raw value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRawValue($rawValue)
|
||||
{
|
||||
$rawValue = preg_replace("#^[`}]|(?:`|\\\$\{)$#", "", $rawValue);
|
||||
$this->setValue(Utils::unquoteLiteralString("`$rawValue`"));
|
||||
$this->rawValue = $rawValue;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a template literal.
|
||||
* For example: `this is a ${test()} template`
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class TemplateLiteral extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"parts" => true,
|
||||
"quasis" => false,
|
||||
"expressions" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Array of quasis that are the literal parts of the template
|
||||
*
|
||||
* @var TemplateElement[]
|
||||
*/
|
||||
protected $quasis = array();
|
||||
|
||||
/**
|
||||
* Array of expressions inside the template
|
||||
*
|
||||
* @var Expression[]
|
||||
*/
|
||||
protected $expressions = array();
|
||||
|
||||
/**
|
||||
* Returns the array of quasis that are the literal parts of the template
|
||||
*
|
||||
* @return TemplateElement[]
|
||||
*/
|
||||
public function getQuasis()
|
||||
{
|
||||
return $this->quasis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of quasis that are the literal parts of the template
|
||||
*
|
||||
* @param TemplateElement[] $quasis Quasis
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setQuasis($quasis)
|
||||
{
|
||||
$this->assertArrayOf($quasis, "TemplateElement");
|
||||
$this->quasis = $quasis;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of expressions inside the template
|
||||
*
|
||||
* @return Expression[]
|
||||
*/
|
||||
public function getExpressions()
|
||||
{
|
||||
return $this->expressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of expressions inside the template
|
||||
*
|
||||
* @param Expression[] $expressions Expressions
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpressions($expressions)
|
||||
{
|
||||
$this->assertArrayOf($expressions, "Expression");
|
||||
$this->expressions = $expressions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the template parts (quasis and expressions)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParts()
|
||||
{
|
||||
// It must be a list of quasis and expressions alternated
|
||||
$parts = array();
|
||||
foreach ($this->quasis as $k => $val) {
|
||||
$parts[] = $val;
|
||||
if (isset($this->expressions[$k])) {
|
||||
$parts[] = $this->expressions[$k];
|
||||
}
|
||||
}
|
||||
return $parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of the template parts (quasis and expressions)
|
||||
*
|
||||
* @param array Template parts
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParts($parts)
|
||||
{
|
||||
$this->assertArrayOf($parts, array("Expression", "TemplateElement"));
|
||||
$quasis = $expressions = array();
|
||||
foreach ($parts as $part) {
|
||||
if ($part instanceof TemplateElement) {
|
||||
$quasis[] = $part;
|
||||
} else {
|
||||
$expressions[] = $part;
|
||||
}
|
||||
}
|
||||
return $this->setQuasis($quasis)->setExpressions($expressions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a serializable version of the node
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$ret = parent::jsonSerialize();
|
||||
unset($ret["parts"]);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the "this" keyword.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ThisExpression extends Node implements Expression
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents the throw statement.
|
||||
* For example: throw err
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class ThrowStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"argument" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* The thrown expression
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $argument;
|
||||
|
||||
/**
|
||||
* Returns the thrown expression
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the thrown expression
|
||||
*
|
||||
* @param Expression $argument The node to set
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArgument(Expression $argument)
|
||||
{
|
||||
$this->argument = $argument;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a try-catch statement.
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class TryStatement extends Node implements Statement
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"block" => true,
|
||||
"handler" => true,
|
||||
"finalizer" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Wrapped block
|
||||
*
|
||||
* @var BlockStatement
|
||||
*/
|
||||
protected $block;
|
||||
|
||||
/**
|
||||
* Catch clause
|
||||
*
|
||||
* @var CatchClause
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* "finally" block
|
||||
*
|
||||
* @var BlockStatement
|
||||
*/
|
||||
protected $finalizer;
|
||||
|
||||
/**
|
||||
* Returns the wrapped block
|
||||
*
|
||||
* @return BlockStatement
|
||||
*/
|
||||
public function getBlock()
|
||||
{
|
||||
return $this->block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wrapped block
|
||||
*
|
||||
* @param BlockStatement $block Wrapped block
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBlock(BlockStatement $block)
|
||||
{
|
||||
$this->block = $block;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the catch clause
|
||||
*
|
||||
* @return CatchClause
|
||||
*/
|
||||
public function getHandler()
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the catch clause
|
||||
*
|
||||
* @param CatchClause $handler Catch clause
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setHandler($handler)
|
||||
{
|
||||
$this->assertType($handler, "CatchClause", true);
|
||||
$this->handler = $handler;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "finally" block
|
||||
*
|
||||
* @return BlockStatement
|
||||
*/
|
||||
public function getFinalizer()
|
||||
{
|
||||
return $this->finalizer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "finally" block
|
||||
*
|
||||
* @param BlockStatement $finalizer The "finally" block
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFinalizer($finalizer)
|
||||
{
|
||||
$this->assertType($finalizer, "BlockStatement", true);
|
||||
$this->finalizer = $finalizer;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a unary expression.
|
||||
* For example: !a
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class UnaryExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"argument" => true,
|
||||
"operator" => false,
|
||||
"prefix" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Expression's operator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* Prefix flag that is always true since the operator preceeds the argument
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $prefix = true;
|
||||
|
||||
/**
|
||||
* Expression's argument
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $argument;
|
||||
|
||||
/**
|
||||
* Returns the expression's operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's operator
|
||||
*
|
||||
* @param string $operator Operator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prefix flag that is always true since the operator preceeds
|
||||
* the argument
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does nothing since the prefix flag is always true for
|
||||
* unary expressions
|
||||
*
|
||||
* @param bool $prefix Prefix flag
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression's argument
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's argument
|
||||
*
|
||||
* @param Expression $argument Argument
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArgument(Expression $argument)
|
||||
{
|
||||
$this->argument = $argument;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents an update expression.
|
||||
* For example: a++
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class UpdateExpression extends Node implements Expression
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"argument" => true,
|
||||
"operator" => false,
|
||||
"prefix" => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Expression's operator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* Prefix flag that is true when the operator preceeds the argument
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $prefix = false;
|
||||
|
||||
/**
|
||||
* Expression's argument
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $argument;
|
||||
|
||||
/**
|
||||
* Returns the expression's operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's operator
|
||||
*
|
||||
* @param string $operator Operator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prefix flag that is true when the operator preceeds the
|
||||
* argument
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the prefix flag that is true when the operator preceeds the
|
||||
* argument
|
||||
*
|
||||
* @param bool $prefix Prefix flag
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression's argument
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getArgument()
|
||||
{
|
||||
return $this->argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expression's argument
|
||||
*
|
||||
* @param Expression $argument Argument
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setArgument(Expression $argument)
|
||||
{
|
||||
$this->argument = $argument;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a "var", "const" or "let" declaration.
|
||||
* For example: var a = 1
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class VariableDeclaration extends Node implements Declaration
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"declarations" => true,
|
||||
"kind" => false
|
||||
);
|
||||
|
||||
//Kind constants
|
||||
/**
|
||||
* "var" kind
|
||||
*/
|
||||
const KIND_VAR = "var";
|
||||
|
||||
/**
|
||||
* "let" kind
|
||||
*/
|
||||
const KIND_LET = "let";
|
||||
|
||||
/**
|
||||
* "const" kind
|
||||
*/
|
||||
const KIND_CONST = "const";
|
||||
|
||||
/**
|
||||
* Declarations array
|
||||
*
|
||||
* @var VariableDeclarator[]
|
||||
*/
|
||||
protected $declarations = array();
|
||||
|
||||
/**
|
||||
* Declaration kind that is one of the kind constants
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $kind = self::KIND_VAR;
|
||||
|
||||
/**
|
||||
* Returns the declarations array
|
||||
*
|
||||
* @return VariableDeclarator[]
|
||||
*/
|
||||
public function getDeclarations()
|
||||
{
|
||||
return $this->declarations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the declarations array
|
||||
*
|
||||
* @param VariableDeclarator[] $declarations Declarations array
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeclarations($declarations)
|
||||
{
|
||||
$this->assertArrayOf($declarations, "VariableDeclarator");
|
||||
$this->declarations = $declarations;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the declaration kind that is one of the kind constants
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKind()
|
||||
{
|
||||
return $this->kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the declaration kind that is one of the kind constants
|
||||
*
|
||||
* @param string $kind Declaration kind
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKind($kind)
|
||||
{
|
||||
$this->kind = $kind;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the Peast package
|
||||
*
|
||||
* (c) Marco Marchiò <marco.mm89@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information refer to the LICENSE file
|
||||
* distributed with this source code
|
||||
*/
|
||||
namespace Peast\Syntax\Node;
|
||||
|
||||
/**
|
||||
* A node that represents a declaration in a VariableDeclaration node.
|
||||
* For example "a=1" in: var a = 1
|
||||
*
|
||||
* @author Marco Marchiò <marco.mm89@gmail.com>
|
||||
*/
|
||||
class VariableDeclarator extends Node
|
||||
{
|
||||
/**
|
||||
* Map of node properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $propertiesMap = array(
|
||||
"id" => true,
|
||||
"init" => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Declaration identifier or pattern
|
||||
*
|
||||
* @var Pattern
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Optional initializer
|
||||
*
|
||||
* @var Expression
|
||||
*/
|
||||
protected $init;
|
||||
|
||||
/**
|
||||
* Returns the declaration identifier or pattern
|
||||
*
|
||||
* @return Pattern
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the declaration identifier or pattern
|
||||
*
|
||||
* @param Pattern $id Declaration identifier or pattern
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId(Pattern $id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the initializer
|
||||
*
|
||||
* @return Expression
|
||||
*/
|
||||
public function getInit()
|
||||
{
|
||||
return $this->init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initializer
|
||||
*
|
||||
* @param Expression $init Initializer
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setInit($init)
|
||||
{
|
||||
$this->assertType($init, "Expression", true);
|
||||
$this->init = $init;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user