Closed Coeur closed 5 years ago
It seems that the culprit is https://github.com/terryyin/lizard/blob/master/lizard_languages/swift.py#L35:
if token in ('get', 'set', 'deinit'):
self.context.start_new_function(token)
self._state = self._expect_function_impl
Note that it is correct Python code for Swift situations like:
var hello {
get { return "hello" }
set {}
}
But in the following contexts it's not correct to interpret get
as a function:
case get ...
var get ...
let get ...
So I advice to create a new _state
for declarations. Something along the lines of:
if token in ('var', 'let', 'case'):
self.context.start_new_variable(token)
self._state = self._expect_variable_impl
And you would leave the declarative state when encountering a new line, an opening brace {
, a semicolon ;
, a colon :
or an equal sign =
.
Hi Antoine,
Thanks! In training this week so the fix will come a bit late. Is it possible to have a pull request from you?
Sent from my iPhone
On Oct 23, 2018, at 11:52, Antoine Cœur notifications@github.com wrote:
It seems that the culprit is https://github.com/terryyin/lizard/blob/master/lizard_languages/swift.py#L35:
if token in ('get', 'set', 'deinit'): self.context.start_new_function(token) self._state = self._expect_function_impl
Note that it is correct Python code for Swift situations like:
var hello { get { return "hello" } set {} } But in the following contexts it's not correct to interpret get as a function:
case get ... var get ... let get ... So I advice to create a new _state for declarations. Something along the lines of:
if token in ('var', 'let', 'case'): self.context.start_new_variable(token) self._state = self._expect_variable_impl
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
@terryyin Ah ah, I was fearing that. OK, I'll do a pull request, but I don't know how to run unit tests from command line (I only know python lizard.py files
). So it's likely that I'll break something.
OK, I figured out how to run the tests locally:
make deps make tests make pylint brew install python3 make tests3
Glad to see you solve this. I still have yet another day of training...
@terryyin How was the training? :)
I have the following Swift file, but lizard (master branch at b631dfd3561366539633a7279f755e237541f3bf) believes it is one single giant getter:
lizard output: