PageRenderTime 42ms CodeModel.GetById 18ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/spirit/home/support/detail/lexer/parser/tree/leaf_node.hpp

http://pythonocc.googlecode.com/
C++ Header | 107 lines | 88 code | 14 blank | 5 comment | 5 complexity | 31e5fee0d8d7c53c66af4b30441e73d0 MD5 | raw file
  1// leaf_node.hpp
  2// Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/)
  3//
  4// Distributed under the Boost Software License, Version 1.0. (See accompanying
  5// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6#ifndef BOOST_LEXER_LEAF_NODE_HPP
  7#define BOOST_LEXER_LEAF_NODE_HPP
  8
  9#include "../../consts.hpp" // null_token
 10#include "node.hpp"
 11#include "../../size_t.hpp"
 12
 13namespace boost
 14{
 15namespace lexer
 16{
 17namespace detail
 18{
 19class leaf_node : public node
 20{
 21public:
 22    leaf_node (const std::size_t token_, const bool greedy_) :
 23        node (token_ == null_token),
 24        _token (token_),
 25        _set_greedy (!greedy_),
 26        _greedy (greedy_)
 27    {
 28        if (!_nullable)
 29        {
 30            _firstpos.push_back (this);
 31            _lastpos.push_back (this);
 32        }
 33    }
 34
 35    virtual ~leaf_node ()
 36    {
 37    }
 38
 39    virtual void append_followpos (const node_vector &followpos_)
 40    {
 41        for (node_vector::const_iterator iter_ = followpos_.begin (),
 42            end_ = followpos_.end (); iter_ != end_; ++iter_)
 43        {
 44            _followpos.push_back (*iter_);
 45        }
 46    }
 47
 48    virtual type what_type () const
 49    {
 50        return LEAF;
 51    }
 52
 53    virtual bool traverse (const_node_stack &/*node_stack_*/,
 54        bool_stack &/*perform_op_stack_*/) const
 55    {
 56        return false;
 57    }
 58
 59    virtual std::size_t token () const
 60    {
 61        return _token;
 62    }
 63
 64    virtual void greedy (const bool greedy_)
 65    {
 66        if (!_set_greedy)
 67        {
 68            _greedy = greedy_;
 69            _set_greedy = true;
 70        }
 71    }
 72
 73    virtual bool greedy () const
 74    {
 75        return _greedy;
 76    }
 77
 78    virtual const node_vector &followpos () const
 79    {
 80        return _followpos;
 81    }
 82
 83    virtual node_vector &followpos ()
 84    {
 85        return _followpos;
 86    }
 87
 88private:
 89    std::size_t _token;
 90    bool _set_greedy;
 91    bool _greedy;
 92    node_vector _followpos;
 93
 94    virtual void copy_node (node_ptr_vector &node_ptr_vector_,
 95        node_stack &new_node_stack_, bool_stack &/*perform_op_stack_*/,
 96        bool &/*down_*/) const
 97    {
 98        node_ptr_vector_->push_back (static_cast<leaf_node *>(0));
 99        node_ptr_vector_->back () = new leaf_node (_token, _greedy);
100        new_node_stack_.push (node_ptr_vector_->back ());
101    }
102};
103}
104}
105}
106
107#endif