2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2014-01-08 07:48:12 +00:00
|
|
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-09-21 06:43:30 +00:00
|
|
|
#ifndef SPROUT_BRAINFUCK_OOK_HPP
|
|
|
|
#define SPROUT_BRAINFUCK_OOK_HPP
|
|
|
|
|
|
|
|
#include <iterator>
|
|
|
|
#include <sprout/config.hpp>
|
2013-02-07 14:12:57 +00:00
|
|
|
#include <sprout/utility/pair/pair.hpp>
|
2012-09-21 06:43:30 +00:00
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
2013-11-20 13:04:11 +00:00
|
|
|
#include <sprout/algorithm/fixed/results.hpp>
|
2012-09-21 06:43:30 +00:00
|
|
|
#include <sprout/weed/parse.hpp>
|
|
|
|
#include <sprout/weed/parser/lim.hpp>
|
|
|
|
#include <sprout/weed/parser/lit.hpp>
|
|
|
|
#include <sprout/weed/parser/char/char.hpp>
|
|
|
|
#include <sprout/weed/parser/char/char_class.hpp>
|
|
|
|
#include <sprout/weed/parser/string/string.hpp>
|
|
|
|
#include <sprout/weed/parser/directive/replace.hpp>
|
|
|
|
#include <sprout/weed/operator.hpp>
|
|
|
|
#include <sprout/brainfuck/detail/convert.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace brainfuck {
|
|
|
|
namespace ook {
|
|
|
|
//
|
|
|
|
// to_brainfuck
|
|
|
|
//
|
|
|
|
template<typename InputIterator, typename Result>
|
2013-11-20 13:04:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::pair<typename sprout::fixed::results::algorithm<Result>::type, bool>
|
2012-09-21 06:43:30 +00:00
|
|
|
to_brainfuck(InputIterator first, InputIterator last, Result const& result) {
|
|
|
|
return sprout::brainfuck::detail::parsed_to_brainfuck(
|
|
|
|
sprout::weed::parse(
|
|
|
|
first, last,
|
|
|
|
*sprout::weed::lim<sprout::container_traits<Result>::static_size>(
|
|
|
|
sprout::weed::replace('>')
|
|
|
|
["Ook." >> *sprout::weed::space_ >> "Ook?"]
|
|
|
|
| sprout::weed::replace('>')
|
|
|
|
["Ook?" >> *sprout::weed::space_ >> "Ook."]
|
|
|
|
| sprout::weed::replace('>')
|
|
|
|
["Ook." >> *sprout::weed::space_ >> "Ook."]
|
|
|
|
| sprout::weed::replace('>')
|
|
|
|
["Ook!" >> *sprout::weed::space_ >> "Ook!"]
|
|
|
|
| sprout::weed::replace('>')
|
|
|
|
["Ook!" >> *sprout::weed::space_ >> "Ook."]
|
|
|
|
| sprout::weed::replace('>')
|
|
|
|
["Ook." >> *sprout::weed::space_ >> "Ook!"]
|
|
|
|
| sprout::weed::replace('>')
|
|
|
|
["Ook!" >> *sprout::weed::space_ >> "Ook?"]
|
|
|
|
| sprout::weed::replace('>')
|
|
|
|
["Ook?" >> *sprout::weed::space_ >> "Ook!"]
|
|
|
|
| sprout::weed::replace(' ')
|
|
|
|
[sprout::weed::char_]
|
|
|
|
)
|
|
|
|
),
|
|
|
|
result
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// exec_range
|
|
|
|
//
|
2013-02-03 16:10:26 +00:00
|
|
|
template<std::size_t BufferSize = 32, typename BidirectionalRangeSource, typename Output, typename InputRangeInput>
|
2013-11-20 13:04:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Output>::type
|
2013-02-03 16:10:26 +00:00
|
|
|
exec_range(BidirectionalRangeSource const& source, Output const& output, InputRangeInput const& input) {
|
|
|
|
typedef typename sprout::container_construct_traits<BidirectionalRangeSource>::copied_type copied_type;
|
2012-09-21 06:43:30 +00:00
|
|
|
return sprout::brainfuck::exec_range<BufferSize>(
|
|
|
|
sprout::brainfuck::ook::to_brainfuck(sprout::begin(source), sprout::end(source), sprout::pit<copied_type>()).first,
|
|
|
|
output, input
|
|
|
|
);
|
|
|
|
}
|
2013-02-03 16:10:26 +00:00
|
|
|
template<std::size_t BufferSize = 32, typename BidirectionalRangeSource, typename Output>
|
2013-11-20 13:04:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Output>::type
|
2013-02-03 16:10:26 +00:00
|
|
|
exec_range(BidirectionalRangeSource const& source, Output const& output) {
|
|
|
|
typedef typename sprout::container_construct_traits<BidirectionalRangeSource>::copied_type copied_type;
|
2012-09-21 06:43:30 +00:00
|
|
|
return sprout::brainfuck::exec_range<BufferSize>(
|
|
|
|
sprout::brainfuck::ook::to_brainfuck(sprout::begin(source), sprout::end(source), sprout::pit<copied_type>()).first,
|
|
|
|
output
|
|
|
|
);
|
|
|
|
}
|
2013-02-03 16:10:26 +00:00
|
|
|
template<std::size_t BufferSize = 32, typename BidirectionalRangeSource>
|
2013-11-20 13:04:11 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<
|
2013-02-03 16:10:26 +00:00
|
|
|
sprout::array<typename sprout::container_traits<BidirectionalRangeSource>::value_type, BufferSize>
|
2012-09-21 06:43:30 +00:00
|
|
|
>::type
|
2013-02-03 16:10:26 +00:00
|
|
|
exec_range(BidirectionalRangeSource const& source) {
|
|
|
|
typedef typename sprout::container_construct_traits<BidirectionalRangeSource>::copied_type copied_type;
|
2012-09-21 06:43:30 +00:00
|
|
|
return sprout::brainfuck::exec_range<BufferSize>(
|
|
|
|
sprout::brainfuck::ook::to_brainfuck(sprout::begin(source), sprout::end(source), sprout::pit<copied_type>()).first
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} // namespace ook
|
|
|
|
} // namespace brainfuck
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_BRAINFUCK_OOK_HPP
|