Skip to content

Completion support #101

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

Closed
wants to merge 13 commits into from
Closed

Completion support #101

wants to merge 13 commits into from

Conversation

jchapuis
Copy link

@jchapuis jchapuis commented Feb 10, 2017

This PR contains a CompletionSupport trait which can be mixed-in to enable completion for a grammar, i.e. parsers which are 'augmented' with a completions method returning possible entry completions for a certain input. This can be used to elaborate as-you-type completions menus or tab-completion experiences, and is e.g. easy to plug with readline to implement a console application. This is ideal to develop e.g. search query grammars, since the flexibility granted by parser-combinators is very valuable in such a context.

All completion-related types, combinator overloads and tests are located in a separate completions package and there no impact to existing code. As a result, a small amount of duplication was required for some combinators (but it's very limited).

Note that in addition to this base set of definitions, I could also add a fuzzy completion mix-in to this PR, which allows defining as-you-type experiences supporting fuzzy string matching in an easy way.

Also, let me know of any required adaptation to the copyright notice for inclusion consideration. Thanks!

@gourlaysama gourlaysama self-requested a review February 10, 2017 14:10
@jchapuis jchapuis closed this Feb 10, 2017
@jchapuis jchapuis reopened this Feb 10, 2017
@gourlaysama
Copy link
Contributor

Thanks for working on this @jchapuis. That looks like a great addition to parser-combinators! I'll try and review and comment soon :)

…was causing missing completions with repeated parsers on nested alternatives with common prefixes, added a test to examplify the case
@SethTisue
Copy link
Member

SethTisue commented Mar 1, 2017

I asked on Gitter (scala/contributors) if anyone else would like to help review this.

@jchapuis
Copy link
Author

jchapuis commented Mar 22, 2017

Hi all, if there is any way I can help in making this move forward, let me know! This extension has proven very valuable for us, and I find that it is an ideal use case for parser combinators. Indeed, when developing interactive and dynamic grammars, flexibility is much more important than performance - and flexibility is where combinators shine. Completions with dynamic grammars and fuzzy string matching allow for slick natural language search experiences for instance (which is what we use it for).

@Test
def intoParserWithSuccessCompletesResultingParser(): Unit = {
val completions = TestParser.completeString(TestParser.test, animal)
Assert.assertEquals(Seq(bear, lion), completions)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool! Would it be possible to use completions to generate helpful parse error messages? For example,

Parse error!
animal plane
       ^
found: plane
expected: bear | lion

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olafurpg thanks! This is a great idea, I will look into this. It should be indeed feasible to "augment" error messages for parsers with CompletionSupport.

@jchapuis
Copy link
Author

For information, I've made this available in a separate library: https://github.com/jchapuis/scala-parser-combinators-completion. It works in the same way, mixing-in the CompletionSupport trait augments parsers with completion support.

So I'm closing this pull request for now (let's see if that library gains some traction and interest).

@jchapuis jchapuis closed this Aug 25, 2017
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

Successfully merging this pull request may close these issues.

4 participants