mmark icon indicating copy to clipboard operation
mmark copied to clipboard

Expose source position to scanners and extensions

Open aleator opened this issue 6 years ago • 5 comments

Would it be possible to expose the source position for scanners and extension building functions? I have two use cases that would greatly benefit from this:

  1. Many extensions can fail on bad markup. Currently, when this happens it can be really hard find out where it happened. For example, I would like to typecheck my code examples.

  2. Wiki like editing would benefit from this as it would allow the generated html to point at the original source

I did notice that this was mentioned in the documentation. You can count this issue as a vote for adding the source locations + an offer to do some of the work.

aleator avatar Jul 05 '18 06:07 aleator

This would require also adding a proper way for extensions to signal failure.

mrkkrp avatar Jul 05 '18 16:07 mrkkrp

I think raising an exception would be sufficient.

aleator avatar Jul 06 '18 06:07 aleator

Well I think it's not the best way to solve the problem, mostly because this

  • Can be handled "purely", i.e. without exceptions.
  • I'm not a big fan of throwing exceptions from pure code.
  • This does not allow us combine and report multiple errors at once, which is something we could reasonably expect from a tool with already such a good story with respect to error reporting.

So for now throwing is an option because the code is written as it's written, but I think we should improve this in the future, or at least try to.

mrkkrp avatar Jul 07 '18 15:07 mrkkrp

I agree on all of your points. However, I think that the error handling depends on the source position, so the latter would be best to implement first. If I'd submit a patch to add source position / span for code blocks and inline urls would that make for acceptable first step?

aleator avatar Jul 11 '18 19:07 aleator

Well you could try, but my understanding is that it's not trivial to get quite right and it may make the parser slower. Be prepared that I may be picky about the solution.

mrkkrp avatar Jul 12 '18 03:07 mrkkrp