nom_locate icon indicating copy to clipboard operation
nom_locate copied to clipboard

Does the given input type need to be specified everythere?

Open candronikos opened this issue 8 years ago • 4 comments
trafficstars

Hi Florent,

I'm testing your library for a project and just want to confirm if your input type needs to be specified everywhere or can a layer be applied over an existing lexer to avoid a total rewrite?

I keep getting errors 'missmatched types' errors in my parser but I still believe this project has a lot of potential.

candronikos avatar Jun 10 '17 07:06 candronikos

Hi Christopher !

Thanks a lot for your experiment and your feedback! The input type indeed needs to be specified everywhere. If you have a special input type you'd probably need to specify it as the fragment type (ie. your new input type would be LocatedSpan<YourCustomType>).

Btw, if you're OK with this and if your project is public, I would be glad to take a look and help. That would let me understand the need of existing projects so the transition is easy.

Florent

fflorent avatar Jun 11 '17 15:06 fflorent

I'm in a similar situation where at first I wrote everything using the nom 5 beta and didn't use nom_locate yet because I thought it wouldn't be worth the effort and the version for nom 5 wasn't released yet. I thought that porting the existing code to using nom_locate would be trivial but now I'm noticing that it's a lot of work.

Maybe a small guide with steps on how to port an existing nom codebase could help other people in a similar situation?

Unfortunately I can't share my code because it's not public.

tversteeg avatar Jul 24 '19 17:07 tversteeg

@tversteeg I didn't play around much with nom5 yet, but afaik with nom5 you must always explictely write the input and return types (because (sub)parsers are now written as functions instead of macros). So this becomes a non-issue for nom_locate.

Porting is pretty straightforward: create your span type (eg. type Span<'a> = LocatedSpan<&'a str>;) and replace &str with Span in all your functions' signature. If you ever read a string directly, use s.fragment instead of just s.

progval avatar Jul 24 '19 17:07 progval

Why not implement AsDeref<Target=T> ?

Stargateur avatar Apr 01 '20 01:04 Stargateur