Sprout
repeat を使用します。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> #include <iostream> template<typename Parsed> struct parsed_holder{ constexpr operator bool() const{ return parsed.success(); } template<typename T> constexpr bool operator ==(T</typename></typename></iostream></sprout/weed.hpp>…
元々これがやりたくてコンパイル時パーサが欲しかったんですが、今のレベルでどれほどのものなのか試してみました。 Shader はここの example から拝借 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Parsed> struct pa</typename></sprout/weed.hpp>…
以前もチラッと書いたのですが、もうちょっと分かりやすい違いをコードで書いてみました。 知っておいて損はないかな? [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Parsed> struct parsed_holder{ constexpr operato</typename></sprout/weed.hpp>…
やってみました。 __FILE__ とかがコンパイル時にパースできますね。 果たして必要になるときが来るのだろか…。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> #include <sprout/tuple/array.hpp> #include <iostream> template<typename Parsed> struct parsed_holder{ cons</typename></iostream></sprout/tuple/array.hpp></sprout/weed.hpp>…
例えがちょっと分かりづらいんですが、文字列を複数読み込む場合に戻り値型がちょっと複雑だったので覚書。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> #include <sprout/string/alias.hpp> int main(){ namespace w = sprout::weed; static co</sprout/string/alias.hpp></sprout/weed.hpp>…
前回はアンダーバーを取り除いただけでしたが、今回は、 4桁区切りで読み込む prefix を定義 「_」,「.」,「,」 のどれかで区切れる という感じに改良してみました。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> templ</sprout/weed.hpp>…
某掲示板で見かけたのでやってみました。 アンダーバー区切りの2進数文字リテラルを Sprout.Weed を使ってコンパイル時に整数に変換します。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Parsed> constexpr long long</typename></sprout/weed.hpp>…
とりあえず、自力で書いてみました。 構文解析とかあんまりやったことが無いので、もっと簡単なやり方がありそうですね。 コードがだいぶアレな感じになってしまってぐぬぬ。 多分問題ない…はず。 ちなみに括弧は対応していないです。 [ソース] #define SPRO…
strtol の第二引数と同じですね。 メンバ関数 current() で取得出来るみたいです。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> int main(){ namespace w = sprout::weed; { static constexpr auto data = sprout::to_</sprout/weed.hpp>…
weed::eol を使用します。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> #include <iostream> #include <sprout/array.hpp> #include <sprout/tuple/array.hpp> #include <sprout/string/alias.hpp> template<typename Parsed> struct parsed_holder{ constexpr operator bool(…</typename></sprout/string/alias.hpp></sprout/tuple/array.hpp></sprout/array.hpp></iostream></sprout/weed.hpp>
出来そうだったのでやってみた。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> #include <iostream> template<typename Parsed> struct parsed_holder{ constexpr operator bool() const{ return parsed.success(); } template<typename T> constexpr bool oper</typename></typename></iostream></sprout/weed.hpp>…
weed::eoi を使用します。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Parsed> struct parsed_holder{ constexpr operator bool() const{ return parsed.success(); } template<typename T> constexpr bool operator ==(T&& t) c</typename></typename></sprout/weed.hpp>…
さて、 homu:mado のような『:』区切りの構文をパースする場合、 namespace weed = sprout::weed; static constexpr auto parser = *weed::lim<4>(weed::char_ - ':') >> ":" >> *weed::lim<4>(weed::char_); のようなパーサを記述すると思います。 しかし、…
Sprout の index_iterator で簡単に実装出来そうだったのでちょっと試してみた。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/algorithm/transform.hpp> #include <sprout/iterator/index_iterator.hpp> #include <sprout/array.hpp> #include <sprout/pit.hpp> #include <iostream> template</iostream></sprout/pit.hpp></sprout/array.hpp></sprout/iterator/index_iterator.hpp></sprout/algorithm/transform.hpp>
ちょっとハマったことがあったので覚書 [比較] Sprout.Variant で比較を行う場合、型が合っていないとエラーになります。 typedef sprout::variant<int, float> var_type; static constexpr var_type x{10}; static_assert(x == 10, ""); static_assert(x != 0.0f, ""); </int,>…
Sprout.Weed では以下の符号付き10進数のパーサが用意されています。 Expression Attribute uint_ std::uintmax_t uint8 std::uint8_t uint16 std::uint16_t uint32 std::uint32_t uint64 std::uint64_t [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_C…
*weed::omit[a]という記述で連続した a を無視することが出来ます。 これを利用して連続したスペースを無視します。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Parsed> struct parsed_holder{ constexpr operator b</typename></sprout/weed.hpp>…
weed::omit を使用して特定の構文を無視することが出来ます。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Parsed> struct parsed_holder{ constexpr operator bool() const{ return parsed.success(); } template<typename T> co</typename></typename></sprout/weed.hpp>…
演算子を使用して // 数値かアルファベットにマッチするパーサ weed::int_ | weed::alpha のようなパーサを記述することが出来ます。 また、上記のパーサだと attribute の型は sprout::variant<std::intmax_t, char> のように sprout::variant 型になります。 [ソース] #define S</std::intmax_t,>…
Sprout.Weed では以下の符号付き10進数のパーサが用意されています。 Expression Attribute int_ std::intmax_t int8 std::int8_t int16 std::int16_t int32 std::int32_t int64 std::int64_t [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_I…
テストしやすいようにちょっとラップしてみました。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Parsed> struct parsed_holder{ constexpr operator bool() const{ return parsed.success(); } template<typename T> constexpr b</typename></typename></sprout/weed.hpp>…
次のように特定の文字まで文字列を読み込む場合に、マイナス演算子を使用して、特定の文字をマッチさせないようにします。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Char, std::size_t N, typename Parser> constexpr bool check_parser(Char con</typename></sprout/weed.hpp>…
weed::char_ と weed::lim を利用して複数の文字のパースを行います。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> template<typename Char, std::size_t N, typename Parser> constexpr bool check_parser(Char const(&str)[N], Parser&& parser){ using sprout::weed</typename></sprout/weed.hpp>…
Boost.Spirit.Qi のドキュメントに載っている test_parser を Sprout.Weed でも書いてみました。 ただし、関数内で static_assert はできないので、結果の出力は実行時に行います。 コンパイル時にチェックを行いたい場合は、check_parser で static_assert …
やっとこさはじめました。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/weed.hpp> #include <sprout/string.hpp> #include <boost/mpl/print.hpp> #include <boost/mpl/int.hpp> int main(){ namespace weed = sprout::weed; using weed::int_; // 21:53:49 というような構文を解析 constexpr</boost/mpl/int.hpp></boost/mpl/print.hpp></sprout/string.hpp></sprout/weed.hpp>…
まぁそんな感じの処理です。 関数の引数を Tuple で渡して評価します。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/tuple.hpp> template<std::size_t... Indices> struct index_tuple{}; template< std::size_t Start, std::size_t Finish, std::size_t S</std::size_t...></sprout/tuple.hpp>…
Sprout 側で処理できるようにゴニョゴニョと拡張してみました。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <functional> #include <sprout/tuple.hpp> #include <sprout/string.hpp> template<typename Tuple, typename F> struct transform_view_tuple{ Tuple tuple; F func; }; namespace sprout{ </typename></sprout/string.hpp></sprout/tuple.hpp></functional>…
って事でやってみました。 counting_iterator が欲しくなりますね。 [ソース] #define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION #include <sprout/algorithm/transform.hpp> #include <sprout/array.hpp> #include <sprout/string.hpp> #include <sprout/string/alias.hpp> #include <sprout/operation.hpp> #include <iostream> templa…</iostream></sprout/operation.hpp></sprout/string/alias.hpp></sprout/string.hpp></sprout/array.hpp></sprout/algorithm/transform.hpp>