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

Using a contiguous range from context range inside a custom scanner #132

Open
hmartin-hst opened this issue Nov 11, 2024 · 0 comments
Open

Comments

@hmartin-hst
Copy link

I'm trying to create a tokenizer/parser for an existing protocol, and I don't find any documentation on how to correctly use the context range as a contiguous range:

struct token {
    std::string_view value;
};

template<>
    struct scanner< token > {

        std::size_t max_length;
        char separator = ';';
        char fill = ' ';
        
        template<typename ParseContext>
        constexpr auto parse(ParseContext &pctx) -> typename ParseContext::iterator {
            return pctx.begin();
        }
        

        template <typename Context>
        auto scan( token &value, Context &ctx ) const -> scan_expected< typename Context::iterator > {
            auto r = scn::scan< std::string_view >( ctx.range(), "{}" );
           if( r ) {
                return r->begin();
           } 
           else {
               ...
           }
        }

    };

How to "cast" or to check the context range to use it as a contiguous range?

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

No branches or pull requests

1 participant