Page MenuHomePhabricator

D10554.id25359.diff
No OneTemporary

D10554.id25359.diff

diff --git a/src/parser/aast/api/AASTNode.php b/src/parser/aast/api/AASTNode.php
--- a/src/parser/aast/api/AASTNode.php
+++ b/src/parser/aast/api/AASTNode.php
@@ -58,6 +58,18 @@
return $this->children;
}
+ public function getChildrenOfType($type) {
+ $nodes = array();
+
+ foreach ($this->children as $child) {
+ if ($child->getTypeName() == $type) {
+ $nodes[] = $child;
+ }
+ }
+
+ return $nodes;
+ }
+
public function getChildOfType($index, $type) {
$child = $this->getChildByIndex($index);
if ($child->getTypeName() != $type) {
@@ -251,7 +263,6 @@
return $stream[$this->r]->getOffset() - $this->getOffset();
}
-
public function getSurroundingNonsemanticTokens() {
$before = array();
$after = array();
@@ -269,6 +280,23 @@
return array($before, $after);
}
+ public function getSurroundingSemanticTokens() {
+ $before = array();
+ $after = array();
+
+ $tokens = $this->tree->getRawTokenStream();
+
+ if ($this->l != -1) {
+ $before = $tokens[$this->l]->getSemanticTokensBefore();
+ }
+
+ if ($this->r != -1) {
+ $after = $tokens[$this->r]->getSemanticTokensAfter();
+ }
+
+ return array($before, $after);
+ }
+
public function getLineNumber() {
return idx($this->tree->getOffsetToLineNumberMap(), $this->getOffset());
}
diff --git a/src/parser/aast/api/AASTToken.php b/src/parser/aast/api/AASTToken.php
--- a/src/parser/aast/api/AASTToken.php
+++ b/src/parser/aast/api/AASTToken.php
@@ -67,6 +67,17 @@
return array_reverse($result);
}
+ public function getSemanticTokensBefore() {
+ $tokens = $this->tree->getRawTokenStream();
+ $result = array();
+ $ii = $this->id - 1;
+ while ($ii >= 0 && $tokens[$ii]->isSemantic()) {
+ $result[$ii] = $tokens[$ii];
+ --$ii;
+ }
+ return array_reverse($result);
+ }
+
public function getNonsemanticTokensAfter() {
$tokens = $this->tree->getRawTokenStream();
$result = array();
@@ -78,4 +89,15 @@
return $result;
}
+ public function getSemanticTokensAfter() {
+ $tokens = $this->tree->getRawTokenStream();
+ $result = array();
+ $ii = $this->id + 1;
+ while ($ii < count($tokens) && $tokens[$ii]->isSemantic()) {
+ $result[$ii] = $tokens[$ii];
+ ++$ii;
+ }
+ return $result;
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 15, 2:43 AM (1 w, 1 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7282622
Default Alt Text
D10554.id25359.diff (2 KB)

Event Timeline