rust-bakery / nom

Rust parser combinator framework
MIT License
9.18k stars 792 forks source link

Consider CR only for line endings #1386

Open huntc opened 2 years ago

huntc commented 2 years ago

As I understand things, CR on its own is also a valid line ending, along with CR+LF and LF.

EDIT: According to Wikipedia at least, line endings can be a single return character. Also, and what motivated me to raise this, the W3C spec for server sent events includes a single return character as a line ending in its ABNF.

Happy to contribute a PR on an agreement. Thanks for providing nom!

Stargateur commented 2 years ago

that a nope for me, if you need special line ending handle use your own combinator, line ending of nom should follow standard and standard say \n or at worse \r\n, that also what rust std do. Mixing convention is a bad idea.

huntc commented 2 years ago

According to Wikipedia at least, line endings can be a single return character. Also, and what motivated me to raise this, the W3C spec for server sent events includes a single return character as a line ending in its ABNF.

Stargateur commented 2 years ago

Yes I know, what I mean is that 99% of the time \r alone is not a valid new line. \n should be used everywhere. Since \n is become the "newline" back in time considering \r as a newline introduce an ambiguous syntax. For complete input it's fine but for streaming you would always need input to confirm it. Thus streaming parser could never succeed if input end with a \r. Handle \r\n is already performance hit in all industry.