jecki / ts2python

Python-interoperability for Typescript-Interfaces
Apache License 2.0
42 stars 4 forks source link

support `declare` keyword on interface #2

Closed alonbl closed 1 year ago

alonbl commented 2 years ago

Hi,

For this interface I get an error:

export declare interface ChecksPluginApi {
}

1:1: Error (1000): Malformed syntax-tree! Possibly caused by a parsing error. 1:16: Error (1040): Parser "declaration->:" did not match: »interface ChecksPlug ...«

I tried to fix this and send pull request, however, the implementation is very difficult to understand so I failed. Replacing s/declare// allows me to compile, so it is only a matter of ignoring the keyword.

Reference example[1]

Regards, Alon

[1] https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/app/api/checks.ts

jecki commented 1 year ago

Thanks for reporting and sorry for answering this so very late. It has now been fixed in the development branch by simply ignoring the "declared" keyword when it appears in front of interface. I hope this is sufficient. Or should the Python code somehow be affected by "declare"?

You are right: The implementation is somewhat complicated and probably needs refactoring. Unfortunately, at the moment I find little time to work on this. In this case since I did not change code generation. I just needed to change the grammar definition slightly by adding an optional "declare" keyword:

interface   = ["export"] ["declare"] ("interface"|"class") §identifier [type_parameters]
              [extends] declarations_block [";"]
alonbl commented 1 year ago

Thank you, I think that ignoring the declare keyword is sufficient.