Home Download Buy Blog Forum Support

Python syntax - import/from

Re: Python syntax - import/from

Postby agibsonsw on Sun Mar 25, 2012 4:48 pm

Hello @atomi.

Unfortunately, I haven't managed to obtain the behaviour I'm after. I believe that I need to modify the behaviour of the default 'meta.function-call.python' (as indicated by facelessuser), rather than trying to modify my own function lists' regex.

I've tried modifying the first/begin regex in the following - I only want it to capture thisword() but only if it's preceded by a dot. But I believe I need to modify the regex for 'dotted.name' as well. But dotted.name has other 'includes', and it's just dawned on me that I probably need to amend all of those as well?! I think that if I could modify the behaviour of these scopes - to only capture single words at a time - then I could just use (\.) within my function-lists/scope :?:

It's been a little frustrating :cry: especially as the documentation is quite poor. [What's the difference between 'patterns' and 'repository'?]

Code: Select all
<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>

I've even considered deleting huge chunks of 'Python.tmLanguage' :lol:
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Python syntax - import/from

Postby agibsonsw on Sun Mar 25, 2012 7:35 pm

Hey, no worries, I've got the behaviour I wanted with a simple (?&lt;=\.) addition:

Code: Select all
<string>(?x)(?:[a-zA-Z_][a-zA-Z0-9_]*\.)*(?&lt;=\.)(set_timeout|status_message|

I'm sure I tried this before :? - but hey, it works!

The point is that set_timeout(), and other methods, should only be recognised as an API call if it's preceded by a dot.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Python syntax - import/from

Postby agibsonsw on Sun Mar 25, 2012 8:00 pm

@atomi - thank you for these details :D. My regex was added as part of the following, near the top of the file.

Code: Select all
<dict>
   <key>captures</key>
   <dict>
      <key>1</key>
      <dict>
         <key>name</key>
         <string>support.function.api.python</string>
      </dict>
   </dict>
   <key>match</key>
   <string>(?x)(?:[a-zA-Z_][a-zA-Z0-9_]*\.)*(?&lt;=\.)(set_timeout|status_message|

I need all the complicated a-z business to prevent everything (prior to '(' ) being gobbled-up into the scope 'meta.function-call.python', and coloured according to this scope.

I've achieved my main aim ;) which was to require that method calls be preceded by a dot; otherwise, they are treated as normal/general function calls.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Previous

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 17 guests