Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make source positions a parser option? #49

Open
jgm opened this issue May 17, 2020 · 5 comments
Open

Make source positions a parser option? #49

jgm opened this issue May 17, 2020 · 5 comments

Comments

@jgm
Copy link
Owner

jgm commented May 17, 2020

Instead of handling it with typeclasses.
This would allow simpler typeclasses: Html, Pandoc.
It might also allow us to improve performance by avoiding the work of storing and computing ranges.

@jgm
Copy link
Owner Author

jgm commented May 17, 2020

One idea would be to add an Options data structure

data Options m =
  Options{
    optIncludeSourceRanges :: Bool,
    optWarn :: Warning -> m (),
    optAddToSourceMap :: Text -> SourceRange -> m ()
  }

optWarn would allow us to issue warnings for things like duplicate references in a flexible way (#48).
optAddToSourceMap would allow us to construct source maps in a flexible way (#33).
Putting these in options may be more flexible than using typeclasses.
Defaults could be False, \_ -> return (), and \_ _ -> return ().

@jgm
Copy link
Owner Author

jgm commented May 17, 2020

We could use a reader monad transformer to make these available in block and inline parsers.

@alerque
Copy link

alerque commented May 18, 2020

I don't really care how they get there as long as the option is there! We're really looking forward to having a source maps available for vim-pandoc! We have a working prototype right now of a new syntax system using an external source map provided by pulldown-cmark which reports start and stop byte ranges. This is working great but we really need the full range of Pandoc extensions, not just CommonMark.

@jgm
Copy link
Owner Author

jgm commented May 18, 2020

The option is there already (as well as the ability to create a source map). This was just an idea about an alternative way to put it there.

@jgm
Copy link
Owner Author

jgm commented May 18, 2020

@alerque for a demo of the source map functionality, you can do commonmark --highlight -xall README.md. This does syntax highlighting with all the extensions enabled. To see how this is done see the code for commonmark-cli.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants