Skip to content

dsl::integer and negative numbers #87

Discussion options

You must be logged in to vote

I found the solution looking at the json example, but I am not quite sure why the dsl::peek is required.

struct production
{
  struct integer
  {
    static constexpr auto rule = dsl::sign + dsl::integer<int64_t>;
    static constexpr auto value = lexy::as_integer<int64_t>;
  };

  static constexpr auto rule = [] {
    auto hex_integer = LEXY_LIT("0x") >> dsl::integer<int64_t, dsl::hex>;
    auto regular_integer = dsl::peek(dsl::lit_c<'-'> / dsl::lit_c<'+'> / dsl::digit<>) >> dsl::p<integer>;
    return ( hex_integer | regular_integer ) + dsl::eof;
  }();

  static constexpr auto value = lexy::forward<int64_t>;
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@foonathan
Comment options

Answer selected by foonathan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #86 on September 04, 2022 13:43.