-
Notifications
You must be signed in to change notification settings - Fork 10
Named parameters are not highlighted for built-in functions like dict
#8
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
Comments
I've looked briefly at the source of the two different language definitions, but I haven't found the source of the change yet. I have a bunch of free time coming up this week, so I'll try and nail it down then. |
This is because the current python syntax file defines dict as a type but not also as a builtin function. What is more, the syntax file does not properly treat builtin functions like all other functions. I have fixed this in my Python language. @MattDMo, you should pick up the change in these two: facelessuser/sublime-languages@95bf5b6 and facelessuser/sublime-languages@d48e0bd |
@MattDMo, you can probably just diff mine against yours to see the changes more clearly. I don't pull in everything you do (I am not always sure of the reasoning behind some of the things you add), but for the most part, mine is pretty close to yours as I sync up useful stuff on occasions. |
I would have tried to match a generic function signature with lookaheads and then match for built in functions as keywords. I'd need access to my debug environment (home) to test this if your patch has the same effects though. |
Meh...It doesn't have to be implemented like mine. It's a personal branch, so sometimes I do things quick and dirty and clean up later...sometimes I'm lazy and don't clean up. I did minimal work to make this happen. The point is that the solution works whether you pretty it up or not. However you decide to do it, the language has to capture those |
Sure, the print keyword from py2 is special, but as far as I can see we have no way to differentiate between the py2 print keyword followed by a tuple or a function call anyway. So we only need to match that separately. |
I am differentiating it in my patch... Again, I'm just presenting what I did to offer a solution, I leave it the PythonImproved to improve upon the final solution. What is better is also subjective based on the desired end result. I am not suggesting my solution has to be used in its entirety. Just a working starting point. Do all built in functions need to be captured and scoped as |
I see there is some confusion about what I am doing, so here is the final snippet of code: <key>builtin_functions</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?<!\.)(__import__|ascii|abs|all|any|apply|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|copyright|credits|del|delattr|dict|dir|divmod|enumerate|eval|exec|execfile|exit|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|license|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|quit|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unicode|unichr|vars|xrange|zip)\s*(?=\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>support.function.builtin.python</string>
</dict>
</dict>
<key>end</key>
<string>(\))</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.arguments.end.python</string>
</dict>
</dict>
<key>name</key>
<string>meta.function-call.python</string>
<key>patterns</key>
<array>
<dict>
<key>begin</key>
<string>(?=[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*\s*\()</string>
<key>end</key>
<string>(?=\s*\()</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#dotted_name</string>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>(\()</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.arguments.begin.python</string>
</dict>
</dict>
<key>contentName</key>
<string>meta.function-call.arguments.python</string>
<key>end</key>
<string>(?=\))</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#keyword_arguments</string>
</dict>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
</array>
</dict>
<dict>
<!-- Non function style print -->
<key>match</key>
<string>(?<!\.)\b(print)\b</string>
<key>name</key>
<string>support.function.builtin.python</string>
</dict>
</array>
</dict> |
It seems that you're rather misunderstanding what I meant to express, though I have to agree I probably didn't convey the message very well. I'll try to draft out and test what I was thinking of but there's something more important right now and I'm a bit alienated from working with plists, but I'm sure you can read YAML well enough. Edit: The old dbg = []
def register_debug(func):
dbg.append(func)
def debug(*args, **kwargs):
return [func(*args, **kwargs) for func in dbg]
register_debug(print)
from functools import partial
register_debug(partial(print, end='\n---\n')) # file="out.log"
debug("test") |
Yes old print I'd not really function, so you could scope that case differently. I guess you could just scope it as a keyword or type if it doent have brackets. |
You could probably check if it's followed by a comma or a |
FYI, there will have to be exceptions for more than just |
To my knowledge (and some quick googling) del is always a keyword and not a function. |
I know, it was one of the things I didn't do though, I didn't go through and evaluate the ones that exclusively should not be functions. I thought of print of the top of my head, but there are more. |
@facelessuser sorry, I haven't been following along as closely as I should have been. So basically, the take-home change for right now would be to modify the current contents of <key>builtin_functions</key>
<dict>
<key>match</key>
<string>(?<!\.)\b(__import__|abs|all|any|apply|callable|chr|cmp|coerce|compile|copyright|credits|del|delattr|dir|divmod|enumerate|eval|exec|execfile|exit|filter|format|getattr|globals|hasattr|hash|help|id|input|intern|isinstance|issubclass|iter|len|license|locals|map|max|memoryview|min|next|open|ord|pow|print|property|quit|range|raw_input|reduce|reload|repr|reversed|round|setattr|sorted|sum|unichr|vars|zip)\b</string>
<key>name</key>
<string>support.function.builtin.python</string>
</dict> with what you posted above in your huge XML dump? I just want to be sure I'm on the right page before I convert it to YAML and merge it with some other (admittedly much more minor) changes I've been working on recently. I also have really gotten tired of trying to interpret regexes surrounded by plist foolishness - YAML just makes so much more sense, even more so than JSON. Never mind, I just went ahead and did it... |
So if you look at the Simple Statements part of the Python 2 docs, then in my mind it seems to imply that |
Good questions. That is really up to you. I have them currently as builtin function exceptions (no parenthesis), but I may end up removing it and letting it fall to types right below it...don't know yet. |
Changes incorporated into release 1.3.0. Thank you, everyone! |
Built-in functions like `any()`, `dict()`, `len()`, `raw_input()`, etc. now have their arguments highlighted just like any other function. Many thanks to [@facelessuser](https://github.com/facelessuser) for the regex, and [@FichteFoll](https://github.com/FichteFoll) for valuable discussion. For those working with Python 2, `print` is still a standalone keyword, as is `del`. If you can think of any others that should be as well, please [let me know](MattDMo/PythonImproved#8).
In the following snippet named parameters are not highlighted for built-in functions like they are for any other function. This works correctly in the standard Python definition.
The reason is likely that you are consuming the
dict
keyword and the construct is not recognized as a function but a tuple (or actually nothing at all because you don't match tuples).The text was updated successfully, but these errors were encountered: