Skip to content

Better function call matching (also decorators) #17

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

Closed
wants to merge 16 commits into from

Conversation

FichteFoll
Copy link

As discussed in #16, I finally worked on the function call matching that I already thought of in #8.

Following is a snippet that I used for testing:

list(map(str, range(100)))
[str(i) for i in range(100)]

super(arg1=1)(arg2=2)
list abs, map
some.None NotImplemented

print (file=None) print . __class__
print keyword print __init__

__init__ . something()

callback(print)

.__init__
__init__ [2]


@ deco . __init__ (call=some)  # rator
def function():
    pass

2014-09-03_06 32 40

Closes #16.

PS: This is unrelated, but there are a couple of include: $self occurences that are technically incorrect because in most of these cases only an expression is allowed. However, the snytax def itself is not grouped into statement vs expression, so the grouping would be a required step for this (and would also add more structure).

Essentially reverts #8, but this is in scope of a bigger change.

Also clearly separate built-in functions and built-in types because some
used to be duplicated.
The previous attempt just didn't work because of two reasons:
1. The "dotted_name" was already consumed in function-call's "begin"
   match.
2. All "special" identifiers were essentially matched before the
   function call which meant that the actual call would never be
   matched since the function to be called (the identifier) was already
   consumed.

Simplify #dotted_name a bit in the process.
The print statement can now only be matched if it's not used in a
function previously since otherwise it would've been consumed.
@FichteFoll
Copy link
Author

Forgot about decorators but for some reason I can't get them to work properly right now. Maybe I'll see it after some sleep.

Edit: got it in the end

@FichteFoll FichteFoll changed the title Better function call matching Better function call matching (also decorators) Sep 3, 2014
Although it looked okay-ish with background color it was not intended.
Otherwise, color schemes defining a background color for
`entitiy.name.function` would make decorators span the remainder of the
line.
@FichteFoll
Copy link
Author

Fixed a few regressions, mostly regarding decorators.

Test snippet:

@normal.decorator
class Class():

    @indented(method)#comment
    def wrapper(self):
        pass

@MattDMo
Copy link
Owner

MattDMo commented Sep 4, 2014

Sorry about my slow feedback, but I'm really taking my time with this, trying to understand all the changes you're making and if they are in the direction I want to go. Feel free to keep pushing more commits, I'm trying to go through them in order, but alas real work is also interfering 😩 so it may be some time before I accept anything. Thanks for your help, though!

@FichteFoll
Copy link
Author

Sure thing. It's not like I depend on an upstream merge here since I can use my local version just fine, so take your time.

I only noticed the regressions as I happend to view a file with lots of decorators that happend to be open while I was testing sublimehq/sublime_text#464. Other than that I think everything's fine.

Furthermore, since I now have a feeling of how the syntax is structured I can make other changes more quickly, such as splitting the syntax def into statements and expressions, should I ever feel bored enough to do that.

Previously, `self.CONSTANT` was not matched.
Or well, it's only valid syntax in Python 3.
Even though we can't really match that correctly, at least match the
leading dot on a new line or after a function call. That's more correct.

Example:
ident = (value.dotted
         .__init__)
It could be of use for regression testing later, or whatever. In any
case it should illustrate most of the changes of my pull request and can
easily be extended.
@FichteFoll
Copy link
Author

Fixed highlighting of ALL_CAPS constants in dotted names which really annoyed me and addressed a few other issues that just crossed my mind.

I also added my personal test file for future reference. It uses the .pyw extension so that it doesn't get loaded by ST as a plugin (since it's invalid syntax anyway).

@FichteFoll
Copy link
Author

poke

@FichteFoll
Copy link
Author

Fixed an annoying regression with from . import statements.

It's likely harder to merge this now because you made changes on your own and they are now conflicting.

@MattDMo
Copy link
Owner

MattDMo commented Sep 9, 2015

@FichteFoll sorry for the huge delay, but I'm finally getting around to thinking about releasing PythonImproved 2.0, and I've incorporated a lot of your changes from this PR into PythonImproved-Unicode.YAML-tmLanguage in the unicode branch. However, right off the bat, I've noticed an issue with meta.dotted-name.python — it's being applied to all meta.identifier.python scopes. If I comment out line 583 it doesn't show up in the identifier scope anymore. Thoughts?

@FichteFoll
Copy link
Author

Well, pretty much everything in Python is a "dotted name" (because I made the dotted part before the last 'undotted' part just optional). #dotted_name includes #generic_names, which is your meta.identifier.python. Note that this is used for "identifier that does not have another special meaning" and does not include the dots. meta.dotted-name.python is just the "catch-all" for pretty much all dotted names you'll encounter, including the illegal ones with keywords for example.

This part would look a lot simpler with contexts from sublime-syntax btw.

@FichteFoll
Copy link
Author

I have the feeling that there are quite a few parts missing which I will look into tomorrow. I'll probably prepare a syntax-test file from my fork and compare that to your unicode branch.

@MattDMo
Copy link
Owner

MattDMo commented Sep 10, 2015

OK, thanks. I'm hoping to release 2.0 by Sunday at the latest (probably quickly followed by 2.0.1, etc.) to coincide with the release of Python 3.5. After that we can talk about making a .sublime-syntax version.

@FichteFoll
Copy link
Author

I prepared a syntax test file from my previously used test file and pushed it to the branch.

Notable issues with your unicode branch (visible in testfile):

  1. The actual reason why I made the PR in the first place (Built-in types are highlighted as support.function and not support.type if called #16): types are matched as functions instead of types when used in function calls
  2. Built-in functions are only matched when used in a function call and not when used as a callback parameter for example
  3. Ellipsis and NotImplemented should not be matched as attributes
  4. parameters for magic function calls do not get highlighted
  5. print matched as invalid in several places where it is valid, just as a function
  6. allcaps constants not matched in attribtue access from results from function calls
  7. decorators with spaces fail deliberately
  8. decorators only have the initial name highlighted as entity.name.function.decorator (which is imo the wrong scope anyway) and do not continue over the entire decorator call, if there is one. This is actually wrong in my version too, but at least consistent

So yeah, it's probably 80% of my work that's still missing.

I honestly do not feel like revisiting this again. You just took too long to merge the changes I made and made too many changes on the main and unicode branch in the meantime so that merging will be a hassle.

Instead, I will most likely work on a new Python.sublime-syntax version from scratch, while taking some inspiration from my fork. There are a couple of things where contexts would be way easier than this.

@MattDMo
Copy link
Owner

MattDMo commented Dec 4, 2015

I'm going to close this, mainly for the reasons you mentioned above - it's no longer mergeable, and things have just moved on. I think working on a .sublime-syntax version is a great idea, although the audience will be somewhat limited due to the fact that the new format isn't supported yet in the public beta. (Speaking of which, any word from Jon on when development is going to start up again?).

I've started #54 to track .sublime-syntax work, and I'll be making a new branch soon.

@MattDMo MattDMo closed this Dec 4, 2015
@FichteFoll
Copy link
Author

(Speaking of which, any word from Jon on when development is going to start up again?)

None that I know of, sadly.

I made a pretty nice YAML syntax definition and submitted it to the packages repo 4 months ago (sublimehq/Packages#90), but no word since. My end goal would be to have a neutral, comprehensive and accurate Python.sublime-syntax that was bundled with Sublime Text by default, but so far I'm hesitant due to the lack of updates.
As you mentioned, .sublime-syntax is still a dev-only feature and I'd rather spend my time on plugins for all people (on ST3) rather than just the ones on dev. There are numerous ways for me do to that.

Yet, I think of how I would structure it at least twice a week.

@MattDMo
Copy link
Owner

MattDMo commented Dec 4, 2015

Definitely understandable. I'll work on it now and again just to learn how the format works, but I'm certainly not expecting a rush effort on PI to push it out the door.

@facelessuser
Copy link
Contributor

sublimehq/Packages#90

Nice, I didn't know about this. I will have to try it out.

infininight pushed a commit to infininight/python.tmbundle that referenced this pull request Apr 20, 2016
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.

Built-in types are highlighted as support.function and not support.type if called
3 participants