tunnelvisionlabs / antlr4ts

Optimized TypeScript target for ANTLR 4
Other
633 stars 109 forks source link

Missing imports in generated classes #284

Closed mike-lischke closed 7 years ago

mike-lischke commented 7 years ago

I'm not 100% sure this is really a bug or by design. At least in the C++ target you have to manually add all the #include calls yourself.

However, in the TS target there are some imports that are automatically added, including the FailedPredicateException class. Grammars might use other exceptions (e.g. InputMismatchException in the CPP14.g4 grammar), though. Should that automatically be included as well or would a named action be required for the import?

sharwell commented 7 years ago

The expectation is imports are automatically added for everything generated by the templates. However, if the grammar contains actions which are copied directly (anything from @members to actions/predicates), they might need to include a @header action to import the required items.

mike-lischke commented 7 years ago

Hmm, ok, in TS you have an own import per class, while in C++, when you import one file for an exception, you automatically have all other exceptions included as well. Thanks.

BurtHarris commented 7 years ago

@mike-lischke: There's an open issue #195 proposing an alternative to the file-per-class structure for imports. During porting from Java, we left things file-per-class, but it's not clear to me if that's good style for Typescript or not.

mike-lischke commented 7 years ago

Well, certainly interesting to group things (like the exception hierarchy or ATNState and ATNStateType etc.). However, I have no problem with adding explicit imports when required. Just wanted to clarify the intended approach here