mediawiki-extensions-AbuseF.../includes/parser/AFPSyntaxTree.php
Daimona Eaytoy d515af0ae6 Add a new class for the CachingParser's AST
This allows a little bit more of abstraction: we can store other data in the
tree, without having to store it in a specific node (e.g. the variables map,
which is still unused). It also adds a few typehints, and specializes
the return value of eval'ing the AST: previously, it was the one of
evalNode, which wasn't guaranteed to be an AFPData. Now we have this
guarantee. Last but not least, we can now measure runtime metrics for
evalTree, which doesn't recurse.
Bonus: fix a check in the old parser, which used the wrong variable when
reporting outofbounds errors.

Change-Id: Iff806793b1d968e9bb6220f1459f3d0ac587c7da
2019-08-25 17:29:16 +00:00

40 lines
708 B
PHP

<?php
/**
* A class representing a whole AST generated by AFPTreeParser, holding AFPTreeNode's and a list
* of custom variable names.
*/
class AFPSyntaxTree {
/**
* @var AFPTreeNode|null
*/
private $rootNode;
/**
* @var string[]
*/
private $variableNames;
/**
* @param string[] $variableNames
* @param AFPTreeNode|null $root
*/
public function __construct( array $variableNames, AFPTreeNode $root = null ) {
$this->rootNode = $root;
$this->variableNames = $variableNames;
}
/**
* @return AFPTreeNode|null
*/
public function getRoot() {
return $this->rootNode;
}
/**
* @return string[]
*/
public function getVariableNames() {
return $this->variableNames;
}
}