Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
parseAssignmentExpression example
final
class
SetTokenParser
extends
AbstractTokenParser
{
public
function
parse
(
Token
$token
)
: Node
{
$lineno
=
$token
->
getLine
(
)
;
$stream
=
$this
->parser->
getStream
(
)
;
$names
=
$this
->parser->
getExpressionParser
(
)
->
parseAssignmentExpression
(
)
;
$capture
= false;
if
(
$stream
->
nextIf
(
/* Token::OPERATOR_TYPE */ 8, '='
)
)
{
$values
=
$this
->parser->
getExpressionParser
(
)
->
parseMultitargetExpression
(
)
;
$stream
->
expect
(
/* Token::BLOCK_END_TYPE */ 3
)
;
if
(
\
count
(
$names
)
!== \
count
(
$values
)
)
{
throw
new
SyntaxError
(
'When using set, you must have the same number of variables and assignments.',
$stream
->
getCurrent
(
)
->
getLine
(
)
,
$stream
->
getSourceContext
(
)
)
;
}
}
else
{
final
class
ForTokenParser
extends
AbstractTokenParser
{
public
function
parse
(
Token
$token
)
: Node
{
$lineno
=
$token
->
getLine
(
)
;
$stream
=
$this
->parser->
getStream
(
)
;
$targets
=
$this
->parser->
getExpressionParser
(
)
->
parseAssignmentExpression
(
)
;
$stream
->
expect
(
/* Token::OPERATOR_TYPE */ 8, 'in'
)
;
$seq
=
$this
->parser->
getExpressionParser
(
)
->
parseExpression
(
)
;
$stream
->
expect
(
/* Token::BLOCK_END_TYPE */ 3
)
;
$body
=
$this
->parser->
subparse
(
[
$this
, 'decideForFork'
]
)
;
if
(
'else' ==
$stream
->
next
(
)
->
getValue
(
)
)
{
$stream
->
expect
(
/* Token::BLOCK_END_TYPE */ 3
)
;
$else
=
$this
->parser->
subparse
(
[
$this
, 'decideForEnd'
]
, true
)
;
}
else
{
$else
= null;
}
protected
function
parseJSXChild
(
)
{
if
(
$node
=
$this
->
parseJSXText
(
)
)
{
return
$node
;
}
elseif
(
$node
=
$this
->
parseJSXFragment
(
)
)
{
return
$node
;
}
elseif
(
$node
=
$this
->
parseJSXElement
(
)
)
{
return
$node
;
}
elseif
(
$startToken
=
$this
->scanner->
consume
(
"{"
)
)
{
$spread
=
$this
->scanner->
consume
(
"..."
)
;
$exp
=
$this
->
parseAssignmentExpression
(
)
;
$midPos
=
$this
->scanner->
getPosition
(
)
;
if
(
(
$spread
&& !
$exp
)
|| !
$this
->scanner->
consume
(
"}"
)
)
{
$this
->
error
(
)
;
}
$node
=
$this
->
createJSXNode
(
$spread
? "JSXSpreadChild" : "JSXExpressionContainer",
$startToken
)
;
if
(
!
$exp
)
{
$exp
=
$this
->
createJSXNode
(
"JSXEmptyExpression",
$midPos
)
;
$this
->
completeNode
(
$exp
,
$midPos
)
;
}
/** * Parses an initializer * * @return Node\Node|null */
protected
function
parseInitializer
(
)
{
if
(
$this
->scanner->
consume
(
"="
)
)
{
if
(
$value
=
$this
->
parseAssignmentExpression
(
)
)
{
return
$value
;
}
$this
->
error
(
)
;
}
return
null;
}
/** * Parses an object binding pattern * * @return Node\ObjectPattern|null */