Refactor to use getStartPosition
This commit is contained in:
Родитель
465d02f146
Коммит
0b40640ac3
|
@ -7,7 +7,7 @@ an experiment and the start of a conversation.
|
|||
|
||||
![image](https://cloud.githubusercontent.com/assets/762848/19023070/4ab01c92-889a-11e6-9bb5-ec1a6816aba2.png)
|
||||
|
||||
This is the v1 branch, which changes data structures to support syntax added after the initial release for php 7.0.
|
||||
This is the v0.1 branch, which changes data structures to support syntax added after the initial 0.0.x release line.
|
||||
|
||||
## Get Started
|
||||
After you've [configured your machine](docs/GettingStarted.md), you can use the parser to generate and work
|
||||
|
|
18
src/Node.php
18
src/Node.php
|
@ -32,13 +32,7 @@ abstract class Node implements \JsonSerializable {
|
|||
* @throws \Exception
|
||||
*/
|
||||
public function getStartPosition() : int {
|
||||
$child = $this->getChildNodesAndTokens()->current();
|
||||
if ($child instanceof Node) {
|
||||
return $child->getStartPosition();
|
||||
} elseif ($child instanceof Token) {
|
||||
return $child->start;
|
||||
}
|
||||
throw new \Exception("Unknown type in AST");
|
||||
return $this->getChildNodesAndTokens()->current()->getStartPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,15 +52,7 @@ abstract class Node implements \JsonSerializable {
|
|||
$child = $child[0];
|
||||
}
|
||||
|
||||
if ($child instanceof Node) {
|
||||
return $child->getFullStartPosition();
|
||||
}
|
||||
|
||||
if ($child instanceof Token) {
|
||||
return $child->fullStart;
|
||||
}
|
||||
|
||||
throw new \Exception("Unknown type in AST: " . \gettype($child));
|
||||
return $child->getFullStartPosition();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче