adamchalmers / blog

1 stars 2 forks source link

Parsing Text with Nom #3

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Parsing Text with Nom

Blogging, generally about Rust

https://blog.adamchalmers.com/nom-chars/

adamchalmers commented 2 years ago

I'm trying to out comments for the blog -- let me know if there's any problems.

beneyal commented 2 years ago

Very nice introduction to Nom! Thank you for posting :-)

ngwemo commented 1 year ago

I had a problem on grasping the concept of how even to use nom, but going through this blog, I've more in-depth knowledge on how and the core concepts of the crate. Thanks for effort on putting this out here man.

azzamsa commented 12 months ago

Any reason to use Nom over the other? Such Pest. I have built an app using Pest, but don't have any experience with Nom.

adamchalmers commented 12 months ago

I've been rewriting a pretty big production parser for KittyCAD into Winnow. I'll definitely be writing about Winnow soon. I think it offers some nice improvements over Nom and has a lot of potential. I found one big bug, but the maintainer fixed it within a few hours of me posting a reproduction, and released a new version. So, I'm very happy.

I haven't used grammar generators like pest before! I gave it a try once for a small project, couldn't figure it out within 20 minutes and went back to Nom. I'd like to try it again though.

On Thu, 5 Oct 2023, 10:33 pm Azzam S.A, @.***> wrote:

Any reason to use Nom over the other? Such Pest. I have built an app https://github.com/azzamsa/nai using Pest, but don't have any experience with Nom.

— Reply to this email directly, view it on GitHub https://github.com/adamchalmers/blog/issues/3#issuecomment-1749937434, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJIFYM2G2VO7ZGJVHB4DJLX553Y5AVCNFSM5LRYBFE2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZUHE4TGNZUGM2A . You are receiving this because you commented.Message ID: @.***>

azzamsa commented 12 months ago

I'll definitely be writing about Winnow soon.

Can't wait to read it.

sentinel1909 commented 7 months ago

Hi Adam, I've been attempting to dive in and understand the Nom crate for about two weeks now. I thought I'd start with something simple, like parsing a sentence to look for a certain word. No matter what I try, I can't figure out how to put it all together. I understand the fundamentals (I think) about individual parsers and what they return, but I feel there is something fundamental I'm missing. The docs are lacking and, other than your blog, there just isn't much out there.

How do you iterate with Nom?

adamchalmers commented 4 months ago

Hi! You don't really iterate, there's no loops or iterators. Instead you use combinators like many1(p) which runs the p parser one or more times.

To parse a sentence I'd:

sentinel1909 commented 4 months ago

Thanks! That helped a lot. After reading your suggestions I worked out how to parse multiple sentences with periods. Now I just have to work in other types of punctuation!