Node does not name a type


#1

I am currently trying to create a custom visitor in c++, however I am getting an error that is preventing compilation. I am using “node” for traversing the tree and I have included the appropriate header files, however the compiler is not having it and is telling me that node does not name a type.

phrase_finder.h

#ifndef META_PARSER_PHRASE_FINDER_H_
#define META_PARSER_PHRASE_FINDER_H_

#include <memory>
#include <vector>

#include "meta/parser/trees/visitors/visitor.h"

namespace meta
{
namespace parser
{

class phrase_finder : public const_visitor<void>
{
  public:
    void operator()(const leaf_node&) override;
    void operator()(const internal_node&) override;

    std::vector<std::unique_ptr<internal_node>> phrase();

  private:
    std::vector<std::unique_ptr<internal_node>> nodes_;
};
}
}

#endif

phrase_finder.cpp

#include "phrase_finder.h"
#include "meta/parser/trees/node.h"
#include "meta/parser/trees/leaf_node.h"
#include "meta/parser/trees/internal_node.h"
#include "meta/util/shim.h"

namespace meta
{
namespace parser
{
void phrase_finder::operator()(const leaf_node& node)
{
  return;
}

void phrase_finder::operator()(const internal_node& node)
{
  if (node.category() == node.category())
  {
    nodes_.push_back(make_unique<internal_node>(node));
  }
  else
  {
    node.each_child([&](const node* child)
                    {
                      child->accept(*this);
                    });
  }
}

std::vector<std::unique_ptr<internal_node>> phrase_finder::phrase()
{
  return std::move(nodes_);
}
}
}

compiler output

[ 25%] Building CXX object src/parseInput/CMakeFiles/parseInput.dir/parseInput.cpp.o
In file included from /home/c1user/Programming/Ygor/src/parseInput/parseInput.cpp:9:0:
/home/c1user/Programming/Ygor/src/parseInput/phrase_finder.cpp: In member function ‘virtual void meta::parser::phrase_finder::operator()(const meta::parser::internal_node&)’:
/home/c1user/Programming/Ygor/src/parseInput/phrase_finder.cpp:23:29: error: ‘node’ does not name a type
   node.each_child([&](const node* child)
                             ^~~~
/home/c1user/Programming/Ygor/src/parseInput/phrase_finder.cpp: In lambda function:
/home/c1user/Programming/Ygor/src/parseInput/phrase_finder.cpp:26:21: error: expected ‘{’ before ‘;’ token
                   });
                     ^
/home/c1user/Programming/Ygor/src/parseInput/phrase_finder.cpp: In member function ‘virtual void meta::parser::phrase_finder::operator()(const meta::parser::internal_node&)’:
/home/c1user/Programming/Ygor/src/parseInput/phrase_finder.cpp:26:21: error: expected ‘)’ before ‘;’ token
src/parseInput/CMakeFiles/parseInput.dir/build.make:62: recipe for target 'src/parseInput/CMakeFiles/parseInput.dir/parseInput.cpp.o' failed
make[2]: *** [src/parseInput/CMakeFiles/parseInput.dir/parseInput.cpp.o] Error 1
CMakeFiles/Makefile2:140: recipe for target 'src/parseInput/CMakeFiles/parseInput.dir/all' failed
make[1]: *** [src/parseInput/CMakeFiles/parseInput.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

#2

My file wasn’t in the appropriate meta file, I needed to include “parser” namespace, or change “node” to “parser::node” to get it to work where it is.