Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a way to provide the line that doesn't compile in the compilation error #178

Open
EmmanuelMess opened this issue Oct 14, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@EmmanuelMess
Copy link

I am having trouble finding where compilation errors are happening using this library. I usually end up adding small components (single elements of a production) of the formal language one at a time. Is there a way to link the compilation error with the original code that produced it?

@EmmanuelMess EmmanuelMess changed the title Find a way to provide the line that doesn't compile on compilation error Find a way to provide the line that doesn't compile in the compilation error Oct 14, 2023
@foonathan
Copy link
Owner

Can you give an example of errors that don't make it clear where they are produced?

@EmmanuelMess
Copy link
Author

EmmanuelMess commented Oct 14, 2023

FAILED: src/main_app/input_reader/CMakeFiles/input_reader.dir/Parser.cpp.o 
/home/emmanuel/Rápido/JetBrains/Toolbox/clion/bin/cmake/linux/x64/bin/cmake -E __run_co_compile --launcher=/usr/bin/ccache --cppcheck="/usr/bin/cppcheck;--template=gcc;--enable=style,performance,warning,portability;--inline-suppr;--suppress=cppcheckError;--suppress=internalAstError;--suppress=unmatchedSuppression;--suppress=passedByValue;--suppress=syntaxError;--suppress=preprocessorErrorDirective;--inconclusive;--std=c++20;--error-exitcode=2" --source=/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/src/main_app/input_reader/Parser.cpp -- /usr/bin/g++-10 -DLEXY_HAS_UNICODE_DATABASE=1 -DSAMPLE_LIBRARY_STATIC_DEFINE -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -I/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/include -I/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/include -isystem /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/spdlog-src/include -isystem /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/fmt-src/include -isystem /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/src/../include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fcf-protection -fstack-clash-protection  -D_GLIBCXX_ASSERTIONS -O3 -DNDEBUG -std=c++2a -flto=auto -fno-fat-lto-objects -fvisibility=hidden -fvisibility-inlines-hidden -fdiagnostics-color=always -fdiagnostics-color=always -fsanitize=address,undefined -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wuseless-cast -Werror -Wno-readability-redundant-member-init -pthread -MD -MT src/main_app/input_reader/CMakeFiles/input_reader.dir/Parser.cpp.o -MF src/main_app/input_reader/CMakeFiles/input_reader.dir/Parser.cpp.o.d -o src/main_app/input_reader/CMakeFiles/input_reader.dir/Parser.cpp.o -c /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/src/main_app/input_reader/Parser.cpp
Checking /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/src/main_app/input_reader/Parser.cpp ...
Checking /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/src/main_app/input_reader/Parser.cpp: LEXY_HAS_UNICODE_DATABASE=1;SAMPLE_LIBRARY_STATIC_DEFINE=1;SPDLOG_COMPILED_LIB=1;SPDLOG_FMT_EXTERNAL=1;_FORTIFY_SOURCE=3;_GLIBCXX_ASSERTIONS=1;NDEBUG=1...
In file included from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/dsl/base.hpp:9,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/base.hpp:11,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/parse.hpp:8,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/include/main_app/input_reader/LexyComponents.hpp:8,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/include/main_app/input_reader/Parser.hpp:6,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/src/main_app/input_reader/Parser.cpp:1:
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/grammar.hpp: In instantiation of ‘constexpr void lexy::_sfinae_sink<Production, Sink>::operator()(Args&& ...) [with Args = {input_reader::internal::ast::PropertyIdentifier}; Production = input_reader::internal::parser::FunctionConstraint; Sink = lexy::_as_aggregate<input_reader::internal::ast::FunctionConstraint>::_sink]’:
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/dsl/base.hpp:178:17:   required from ‘static constexpr std::true_type lexy::sink_parser::parse(Context&, Reader&, Sink&, Args&& ...) [with Context = lexy::_pc<lexy::_ph<lexy::_br8>, void, input_reader::internal::parser::FunctionConstraint, input_reader::internal::parser::SimulationState>; Reader = lexy::_br8; Sink = lexy::_sfinae_sink<input_reader::internal::parser::FunctionConstraint, lexy::_as_aggregate<input_reader::internal::ast::FunctionConstraint>::_sink>; Args = {input_reader::internal::ast::PropertyIdentifier}; std::true_type = std::integral_constant<bool, true>]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/base.hpp:190:39:   required from ‘static constexpr bool lexy::_detail::context_finish_parser<NextParser>::parse(Context&, Reader&, SubContext&, Args&& ...) [with Context = lexy::_pc<lexy::_ph<lexy::_br8>, void, input_reader::internal::parser::FunctionConstraint, input_reader::internal::parser::SimulationState>; Reader = lexy::_br8; SubContext = lexy::_pc<lexy::_ph<lexy::_br8>, void, input_reader::internal::parser::PropertyIdentifier, input_reader::internal::parser::SimulationState>; Args = {lexy::_sfinae_sink<input_reader::internal::parser::FunctionConstraint, lexy::_as_aggregate<input_reader::internal::ast::FunctionConstraint>::_sink>&}; NextParser = lexy::sink_parser]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/dsl/production.hpp:66:43:   required from ‘static constexpr bool lexyd::_prd<Production>::p<NextParser>::parse(Context&, Reader&, Args&& ...) [with Context = lexy::_pc<lexy::_ph<lexy::_br8>, void, input_reader::internal::parser::FunctionConstraint, input_reader::internal::parser::SimulationState>; Reader = lexy::_br8; Args = {lexy::_sfinae_sink<input_reader::internal::parser::FunctionConstraint, lexy::_as_aggregate<input_reader::internal::ast::FunctionConstraint>::_sink>&}; NextParser = lexy::sink_parser; Production = input_reader::internal::parser::PropertyIdentifier]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/dsl/list.hpp:79:66:   required from ‘static constexpr bool lexyd::_lst<Item, Sep>::p<NextParser>::parse(Context&, Reader&, Args&& ...) [with Context = lexy::_pc<lexy::_ph<lexy::_br8>, void, input_reader::internal::parser::FunctionConstraint, input_reader::internal::parser::SimulationState>; Reader = lexy::_br8; Args = {}; NextParser = lexyd::token_base<lexyd::_lit<char, '-', '>'>, lexyd::branch_base>::p<lexyd::_mem<lexy::_mem_ptr_fn<&input_reader::internal::ast::FunctionConstraint::identifier>, lexyd::_prd<input_reader::internal::parser::Identifier> >::p<lexy::_detail::final_parser> >; Item = lexyd::_prd<input_reader::internal::parser::PropertyIdentifier>; Sep = lexyd::_sep<lexyd::_comma, void>]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/dsl/whitespace.hpp:188:33:   required from ‘static constexpr bool lexy::_detail::automatic_ws_parser<NextParser>::parse(Context&, Reader&, Args&& ...) [with Context = lexy::_pc<lexy::_ph<lexy::_br8>, void, input_reader::internal::parser::FunctionConstraint, input_reader::internal::parser::SimulationState>; Reader = lexy::_br8; Args = {}; NextParser = lexyd::_lst<lexyd::_prd<input_reader::internal::parser::PropertyIdentifier>, lexyd::_sep<lexyd::_comma, void> >::p<lexyd::token_base<lexyd::_lit<char, '-', '>'>, lexyd::branch_base>::p<lexyd::_mem<lexy::_mem_ptr_fn<&input_reader::internal::ast::FunctionConstraint::identifier>, lexyd::_prd<input_reader::internal::parser::Identifier> >::p<lexy::_detail::final_parser> > >]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/dsl/token.hpp:111:75:   [ skipping 32 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/dsl/whitespace.hpp:188:33:   required from ‘static constexpr bool lexy::_detail::automatic_ws_parser<NextParser>::parse(Context&, Reader&, Args&& ...) [with Context = lexy::_pc<lexy::_ph<lexy::_br8>, void, input_reader::internal::parser::SimulationState, input_reader::internal::parser::SimulationState>; Reader = lexy::_br8; Args = {}; NextParser = lexyd::_optt<lexyd::_eof, lexyd::_lstt<lexyd::_eof, lexyd::_prd<input_reader::internal::parser::Statement>, void, lexyd::_reco<void, lexyd::_eof> > >::p<lexy::_detail::final_parser>]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/base.hpp:209:37:   required from ‘constexpr auto lexy::_do_action(lexy::_pc<Handler, State, Production>&, Reader&) [with Handler = lexy::_ph<lexy::_br8>; State = void; Production = input_reader::internal::parser::SimulationState; Reader = lexy::_br8; typename std::conditional<_production_defines_whitespace<Production>, Production, void>::type = input_reader::internal::parser::SimulationState]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/base.hpp:229:34:   required from ‘constexpr auto lexy::do_action(Handler&&, State*, Reader&) [with Production = input_reader::internal::parser::SimulationState; Result = lexy::parse_action<void, lexy::buffer<lexy::utf8_encoding, void>, lexy_ext::_report_error<lexy::stderr_output_iterator> >::result_type; Handler = lexy::_ph<lexy::_br8>; State = void; Reader = lexy::_br8]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/parse.hpp:164:56:   required from ‘constexpr auto lexy::parse_action<State, Input, ErrorCallback>::operator()(Production, const Input&) const [with Production = input_reader::internal::parser::SimulationState; State = void; Input = lexy::buffer<lexy::utf8_encoding, void>; ErrorCallback = lexy_ext::_report_error<lexy::stderr_output_iterator>]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/parse.hpp:173:62:   required from ‘constexpr auto lexy::parse(const Input&, const ErrorCallback&) [with Production = input_reader::internal::parser::SimulationState; Input = lexy::buffer<lexy::utf8_encoding, void>; ErrorCallback = lexy_ext::_report_error<lexy::stderr_output_iterator>]’
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/src/main_app/input_reader/Parser.cpp:7:101:   required from here
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/grammar.hpp:274:36: error: static assertion failed: missing value sink callback overload for production
  274 |             static_assert(_detail::error<Production, Args...>,
      |                           ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/grammar.hpp:276:14: error: no match for call to ‘(lexy::_as_aggregate<input_reader::internal::ast::FunctionConstraint>::_sink) (input_reader::internal::ast::PropertyIdentifier)’
  276 |         _sink(LEXY_FWD(args)...);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
In file included from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/callback.hpp:8,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/include/main_app/input_reader/LexyComponents.hpp:9,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/include/main_app/input_reader/Parser.hpp:6,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/src/main_app/input_reader/Parser.cpp:1:
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/callback/aggregate.hpp:50:24: note: candidate: ‘template<class Fn, class Value> constexpr void lexy::_as_aggregate<T>::_sink::operator()(lexy::member<Fn>, Value&&) [with Fn = Fn; Value = Value; T = input_reader::internal::ast::FunctionConstraint]’
   50 |         constexpr void operator()(lexy::member<Fn>, Value&& value)
      |                        ^~~~~~~~
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/callback/aggregate.hpp:50:24: note:   template argument deduction/substitution failed:
In file included from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/dsl/base.hpp:9,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/base.hpp:11,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/action/parse.hpp:8,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/include/main_app/input_reader/LexyComponents.hpp:8,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/include/main_app/input_reader/Parser.hpp:6,
                 from /fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/src/main_app/input_reader/Parser.cpp:1:
/fast/emmanuel/Projects/GitHub/ConstraintBasedSimulator/code/cmake-build-release-gcc-10/_deps/lexy-src/include/lexy/grammar.hpp:276:14: note:   mismatched types ‘lexy::member<Fn>’ and ‘input_reader::internal::ast::PropertyIdentifier’
  276 |         _sink(LEXY_FWD(args)...);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
cc1plus: note: unrecognized command-line option ‘-Wno-readability-redundant-member-init’ may have been intended to silence earlier diagnostics
ninja: build stopped: subcommand failed.

Produced by the code (relevant parts):

namespace ast {
    using Identifier = std::string;

    struct FunctionConstraint {
        Identifier identifier;
    };
}
namespace parser {
    struct PropertyIdentifier {
        struct InvalidPropertyIdentifier {
            static LEXY_CONSTEVAL auto name() { return "property identifier is not time or distance"; }
        };

        static constexpr auto types
          = lexy::symbol_table<ast::PropertyIdentifier>
              .map(timeIdentifierReserved, ast::PropertyIdentifier::TIME_PROPERTY)
              .map(timeShortIdentifierReserved, ast::PropertyIdentifier::TIME_PROPERTY)
              .map(distanceIdentifierReserved, ast::PropertyIdentifier::DISTANCE_PROPERTY)
              .map(distanceShortIdentifierReserved, ast::PropertyIdentifier::DISTANCE_PROPERTY);

        static constexpr auto rule = [] {
            return dsl::symbol<types> | dsl::error<InvalidPropertyIdentifier>;
        }();
        static constexpr auto value = lexy::construct<ast::PropertyIdentifier>;
    };


    struct FunctionConstraint {
        static constexpr auto rule = [] {
            auto ws = dsl::whitespace(dsl::ascii::space);
            auto condition = dsl::peek(functionReserved
                                       + ws + dsl::list(dsl::p<PropertyIdentifier>, dsl::sep(dsl::comma))
                                       + ws + arrowReserved + ws + dsl::p<Identifier>);

            auto identifier = (dsl::member<&ast::FunctionConstraint::identifier> = dsl::p<Identifier>);
            return condition >> (functionReserved + dsl::list(dsl::p<PropertyIdentifier>, dsl::sep(dsl::comma)) + arrowReserved + identifier);
        }();
        static constexpr auto value = lexy::as_aggregate<ast::FunctionConstraint>;
    };
}

Formal language (relevant parts):

function ::= (<function-parameters>) -> <function-body>

function-parameters ::= <property-identifier>
                      | <function-parameters>, <property-identifier>

property-identifier ::= distance | t

function-body ::= <function-body> <binary-operator> <function-body>
                | <unary-operator> <function-body>
                | ( <function-body> )
                | <property-identifier>
                | <decimal>

unary-operator ::= sin | cos | tan
                 | asin | acos | atan
                 | sinh | cosh | tanh
                 | ln | log | exp | sqrt

binary-operator ::= + | - | * | / | ^

I know it is telling me that it cannot construct the FunctionConstraint, but it would be nice if it told me what line failed and what it is actually doing. Even for simple errors it is very convoluted, having to decipher the type of the parameters to a static_assert to guess what could have failed.

@foonathan
Copy link
Owner

Yeah, that's C++ for you, there isn't a lot I can do there.

clang's error messages are a nicer: https://godbolt.org/z/on6EoG8E8

In file included from <source>:1:
In file included from /opt/compiler-explorer/libs/lexy/trunk/include/lexy/action/parse.hpp:8:
In file included from /opt/compiler-explorer/libs/lexy/trunk/include/lexy/action/base.hpp:11:
In file included from /opt/compiler-explorer/libs/lexy/trunk/include/lexy/dsl/base.hpp:9:
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/grammar.hpp:365:27: error: static assertion failed due to requirement '_detail::error<ipv4_address, unsigned char &, unsigned char &, unsigned char &, unsigned char &>': missing value callback overload for production
  365 |             static_assert(_detail::error<Production, Args...>,
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/_detail/lazy_init.hpp:130:24: note: in instantiation of function template specialization 'lexy::production_value_callback<ipv4_address>::operator()<unsigned char &, unsigned char &, unsigned char &, unsigned char &>' requested here
  130 |         return emplace(LEXY_FWD(fn)(LEXY_FWD(args)...));
      |                        ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/_detail/config.hpp:22:23: note: expanded from macro 'LEXY_FWD'
   22 | #define LEXY_FWD(...) static_cast<decltype(__VA_ARGS__)>(__VA_ARGS__)
      |                       ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/action/base.hpp:169:23: note: in instantiation of function template specialization 'lexy::_detail::lazy_init<unsigned int>::emplace_result<lexy::production_value_callback<ipv4_address>, unsigned char &, unsigned char &, unsigned char &, unsigned char &>' requested here
  169 |         context.value.emplace_result(context.value_callback(), LEXY_FWD(args)...);
      |                       ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/dsl/eof.hpp:66:32: note: in instantiation of function template specialization 'lexy::_detail::final_parser::parse<lexy::_pc<lexy::_ph<lexy::_br8>, void, ipv4_address>, lexy::_br8, unsigned char &, unsigned char &, unsigned char &, unsigned char &>' requested here
   66 |             return NextParser::parse(context, reader, LEXY_FWD(args)...);
      |                                ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/dsl/separator.hpp:56:36: note: in instantiation of function template specialization 'lexyd::_eof::p<lexy::_detail::final_parser>::parse<lexy::_pc<lexy::_ph<lexy::_br8>, void, ipv4_address>, lexy::_br8, unsigned char &, unsigned char &, unsigned char &, unsigned char &>' requested here
   56 |                 return NextParser::parse(context, reader, LEXY_FWD(args)...);
      |                                    ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/dsl/integer.hpp:409:66: note: in instantiation of function template specialization 'lexyd::_nsep<lexyd::_period, void>::p<lexyd::_eof::p<lexy::_detail::final_parser>>::parse<lexy::_pc<lexy::_ph<lexy::_br8>, void, ipv4_address>, lexy::_br8, unsigned char &, unsigned char &, unsigned char &, unsigned char &>' requested here
  409 |             return lexy::whitespace_parser<Context, NextParser>::parse(context, reader,
      |                                                                  ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/dsl/integer.hpp:481:37: note: (skipping 10 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
  481 |             return _pc<NextParser>::parse(context, reader, begin, end, LEXY_FWD(args)...);
      |                                     ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/action/base.hpp:209:32: note: in instantiation of function template specialization 'lexyd::_int<lexyd::_digits<lexyd::_d<10>>, lexyd::_bounded_integer_parser<unsigned char, lexyd::_d<10>, true>, void>::p<lexyd::token_base<lexyd::_lit<char, '.'>>::p<lexyd::_int<lexyd::_digits<lexyd::_d<10>>, lexyd::_bounded_integer_parser<unsigned char, lexyd::_d<10>, true>, void>::p<lexyd::token_base<lexyd::_lit<char, '.'>>::p<lexyd::_int<lexyd::_digits<lexyd::_d<10>>, lexyd::_bounded_integer_parser<unsigned char, lexyd::_d<10>, true>, void>::p<lexyd::token_base<lexyd::_lit<char, '.'>>::p<lexyd::_int<lexyd::_digits<lexyd::_d<10>>, lexyd::_bounded_integer_parser<unsigned char, lexyd::_d<10>, true>, void>::p<lexyd::_nsep<lexyd::_period, void>::p<lexyd::_eof::p<lexy::_detail::final_parser>>>>>>>>>::parse<lexy::_pc<lexy::_ph<lexy::_br8>, void, ipv4_address>, lexy::_br8>' requested here
  209 |     auto rule_result = parser::parse(context, reader);
      |                                ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/action/base.hpp:229:24: note: in instantiation of function template specialization 'lexy::_do_action<lexy::_ph<lexy::_br8>, void, ipv4_address, lexy::_br8>' requested here
  229 |     auto rule_result = _do_action(context, reader);
      |                        ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/action/parse.hpp:164:22: note: in instantiation of function template specialization 'lexy::do_action<ipv4_address, lexy::parse_action<void, lexy::buffer<lexy::utf8_encoding>, lexy_ext::_report_error<lexy::stderr_output_iterator>>::result_type, lexy::_ph<lexy::_br8>, void, lexy::_br8>' requested here
  164 |         return lexy::do_action<Production, result_type>(handler(input_holder, sink), _state,
      |                      ^
/opt/compiler-explorer/libs/lexy/trunk/include/lexy/action/parse.hpp:173:12: note: in instantiation of function template specialization 'lexy::parse_action<void, lexy::buffer<lexy::utf8_encoding>, lexy_ext::_report_error<lexy::stderr_output_iterator>>::operator()<ipv4_address>' requested here
  173 |     return parse_action<void, Input, ErrorCallback>(callback)(Production{}, input);
      |            ^
<source>:31:25: note: in instantiation of function template specialization 'lexy::parse<ipv4_address, lexy::buffer<lexy::utf8_encoding>, lexy_ext::_report_error<lexy::stderr_output_iterator>>' requested here
   31 |     auto result = lexy::parse<ipv4_address>(input, lexy_ext::report_error);
      |                         ^
1 error generated.

If you look at the first line there, it tells you which production fails and what values are being produced.

With some effort, I can change that to:

/opt/compiler-explorer/libs/lexy/trunk/include/lexy/grammar.hpp:365:27: error: static assertion failed due to requirement '_detail::error<ipv4_address, rule<"integer", unsigned char &>, rule<"integer", unsigned char &>, rule<"integer", unsigned char &>, rule<"integer", unsigned char &>>': missing value callback overload for production
  365 |             static_assert(_detail::error<Production, Args...>,
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That way, you'll also get the name of the rule that produced a value. However, it probably requires C++20.

I can see what I can do about GCC.

@foonathan foonathan added the enhancement New feature or request label Oct 15, 2023
@EmmanuelMess
Copy link
Author

EmmanuelMess commented Oct 15, 2023

Yeah, that's C++ for you, there isn't a lot I can do there.

I'm not quite sure, but I think that adding more complex requirements to the type parameters (something like concepts does) of different components, maybe it would show the error directly on the user defined type. I feel like the library simply assumes that the user defined type is correct and fails internally, instead it should check all assumptions directly on the user defined type before using it.

However, it probably requires C++20.

I have no problem with that.

I can see what I can do about GCC.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants