AzureMarker / intellij-lalrpop

Jetbrains plugin for the LALRPOP parser-generator
MIT License
16 stars 2 forks source link

Resolve `<>`? #3

Closed dnbln closed 3 years ago

dnbln commented 4 years ago

As of now, (I think the Rust plugin?) says "error: Chained comparison operator require parentheses" when using <>

AzureMarker commented 4 years ago

Yeah, this is the next big area of improvement for the plugin. A few things need to happen to support this notation:

  1. We need to be able to modify the injected Rust action code such that <> is replaced with some special variable (e.g. __intellij_lalrpop_selection) so the Rust plugin can parse the code. The hard part is performing this transformation without affecting the source PSI elements (what's shown in the lalrpop file). This will require some more research.
  2. Parse the "alternative" grammar so we know what the input variables and types are. Examples: Item* is a Vec of Item's type, <Visibility> "fn" <Name> is a tuple of the visibility and name types, <var:Id> "=" <expr:Expression> has two named variables, etc. Currently, the last example is supported as long as Id and Expression explicitly declare their types, i.e. Id: String = ....

Edit: some more examples of alternatives at the bottom of this page: http://lalrpop.github.io/lalrpop/tutorial/003_type_inference.html

dnbln commented 4 years ago

I tried my hand at solving the second part and realized that in cases like <Visibility> "fn" <Name>, <> is not really a tuple, but (<>) is. Small but important distinction here.

dnbln commented 4 years ago

I might have just found a solution to 1. (but I'm not really sure it would work): the LiteralTextEscaper

// from PsiLanguageInjectionHost
  /**
   * @return {@link LiteralTextEscaper} instance which will be used to convert the content of this host element to the content of injected file
   */
  @NotNull
  LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper();
dnbln commented 4 years ago

Ok turns out I was right: it is able to do that. Implemented it in https://github.com/dblanovschi/intellij-lalrpop/commit/745608f234e9bfa99d114738b879aa3401d4d3ef :tada: . Now on to evaluating what's "selected" from the list of symbols in the alternative.

dnbln commented 4 years ago

I finally got it to find what's selected or not (after getting sidetracked on type resolution in lalrpop; so now the types in rust injections are way more accurate, but at quite the cost).

AzureMarker commented 3 years ago

Fixed by #17 :tada: