scala-parser-combinators
scala-parser-combinators copied to clipboard
Fork with completion support
Hi all,
I've created a fork which adds completion support to the library, which allows providing as-you-type autocomplete or TAB-completion experiences: https://github.com/jchapuis/scala-parser-combinators.git
In a nutshell, additions are:
def completions(in: Input): Completionsmethod which allows querying the list of possible completions for a certain input. This returns a structured type which can contain tagged and ranked completions.- implementations of this method for all the combinators
- a new set of operators which allows tagging and ranking elements of the grammar
I have also implemented fuzzy matching completion parsers which are not present in the fork right now but that I could potentially integrate.
Would you consider this as a possible PR? It's of course extending the "traditional" functionality of parser combinators, so it add extra complexity and testing requirements that are maybe not desirable for the core library. At any rate I'm creating this issue also to to point out that building completion experiences using parser-combinators is feasible and actually works well with the functional nature of these grammars.
Wow, that's interesting!
Does this have a performance impact for people that don't use the completion support at all?
Yes, that would be an interesting PR (for v1.1.0, the master branch). It would be easier to get it in if the completion stuff could all be moved into some trait that the user could just mix in if they need it, as in:
object MyParsers extends RegexParsers with CompletionSupport
That way it would be opt-in, and not as invasive.
Looking quickly at the code, I think this should be possible with a few changes to Parsers to allow that trait to subclass the Parser class used and change how it is created...
It would be easier to get it in if the completion stuff could all be moved into some trait that the user could just mix in if they need it
agree. if that's possible, it would be much better
Thanks for your feedback, I also agree, this is what I wanted to do initially actually. I'll investigate further along those lines.
Hi there, I've just created a PR (https://github.com/scala/scala-parser-combinators/pull/101) with the completion aspects now separate from the main code and exposed in a CompletionSupport trait as suggested. Note that a separate RegexCompletionSupport trait is also defined which adds completion support to the literal parser, and can be used like so:
object MyParsers extends RegexParsers with RegexCompletionSupport
This CompletionSupport trait is a subtype of Parsers (and not a self-type) as it subclasses Parser to add the completions method and overrides some methods. Let me know what you think!
Also in the case this can be considered, thanks for letting me know what is required in terms of copyright notice, licensing etc. Thanks!