nom icon indicating copy to clipboard operation
nom copied to clipboard

Example parsers

Open Geal opened this issue 9 years ago • 97 comments

We currently have a few example parsers. In order to test the project and make it useful, other formats can be implemented. Here is a list, if anyone wants to try it:

Geal avatar Feb 26 '15 13:02 Geal

I'm writing a Thrift library for Rust that'll use Nom for both their IDL and the network protocol, so that can be another example (although in a different repo).

thehydroimpulse avatar Apr 03 '15 04:04 thehydroimpulse

Nice idea, that will be useful! Please notify me when it is done, I will add a link in this list.

Geal avatar Apr 03 '15 07:04 Geal

This looks interesting. Is anyone actively working on any of these parsers? I'd like to work on a few of these.

filipegoncalves avatar Apr 27 '15 10:04 filipegoncalves

I have some code for a GIF one at https://github.com/Geal/gif.rs but it is hard to test, since the graphical tools in Piston change a lot.

You can pick any of them. Network packets may be the easiest, since they don't require a decompression phase.

I am using the gif example to see what kind of API can be built over nom. Most of the parsing example are done as one pass over the data, but often there is some logic on the side, and it is not easy to encode correctly.

Geal avatar Apr 27 '15 12:04 Geal

I've started a fastq (http://en.wikipedia.org/wiki/FASTQ_format) parser https://github.com/elij/fastq.rs

elij avatar May 01 '15 13:05 elij

@elij this is a great idea! Was it easy to do?

Geal avatar May 05 '15 09:05 Geal

yup it's a great framework -- though I struggled a bit with eof so I borrowed some code from rust-config (https://github.com/elij/fastq.rs/blob/master/src/parser.rs#L69) -- is there a better solution?

elij avatar May 05 '15 13:05 elij

yes, eof should be a parser provided by nom, I am just waiting for @filipegoncalves to send a PR :wink:

Geal avatar May 05 '15 14:05 Geal

Hah, sorry for my silence. I've been busy lately. I just sent a PR (https://github.com/Geal/nom/pull/31).

I will be working on one of these example parsers as soon as I get some spare time. There are some great ideas in here!

filipegoncalves avatar May 05 '15 15:05 filipegoncalves

I might give tar a try

Keruspe avatar May 29 '15 21:05 Keruspe

Does this check off PCAP?

https://github.com/richo/pcapng-rs

nelsonjchen avatar Jun 19 '15 02:06 nelsonjchen

pcap-ng and pcap are two different formats, right? It seems the consensus now is to move everything to pcap-ng, though.

Geal avatar Jun 19 '15 09:06 Geal

I will try a FLAC parser, need to add quite a few things for it though.

TechnoMancer avatar Jul 17 '15 09:07 TechnoMancer

ISO8601 is done in https://github.com/badboy/iso8601 (I hope it's mostly correct.)

badboy avatar Jul 17 '15 10:07 badboy

ok, it should be up to date. More to come :smile:

Geal avatar Jul 17 '15 11:07 Geal

WARC file format released. https://crates.io/crates/warc_parser

sbeckeriv avatar Aug 23 '15 21:08 sbeckeriv

@sbeckeriv great, thanks!

Geal avatar Aug 24 '15 21:08 Geal

It might be informative to try parsing the rust grammar with nom, if nobody has yet. In any case, I'd like to see a few programming languages on that list, since that's my use case.

porglezomp avatar Sep 14 '15 19:09 porglezomp

@porglezomp programming languages examples would definitely be useful, but the Rust grammar might be a bit too much for the first attempt. Which other languages would you like to handle?

Geal avatar Sep 15 '15 07:09 Geal

Yeah, I'm aware of the scale problem of Rust. I don't want to write that one, but I think it's a good holy grail for any parser library written in Rust. I'd like to try parsing the Lua grammar first, I think.

I recommend adding to the list:

  • Programming Languages
    • Rust
    • Lua (I'll do this)
    • Python (or some other whitespace significant language)
    • C

porglezomp avatar Sep 15 '15 11:09 porglezomp

ok, I added them to the list :)

Geal avatar Sep 15 '15 13:09 Geal

You have INI marked as done; do you have a link to it? (I'd love to use this for some tooling I'm hoping to build in 2016; need a good non-trivial example for it, though.)

chriskrycho avatar Nov 16 '15 19:11 chriskrycho

@chriskrycho: https://github.com/Geal/nom/blob/master/tests/ini.rs

badboy avatar Nov 16 '15 19:11 badboy

Thanks very much, @badboy!

chriskrycho avatar Nov 16 '15 19:11 chriskrycho

I'll try to make the TOML parser very soon.

fbernier avatar Nov 16 '15 22:11 fbernier

Actually, I think I should rewrite that INI parser, now that more convenient combinators are available. Also, I should really work on that combinator for space separated stuff

Geal avatar Nov 16 '15 23:11 Geal

@fbernier great! Please keep me posted!

Geal avatar Nov 16 '15 23:11 Geal

Maybe add a simple example for trailing commas in lists? Python has those, but is quite complex. Can't think of a simple example though.

l0calh05t avatar Nov 16 '15 23:11 l0calh05t

That IRC example is no longer using nom. The parser was moved into its own repository: https://github.com/Detegr/RBot-parser

johshoff avatar Nov 17 '15 06:11 johshoff

@l0calh05t to parse something like [a,b,c,] or [a,b,c] ? @johshoff fixed, thanks

Geal avatar Nov 17 '15 08:11 Geal