#include "tree/ParseTree.h"
#include "tree/Trees.h"
#include "XPathRuleElement.h"
using namespace antlr4::tree;
using namespace antlr4::tree::xpath;
XPathRuleElement::XPathRuleElement(const std::string &ruleName, size_t ruleIndex) : XPathElement(ruleName) {
_ruleIndex = ruleIndex;
}
std::vector<ParseTree *> XPathRuleElement::evaluate(ParseTree *t) {
std::vector<ParseTree *> nodes;
for (auto *c : t->children) {
if (antlrcpp::is<ParserRuleContext *>(c)) {
ParserRuleContext *ctx = dynamic_cast<ParserRuleContext *>(c);
if ((ctx->getRuleIndex() == _ruleIndex && !_invert) || (ctx->getRuleIndex() != _ruleIndex && _invert)) {
nodes.push_back(ctx);
}
}
}
return nodes;
}