Grammar-Kit icon indicating copy to clipboard operation
Grammar-Kit copied to clipboard

Is there any way to keep psiImplUtilClass smaller?

Open OptimisticLock opened this issue 9 years ago • 9 comments

Thank you for an awesome plugin!

Our psiImplUtilClass is 2,000 lines long and growing. It made sense to use one single psiImplUtilClass it for a smaller, simpler grammar, but for us, this is beginning to get out of control. In some cases, it's also bad OO: many of my PSI elements do reference lookup, and I don't think it's a good idea to add multiple reference lookups to this already bloated file. Is there a better way?

OptimisticLock avatar Sep 23 '16 20:09 OptimisticLock

Have you tried mixin classes? You should be able to specify a mixin for your type and tell Grammar-Kit to extract methods from that class.

jvolkman avatar Sep 23 '16 21:09 jvolkman

Thank you for a quick answer. Just did that. Beautiful!

This leads me to a couple more questions.

  1. Is there any way to import a package name, so that I don't have to do a fully-qualified class name in every mixin? I only saw parser imports.
  2. I'd love to be able to do something like this: mixin(".*") = "com.dreambox.elements.My$1"

As usual, it would only generate mixins if corresponding classes exist. Doable?

BTW, one of your manuals says "to be continued".. would be great to learn more.

OptimisticLock avatar Sep 23 '16 22:09 OptimisticLock

I don't think either of those features currently exist, although I'm not positive (I'm just a fellow Grammar-Kit user).

jvolkman avatar Sep 23 '16 23:09 jvolkman

Ah, then thank you very much for your help.

OptimisticLock avatar Sep 23 '16 23:09 OptimisticLock

BTW, maybe you also know how to remove those ugly error messages, short of changing name in every rule?

MyTokenType.DOT expected, got ";"

Any way to substitute token names with values?

OptimisticLock avatar Sep 23 '16 23:09 OptimisticLock

Are you using Live Preview when you see that error? It has been a veery long time since I've used that now, but I believe that style of message only occurs in Live Preview mode.

In a proper run of your app, Grammar-Kit should make use of the 'debug name' you provide to the token's IElementType constructor.

calexHG avatar Sep 24 '16 03:09 calexHG

No, I am getting this in tool tips in an actual IntelliJ. My generated GenElementTypes.java has the following:

IElementType DIVIDE = new MyTokenType("DIVIDE"); And, in .flex "/" { return GenElementTypes.DIVIDE; }

OptimisticLock avatar Sep 27 '16 01:09 OptimisticLock

LOL, a well asked question answers itself. The culprit was MyTokenType.toString(). DIVIDE is still not as good as / would have been, but much better now.

OptimisticLock avatar Sep 27 '16 02:09 OptimisticLock

Ahh, yes, that would obviously get in the way of things also ;P

... As for the automatically generated debugName, I don't notice it, as I provide all of my IElementTypes.

calexHG avatar Sep 30 '16 14:09 calexHG