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

How generate the LL1 table and how use it ? #16

Open
BorderCloud opened this issue Mar 7, 2020 · 4 comments
Open

How generate the LL1 table and how use it ? #16

BorderCloud opened this issue Mar 7, 2020 · 4 comments

Comments

@BorderCloud
Copy link

Hello

I have difficulty to use the functions generated by ANTLR4 for Intellij.
I searched in the doc but It's not clear.

What is the name of the function to call to have the possible rules and tokens in function of offset in the file ? I see the error messages with the possible rules and tokens but I didn't found the good function to call.

I don't know if ANTLR4 for Intellij can generate the LL1 tools for my language. Have you examples of CompletionContributor class that use the basic completion tool and the LL1 tool ?

My code:

public class TestCompletionContributor extends CompletionContributor {
    public TestCompletionContributor() {
        extend(CompletionType.BASIC,
                PlatformPatterns.psiElement(),
                new CompletionProvider<CompletionParameters>() {
                    public void addCompletions(@NotNull CompletionParameters parameters,
                                               ProcessingContext context,
                                               @NotNull CompletionResultSet resultSet) {

                        //  How do the list of Rules and Tokens probable ? (with a LL1 tool ?)

                        resultSet.addElement(
                                        PrioritizedLookupElement.withPriority(
                                                LookupElementBuilder
                                                        .create("prevision1"),
                                                probability
                                        )
                                );
                    }
                }
        );
    }

    public static final String DUMMY_IDENTIFIER = "";

    @Override
    public void beforeCompletion(@NotNull CompletionInitializationContext context) {
        context.setDummyIdentifier(DUMMY_IDENTIFIER);
    }
}

Thanks

@BorderCloud
Copy link
Author

I found this function in the project antlr4 :

	protected void reportInputMismatch(Parser recognizer,
									   InputMismatchException e)
	{
		String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+
		" expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary());
		recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
	}

This function builds the description of PsiErrorElement.

Is it possible to add the function getExpectedTokens(offset) somewhere in your project ?

Or a method to read this list of tokens in my CompletionContributor class ?

@bjansen
Copy link
Collaborator

bjansen commented Mar 8, 2020

You could try https://github.com/mike-lischke/antlr4-c3, which has a Java port. I might be possible to plug this library to a CompletionContributor.

@BorderCloud
Copy link
Author

Thanks, it works with
https://github.com/mike-lischke/antlr4-c3/blob/master/ports/java/src/main/java/com/vmware/antlr4c3/CodeCompletionCore.java

I will try to implement a basic list of token for the moment.

It's a very good idea to plug this library to a CompletionContributor 💯

@BorderCloud
Copy link
Author

I tested... May be I used bad this class but sometimes, there are not responses :(

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

2 participants