Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matlab: Parse variables in Matlab cod #571

Merged
merged 1 commit into from
Sep 24, 2015

Conversation

vhda
Copy link
Contributor

@vhda vhda commented Sep 22, 2015

No description provided.

@vhda
Copy link
Contributor Author

vhda commented Sep 22, 2015

Fixes #570, but since there isn't proper variable declaration in Matlab every assignment is identified as a declaration of a variable. So this solution is less than ideal.

@petobens
Copy link

@vhda thank you! Seems to work for me but I understand if you prefer not to merge it. No idea how to workaround the fact that Matlab doesn't have a proper variable declartion.

@vhda
Copy link
Contributor Author

vhda commented Sep 23, 2015

Let's wait for comments from the rest of the team (who have been oddly quiet lately).

@petobens
Copy link

@vhda ok. Thanks once again.

@masatake
Copy link
Member

@vhda, I'm sorry I'm bit busy now.
Could you show me unwanted input?
My guessing is:

A=1;
A=2;

In my example A is tagged twice, this is what you don't want?
If yes, do you want ctags to tag only the first A?
How about the seoncd A?
If #569 is merged, the second A should be marked as "reference"?

I would like to know idea case for future development.

@vhda
Copy link
Contributor Author

vhda commented Sep 24, 2015

Your guessing is correct.

Generally speaking, a tag is created when a variable is declared. But this is a problem in languages like Matlab, where the syntax does not include variable declaration. This is also true in Python, which does not use a regex parser but it also generates two tags if we assign the same variable twice. So, at least we would be consistent even if we merge this PR.

Going forward, it might make sense to create a mechanism where we only create a tag on the first occurrence in the current context. The context requirement would allow the use the same variable name in different functions, for example. This could probably not be too hard to implement in the cork mechanism, if I understood its functionality correctly. But parsers that do not use it will not benefit from the change.

Yes, if #569 is merged, the second A should be marked as "reference".
(P.S. - While reviewing #569, could you also take a peek at #80 again?)

@masatake
Copy link
Member

Generally speaking, a tag is created when a variable is declared. But this is a problem in languages like Matlab, where the syntax does not include variable declaration. This is also true in Python, which does not use a regex parser but it also generates two tags if we assign the same variable twice. So, at least we would be consistent even if we merge this PR.

Yes. Let's merge this.


Interesting topic.

About cork, as you wrote, it is possible to implement what we need.
I will introduce cork more to parsers; the first step is ruby.

After reading your comment, "reference" is not so simple. A name is referred variety reasons.
For this example "A" is referred as lvalue...It seems that there is a concept "reference kind".
Some ideas:

reference:D - Not reference, a definition.
reference:R - Generic. 
reference:A - Assignment(for variable)
reference:r - The value is used.
...

I wonder wheter ctags should deal with such detail or not.
I should implement -X option first. About "reference" we have to discuss more.

@petobens
Copy link

Generally speaking, a tag is created when a variable is declared. But this is a problem in languages like Matlab, where the syntax does not include variable declaration. This is also true in Python, which does not use a regex parser but it also generates two tags if we assign the same variable twice. So, at least we would be consistent even if we merge this PR.

Not really sure if I completely understand the discussion but I just want to mention that with R files if one writes:

A <- 1
A <- 2

then two tags are generated for the variable A.

@masatake
Copy link
Member

@petobens, do you want ctags to make a tag entry for each "A" ?
I guessed you may want ctags to make a tag entry only for the first one.

@petobens
Copy link

@masatake , I'm not really sure. I believe that a tag entry for the first one is definitely necessary. However tags for each entry might be useful . For example in Vim I use a tag explorer buffer: if there is an entry for each variable then I can see how that variables changes with each new assignment (this might be useful or not, I guess in the end it's a matter of personal preference).
But I understand that maybe the standard use is to use tags to jump to the definition (i.e to the first variable declaration). So really I cannot decide for one or the other.

screenshot-24-09-2015_11-08-55

@masatake
Copy link
Member

@petobens, thank you for explanation. I understand the second one is useful. However, the first one may be more important than the other. Anyway we will merge the change.

@petobens
Copy link

@masatake great. Thank you!

@vhda
Copy link
Contributor Author

vhda commented Sep 24, 2015

@masatake just noticed the typo in the subject of the commit. Allow me to fix it tonight and I'll merge the PR afterwards.

@masatake
Copy link
Member

@vhda, sure!.

vhda added a commit that referenced this pull request Sep 24, 2015
matlab: Parse variables in Matlab cod
@vhda vhda merged commit 1802161 into universal-ctags:master Sep 24, 2015
@vhda vhda deleted the matlab/variables branch September 24, 2015 23:32
@petobens
Copy link

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants