j-mie6 / parsley

A fast and modern parser combinator library for Scala
https://j-mie6.github.io/parsley/
BSD 3-Clause "New" or "Revised" License
173 stars 15 forks source link

Multiple labels with `.label`? #193

Closed j-mie6 closed 11 months ago

j-mie6 commented 1 year ago

It turns out that venerable parsec's <?> has a synonym labels, which can attach more than one label to an error. This is definitely something I've wanted to do in the past, but I've implemented it as:

def labels[A](name: String, names: String*)(p: Parsley[A]) = 
  p.label(name) <|> choice(names.map(empty.label(_)): _*)

This is a bit clumsy, especially when MultiExpectedError does exist for the JumpTable in the machine. Instead, we could just add the varargs onto label and do away with MultiExpectedError.

j-mie6 commented 1 year ago

This can be done in a minor way by introducing def label(name1: String, name2: String, names: String*) I believe, and then the single overloading can be removed as part of parsley 5