hayleigh-dot-dev / nibble

A string parsing library heavily inspired by elm/parser.
MIT License
51 stars 7 forks source link

✨ Add `span` parser #10

Closed MystPi closed 7 months ago

MystPi commented 7 months ago

Adds a parser for getting the current position.

Apologies for the messy diff; looks like my editor removed some trailing whitespace from comments.

MystPi commented 7 months ago

I noticed that CanBacktrack actually has to be set to False for the parser to work correctly. What do you think @hayleigh-dot-dev?

hayleigh-dot-dev commented 7 months ago

Ah it might be that I got confused with the naming. At one point in time I think this type was called ShouldBacktrack or Backtrackble or something... the core parser stuff is a port from elm that I muddled through.

Do you think you could add some tests for this just to make sure it works fine?

MystPi commented 7 months ago

I can try! Is ./test/unit/parser_test.gleam a good place for the tests?

hayleigh-dot-dev commented 7 months ago

Yeah sounds good! I'd just like to make sure we get sensible results if we do like

use before <- do(span())
use _ <- do(some_parser())
use after <- do(span())
hayleigh-dot-dev commented 7 months ago

If you could be bothered you could also consider a very minimal reproduction of your sexpr parser and place it under test/examples/ :)

MystPi commented 7 months ago

If you could be bothered you could also consider a very minimal reproduction of your sexpr parser and place it under test/examples/ :)

Ooh I think I'll do that!

MystPi commented 7 months ago

I think the sexpr test I added pretty much verifies that the parser works. Nice to have more nibble examples too!