Add an example on how to implement a parser for interspersed input#468
Add an example on how to implement a parser for interspersed input#468daddykotex wants to merge 2 commits intotypelevel:mainfrom
Conversation
mdoc already renders expressions automatically (but not statements like In fact I think in some places there is duplicate output. |
|
|
||
| But you can use, `soft` along with `|` to implement that: | ||
| ```scala mdoc | ||
| val interspersed = ((p4.soft <* pchar(',')) | p4).rep |
There was a problem hiding this comment.
this example would also parse abc which maybe what you want but might be a bit confusing for newcomers.
here is an example of how I parse lists in bosatsu:
https://github.com/johnynek/bosatsu/blob/c58b55785b6ac72e59b98afe3149a042d623a902/core/src/main/scala/org/bykn/bosatsu/Parser.scala#L302
johnynek
left a comment
There was a problem hiding this comment.
thanks for sending the PR.
I think we should add some notes to the example you added because I think it accepts more than most people would expect with a list example (making the , fully optional).
While looking at the documentation I found some things that I could be improved so here is a PR for that.
I was specifically looking to see how I could implement something to parse
"a,b,c"and extracta,bandc. I found that soft could be used for that and because I think it's a common pattern in parsers, I figured it could be useful to have an example in the documentation.On top of that, I get feedback from experts to tell me if that solution is bad and what would be a better alternative, win-win!
One annoying thing about the
docs/index.mdis that yes, it's compiled but it's not the actual output of mdoc and so the result in there are hard coded. I found it annoying to go intosite/target/mdoc/index.mdand retrieve the output and format it to fit with the rest of the document. Is there a better way?