text: #include <ctpg/ctpg.hpp>
  #include <iostream>
  
  using namespace ctpg;
  using namespace ctpg::buffers;
  
  constexpr nterm<int> list("list");
  
  constexpr char number_pattern[] = "[1-9][0-9]*";
  constexpr regex_term<number_pattern> number("number");
  
  constexpr int to_int(std::string_view sv)
  {
      int sum = 0;
      for (auto c : sv) { sum *= 10; sum += c - '0'; }
      return sum;
  }
  
  constexpr parser p(
      list,
      terms(',', number),
      nterms(list),
      rules(
          list(number)
              >= to_int,
          list(list, ',', number)
              >= [](int sum, char, const auto& n){ return sum + to_int(n); }
      )
  );
  
  int main(int argc, char* argv[])
  {
      if (argc < 2)
      {
          constexpr char example_text[] = "1, 2, 3";
          constexpr auto cres = p.parse(cstring_buffer(example_text));
          std::cout << cres.value() << std::endl;
          return 0;
      }
  
      auto res = p.parse(string_buffer(argv[1]), std::cerr);
      bool success = res.has_value();
      if (success)
          std::cout << res.value() << std::endl;
      return success ? 0 : -1;
  }
  