Add Sedlexing.accept for custom buffer control#188
Conversation
|
Here is a usecase https://github.com/ifazk/sedlying |
toots
left a comment
There was a problem hiding this comment.
Could it be possible to add an example with a custom accept to better illustrate a situation where this is useful?
There should be a major version bump for this.
Worth noting for future reference: I do remember having a lot of projects vendoring the sedlexing.mli interface which can cause a lot of obscure compilation failures when pushing the package to the opam CI.
Since you're only adding a net-new API perhaps this wont happen?
|
We should probably wait for feedback from @ifazk |
|
It has been a long time since I've hacked around with sedlex, and I haven't even been using OCaml for the last little bit. I personally don't need this anymore, but I would still like to see this merged. Will need a day or two to figure out how to use the new |
You should be able to define let accept lexbuf final =
mark lexbuf final;
backtrack lexbuf |
|
If we decide to add this feature. #180 would need to be implemented differently. |
|
Someone tell me what to merge (if anything.) |
|
gentle ping @ifazk |
|
Sorry, was busy the last two weekends. I'm trying to work through it now, but ran into some issues and need some help since I haven't been keeping up with sedlex changes. I locally added It seems to come from My accept implementation: Test code that's failing: I should be more responsive now that I have OCaml and dune setup, again sorry I was a little MIA. |
|
Just provide __private__next_int by exporting the one found in the official Sedlexing module. For accept, you need to return the accepting state. let accept lexbuf i =
mark lexbuf i;
let x = backtrack lexbuf in
x |
|
Thanks for all your help. The accept change fit my original use case and passed all the test cases I had! Sorry it took so long that you have to rebase now. |
|
I'd like to explore a bit more on this front before we commit to anything. I've concerted the into a Draft |
…tance (ocaml-community#81) When a DFA reaches a final state with no further transitions, the generated code now calls Sedlexing.accept instead of directly returning the state index. The default implementation simply returns the index, so there is no behavior change. Custom Sedlexing modules can override accept to call backtrack instead, e.g. to reject matches that do not end on a grapheme cluster boundary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The int parameter was unnecessary — the PPX already knows the rule index, so accept only needs to signal yes/no. This simplifies both the API and the generated code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
I've explored a different design space for what you wanted to achieve in #192 that is support for |
Summary
Sedlexing.accept : lexbuf -> int -> intcalled when the lexer reaches a final state with no further transitionsSedlexingmodules can overrideacceptto callbacktrackinstead, e.g. to reject matches that do not end on a grapheme cluster boundaryTest plan
dune buildpassesdune runtestpassesSedlexing.acceptcalls in generated code🤖 Generated with Claude Code