Replies: 1 comment 1 reply
-
That is more of a safety thing and it is reasonable to have your own
As I'm unfamiliar with this language, it would help to step through some of the error cases you are trying to create but have difficulty with. I'm guessing one is that for un-terminated brackets, you want to point at the open bracket but have the close bracket context. Is that right?
I'd recommend creating an issue for discussing this. |
Beta Was this translation helpful? Give feedback.
-
I'm writing a brainfuck parser, and I'm finding that it's very easy to write a working parser with winnow, but pretty annoying to make it report good errors, at least with a grammar as simple as brainfuck (which I do admit might be simpler than what winnow was designed for). I keep either getting errors in places where I can't attach context (for example the
eof
that my parser gets chained with inParser::parse
), or the error's context holds the wrong offset because it backtracked too far, or not enough.Here's the parser code (it's a bit of a mess because I've been trying to find a way to make it both work correctly and report the correct offsets and locations in the errors, and as it is right now I actually broke bracket parsing in the process so it thinks any opening bracket is mismatched)
it would be really nice if I could just manually edit the offset or provide and offset to the reported offset as usize so that I don't have to do the song and dance I had to do when catching the error just to reset a checkpoint and throw another error with
fail
(which also changes the error cause, which thankfully don't need in this case)another thing that would be nice is if
take_till
acceptedFnMut
as the parser, and not justFn
, since I tried to implement the recursion in my parser by doing atake_till
with a closure that just counts the number of opening and closing brackets to take until the matching bracket, but sincetake_till
requiresFnMut
, I have to useCell
, and interior mutability just to satisfy a trait boundary that I'm not sure needs a reason to be there (tbf, I know there might be one, I don't don't know it) rubs me the wrong way.also general tips on how I could improve the parser are welcome. Chances are whatever you suggested I have already tried but had to change for one reason or another, usually for error reporting reasons.
Beta Was this translation helpful? Give feedback.
All reactions