taocpp / PEGTL

Parsing Expression Grammar Template Library
Boost Software License 1.0
1.95k stars 228 forks source link

tao/pegtl/match.hpp:143:14: error: value of type 'std::__1::pair<bool, unsigned long>' is not contextually convertible to 'bool' #286

Closed mgood7123 closed 2 years ago

mgood7123 commented 2 years ago

when i try to compile this

using namespace tao;
//
        template <typename ParseInput>
        [[nodiscard]] const char* line_at( const ParseInput& in, const pegtl::position& p ) const noexcept
        {
            using input_t = pegtl::memory_input< pegtl::tracking_mode::lazy, pegtl::eol::lf, const char* >;
            input_t in_( in.at( p ), in.end(), "" );

            using grammar = pegtl::until< pegtl::at< pegtl::eol::lf > >;

            (void)pegtl::normal< grammar >::match< pegtl::apply_mode::nothing, pegtl::rewind_mode::dontcare, pegtl::nothing, pegtl::normal >( in_ );

            return in_.current();
        }

i get this error

In file included from /Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/PEGTL/include/tao/pegtl/contrib/../normal.hpp:14:
/Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/PEGTL/include/tao/pegtl/match.hpp:143:14: error: value of type 'std::__1::pair<bool, unsigned long>' is not contextually convertible to 'bool'
         if( result ) {
             ^~~~~~
/Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/PEGTL/include/tao/pegtl/contrib/../normal.hpp:93:41: note: in instantiation of function template specialization 'tao::pegtl::match<tao::pegtl::ascii::eol::lf, tao::pegtl::apply_mode::nothing, tao::pegtl::rewind_mode::active, nothing, normal, tao::pegtl::memory_input<tao::pegtl::tracking_mode::lazy, tao::pegtl::ascii::eol::lf, const char *>>' requested here
            return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
                                        ^
/Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/PEGTL/include/tao/pegtl/internal/at.hpp:47:43: note: in instantiation of function template specialization 'tao::pegtl::normal<tao::pegtl::ascii::eol::lf>::match<tao::pegtl::apply_mode::nothing, tao::pegtl::rewind_mode::active, nothing, normal, tao::pegtl::memory_input<tao::pegtl::tracking_mode::lazy, tao::pegtl::ascii::eol::lf, const char *>>' requested here
         return Control< Rule >::template match< apply_mode::nothing, rewind_mode::active, Action, Control >( in, st... );
                                          ^
/Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/PEGTL/include/tao/pegtl/match.hpp:45:32: note: in instantiation of function template specialization 'tao::pegtl::internal::at<tao::pegtl::ascii::eol::lf>::match<tao::pegtl::apply_mode::nothing, tao::pegtl::rewind_mode::required, nothing, normal, tao::pegtl::memory_input<tao::pegtl::tracking_mode::lazy, tao::pegtl::ascii::eol::lf, const char *>>' requested here
         return Rule::template match< A, M, Action, Control >( in, st... );
                               ^
/Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/PEGTL/include/tao/pegtl/match.hpp:85:20: note: in instantiation of function template specialization 'tao::pegtl::internal::match_no_control<tao::pegtl::at<tao::pegtl::ascii::eol::lf>, tao::pegtl::apply_mode::nothing, tao::pegtl::rewind_mode::required, nothing, normal, tao::pegtl::memory_input<tao::pegtl::tracking_mode::lazy, tao::pegtl::ascii::eol::lf, const char *>>' requested here
            return match_no_control< Rule, A, M, Action, Control >( in, st... );
                   ^
/Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/PEGTL/include/tao/pegtl/internal/until.hpp:46:44: note: in instantiation of function template specialization 'tao::pegtl::normal<tao::pegtl::at<tao::pegtl::ascii::eol::lf> >::match<tao::pegtl::apply_mode::nothing, tao::pegtl::rewind_mode::required, nothing, normal, tao::pegtl::memory_input<tao::pegtl::tracking_mode::lazy, tao::pegtl::ascii::eol::lf, const char *>>' requested here
         while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) {
                                           ^
/Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/PEGTL/include/tao/pegtl/match.hpp:45:32: note: (skipping 2 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
         return Rule::template match< A, M, Action, Control >( in, st... );
                               ^
/Users/smallville7123/StudioProjects/Astrid/app/src/main/cpp/MainApplication_CPP/./GLShaper/PSL_TRACE.h:101:45: note: in instantiation of function template specialization 'tao::pegtl::normal<tao::pegtl::until<tao::pegtl::at<tao::pegtl::ascii::eol::lf>> >::match<tao::pegtl::apply_mode::nothing, tao::pegtl::rewind_mode::dontcare, pegtl::nothing, pegtl::normal, tao::pegtl::memory_input<tao::pegtl::tracking_mode::lazy, tao::pegtl::ascii::eol::lf, const char *>>' requested here
            (void)pegtl::normal< grammar >::match< pegtl::apply_mode::nothing, pegtl::rewind_mode::dontcare, pegtl::nothing, pegtl::normal >( in_ );
                                            ^
ColinH commented 2 years ago

Class tao::pegtl::eol is a rule class and can be used as such, however tao::pegtl::eol::lf etc. are not rule classes. This would probably be more obvious if the methods they had weren't called match(), which is something we can easily change.

mgood7123 commented 2 years ago

oh ok

it would be easier if all the classes where seperated into seperate namespaces, like

rules:: actions:: states:: (if any) and so on

ColinH commented 2 years ago

There is https://github.com/taocpp/PEGTL/blob/main/doc/Rule-Reference.md.