BenHanson / parsertl14

C++14 version of parsertl
32 stars 4 forks source link

Documentation example doesn't work #6

Closed mingodad closed 11 months ago

mingodad commented 11 months ago

While trying the examples in http://benhanson.net/parsertl.html the search example give this error:

g++ -std=c++17   -c -g -I../../parsertl14/include -I../../lexertl14/include -MMD -MP -MF "build/Debug/GNU-Linux/_ext/5c0/search.o.d" -o build/Debug/GNU-Linux/_ext/5c0/search.o ../search.cpp
../search.cpp: In function ‘int main(int, char**)’:
../search.cpp:57:58: error: no matching function for call to ‘search(lexertl::citerator&, lexertl::citerator&, parsertl::state_machine&, std::set<long unsigned int>*)’
   57 |             if (parsertl::search(iter_, end_, gsm_, &set_))
      |                                                          ^
In file included from ../search.cpp:3:
../../parsertl14/include/parsertl/search.hpp:43:10: note: candidate: ‘bool parsertl::search(lexer_iterator&, lexer_iterator&, const sm_type&, captures&) [with lexer_iterator = lexertl::iterator<const char*, lexertl::basic_state_machine<char>, lexertl::match_results<const char*> >; sm_type = parsertl::basic_state_machine<short unsigned int>; captures = std::set<long unsigned int>*]’ <near match>
   43 |     bool search(lexer_iterator& iter_, lexer_iterator& end_, const sm_type& sm_,
      |          ^~~~~~
../../parsertl14/include/parsertl/search.hpp:43:10: note:   conversion of argument 4 would be ill-formed:
../search.cpp:57:53: error: cannot bind non-const lvalue reference of type ‘std::set<long unsigned int>*&’ to an rvalue of type ‘std::set<long unsigned int>*’
   57 |             if (parsertl::search(iter_, end_, gsm_, &set_))
      |                                                     ^~~~~
In file included from ../search.cpp:3:
../../parsertl14/include/parsertl/search.hpp:105:10: note: candidate: ‘bool parsertl::search(lexer_iterator&, lexer_iterator&, const sm_type&, std::set<typename sm_type::id_type>*) [with lexer_iterator = lexertl::iterator<const char*, lexertl::basic_state_machine<char>, lexertl::match_results<const char*> >; sm_type = parsertl::basic_state_machine<short unsigned int>; typename sm_type::id_type = short unsigned int]’
  105 |     bool search(lexer_iterator& iter_, lexer_iterator& end_, const sm_type& sm_,
      |          ^~~~~~
../../parsertl14/include/parsertl/search.hpp:106:46: note:   no known conversion for argument 4 from ‘std::set<long unsigned int>*’ to ‘std::set<short unsigned int, std::less<short unsigned int>, std::allocator<short unsigned int> >*’
  106 |         std::set<typename sm_type::id_type>* prod_set_ = nullptr)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
../../parsertl14/include/parsertl/search.hpp:164:10: note: candidate: ‘template<class lexer_iterator, class sm_type, class token_vector> bool parsertl::search(lexer_iterator&, lexer_iterator&, const sm_type&, std::multimap<typename sm_type::id_type, token_vector>*)’
  164 |     bool search(lexer_iterator& iter_, lexer_iterator& end_, const sm_type& sm_,
      |          ^~~~~~
../../parsertl14/include/parsertl/search.hpp:164:10: note:   template argument deduction/substitution failed:
../search.cpp:57:58: note:   ‘std::set<long unsigned int>’ is not derived from ‘std::multimap<typename sm_type::id_type, token_vector>’
   57 |             if (parsertl::search(iter_, end_, gsm_, &set_))
      |                                                          ^
BenHanson commented 11 months ago

The solution is to replace the 3 instances of std::size_t to uint16_t when using parsertl14.

I have updated the webpage.

mingodad commented 11 months ago

Thanks !