]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/tree/xpath/XPathTokenElement.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / tree / xpath / XPathTokenElement.cpp
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #include "tree/ParseTree.h"
7 #include "tree/Trees.h"
8 #include "support/CPPUtils.h"
9 #include "Token.h"
10
11 #include "XPathTokenElement.h"
12
13 using namespace antlr4;
14 using namespace antlr4::tree;
15 using namespace antlr4::tree::xpath;
16
17 XPathTokenElement::XPathTokenElement(const std::string &tokenName, size_t tokenType) : XPathElement(tokenName) {
18   _tokenType = tokenType;
19 }
20
21 std::vector<ParseTree *> XPathTokenElement::evaluate(ParseTree *t) {
22   // return all children of t that match nodeName
23   std::vector<ParseTree *> nodes;
24   for (auto *c : t->children) {
25     if (antlrcpp::is<TerminalNode *>(c)) {
26       TerminalNode *tnode = dynamic_cast<TerminalNode *>(c);
27       if ((tnode->getSymbol()->getType() == _tokenType && !_invert) || (tnode->getSymbol()->getType() != _tokenType && _invert)) {
28         nodes.push_back(tnode);
29       }
30     }
31   }
32   return nodes;
33 }