[TxMt] Python grammar bugs

Paul Williamson paul at mustbeart.com
Fri Nov 24 03:23:39 UTC 2006


I have discovered a couple of oddities in the Python language grammar:

Function names containing digits are not handled the same as functions names that do not contain digits. You can see this by looking at how the following code is highlighted:

def foo(self):
	pass

def foo2(self):
	pass
	
I have not spent much time studying TextMate language grammars yet, but it appears that the "begin" regular expression for meta.function.python should be modified to allow digits in the function name.


Type names are highlighted as type names even in contexts where they couldn't possibly be type names. For example, in:

	foo.set(x)
	
the member function "set" is highlighted as if it were a type.

A negative look-behind RE could distinguish this specific case. I don't know how many other such cases are lurking in Python.

One could argue that it's bad practice to use type names as method names. Probably so, but it's not always avoidable. In particular, "set" wasn't even a type name until recently, and it's used as a method name in the standard library (e.g., in Tkinter). It's also a very nice verb to use as a method name.


Both of these came up while typing in a single recipe from _Python Cookbook_ (Recipe 11.11 from the 2nd Edition). I hope that's not typical. Syntax coloring needs to be *more* reliable than eyeballing the code.

  -Paul
paul at mustbeart.com



More information about the textmate mailing list