1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Clarify attribute assignment code

* Don't assign to attribute stack on reduce - why was that there
in the first place?
* Assign attributes to the position in the stack where the first
token of the production is, instead of one position earlier.
* Add a comment to clarify why we also assign attributes on read,
instead of just on shift.
This commit is contained in:
Nikita Popov 2015-04-23 13:13:45 +02:00
parent 6996db1e3a
commit a6d2cd69f8
3 changed files with 264 additions and 263 deletions

View File

@ -105,7 +105,7 @@ function resolveMacros($code) {
if ('attributes' == $name) {
assertArgs(0, $args, $name);
return '$this->startAttributeStack[#0] + $this->endAttributes';
return '$this->startAttributeStack[#1] + $this->endAttributes';
}
if ('init' == $name) {

File diff suppressed because it is too large Load Diff

View File

@ -178,7 +178,9 @@ abstract class ParserAbstract
));
}
$this->startAttributeStack[$this->stackPos] = $startAttributes;
// This is necessary to assign some meaningful attributes to /* empty */ productions. They'll get
// the attributes of the next token, even though they don't contain it themselves.
$this->startAttributeStack[$this->stackPos+1] = $startAttributes;
//$this->traceRead($symbol);
}
@ -257,7 +259,6 @@ abstract class ParserAbstract
++$this->stackPos;
$stateStack[$this->stackPos] = $state;
$this->semStack[$this->stackPos] = $this->semValue;
$this->startAttributeStack[$this->stackPos] = $startAttributes;
} else {
/* error */
switch ($errorState) {