[TxMt] Re: Best approach to add new Scoping rules to grammar

Steve Lianoglou lists at arachnedesign.net
Mon Feb 12 06:29:46 UTC 2007


>> Or should I change the Python grammar to somehow set those two scopes
>> for the """ ... """ string matching pattern (I'm not sure if you can
>> do that, though).
>
> At the moment, the best way is probably to just edit the python  
> grammar, adding
> the text.restructuredtext scope to the strings.  Then you'll also  
> get niceties
> like syntax highlighting for reST inside your python strings, etc.

I see ... so how would that look like, exactly?

In the Python grammar, I guess this would be the right place:

{	name = 'string.quoted.double.block.python';
comment = 'double quoted string';
begin = '(""")';
end = '((?<=""")(")""|""")';
beginCaptures = { 1 = { name =  
'punctuation.definition.string.begin.python'; }; };
endCaptures = {
1 = { name = 'punctuation.definition.string.end.python'; };
2 = { name = 'meta.empty-string.double.python'; };
};
patterns = (
{	include = '#constant_placeholder'; },
{	include = '#escaped_char'; },
);
},

Do I just fiddle with the first name =  
string.quoted.double.block.python to add test.reStructuredText to it  
(what's the right way to do that)?

> Incidentally, are any other python users bothered by the decision  
> to use reST as
> the de facto format for docstrings?  reST really clashes with  
> python's clean
> aesthetic for me.

There was a bit of a (long) discussion on the NumPy / SciPy list  
about this very same issue a while back over the same issue (reST  
looking too noisy). I think they settled on using reST with a bit of  
tweaking via some epydoc magic to make it *just a bit* cleaner.

To be honest, however, I don't find reST all that bad ... I kinda  
like it.

That said, though, I look forward to v2.0 when (I think) we'll be  
able to fold away the docstrings a bit more cleanly/robustly so I  
don't have to look at them all day :-)

-steve




More information about the textmate mailing list