durkiewicz / elm-plugin

Elm language support plugin for IntelliJ IDEA.
MIT License
136 stars 15 forks source link

Valid let-in is marked as invalid #52

Closed l0rinc closed 7 years ago

l0rinc commented 7 years ago

For the following valid code

a = let b = 0
        c = 1
    in b + c

I get the error at the c = 1 line:

BACKSLASH, CASE, CHAR_LITERAL, DOT, IF, IN, LEFT_BRACE, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LET, LIST_CONSTRUCTOR, LOWER_CASE_IDENTIFIER, MINUS, NUMBER_LITERAL, OPERATOR, SEPARATION_BY_INDENTATION, STRING_LITERAL or UPPER_CASE_IDENTIFIER expected, got '='

The workaround is simple:

a = let 
        b = 0
        c = 1
    in b + c

I would gladly provide a PR for it, if needed :)

durkiewicz commented 7 years ago

That's great. You can have a look at org.elmlang.intellijplugin.manualParsing.CaseOfParser class. let ... in clauses need to be parsed by hand-written Java code, because it is one of 2 things that make Elm's grammar not context-free. BNF can only express context-free grammars.

l0rinc commented 7 years ago

Thanks, will do that. However, currently the generated PSI seems invalid for some reason, e.g.

public interface ElmRecord extends PsiElement

doesn't contain getReferencesStream:

Error:(45, 33) java: cannot find symbol symbol: method getReferencesStream() location: variable record of type org.elmlang.intellijplugin.psi.ElmRecord

Should it be a ElmPsiElement instead?

Would it be a good idea to push the default generated files up also, to simplify this procedure? Or to create a simple Gradle script that runs the code generation and tests automatically via Travis?

durkiewicz commented 7 years ago

Please try to generate the PSI once again. It sometimes generates incorrect code for the first run.

Regarding Gradle: there were some attempts to do it but it wasn't perfect: https://github.com/durkiewicz/elm-plugin/pull/7

I don't have enough Java ecosystem competences to do it properly. But if you are able to do it so that it:

then you are more than welcome to contribute.

l0rinc commented 7 years ago

Thank you @durkiewicz, generating it twice (without deleting the gen) solved the issue. I've put that in the readme also. I've provided a PR to fix this issue, though I couldn't find any let-in tests to modify or run. If you could give me some guidance, I would gladly augment the PR with proper tests also :).