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

Fork with completion support #91

Open
jchapuis opened this issue Dec 8, 2016 · 4 comments
Open

Fork with completion support #91

jchapuis opened this issue Dec 8, 2016 · 4 comments

Comments

@jchapuis
Copy link

jchapuis commented Dec 8, 2016

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): Completions method 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.

@gourlaysama
Copy link
Contributor

gourlaysama commented Dec 16, 2016

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...

@SethTisue
Copy link
Member

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

@jchapuis
Copy link
Author

Thanks for your feedback, I also agree, this is what I wanted to do initially actually. I'll investigate further along those lines.

@jchapuis
Copy link
Author

Hi there, I've just created a PR (#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!

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

3 participants