scnlib icon indicating copy to clipboard operation
scnlib copied to clipboard

Using a contiguous range from context range inside a custom scanner

Open hmartin-hst opened this issue 1 year ago • 1 comments

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?

hmartin-hst avatar Nov 11 '24 08:11 hmartin-hst

Is there a solution for this yet?

beojan avatar Oct 17 '25 22:10 beojan