I want to create a tmLanguage file that will capture functions in SourcePawn files and add them to the symbol list.
The problem I’m having is that Pawn has no keyword to denote a function definition and semicolons are optional. Therefore I can’t seem to find a way to match function definitions using the single-line regex that Sublime uses and I can’t figure out how to make a begin/end work.
Take this code for example (formatting purposely inconsistent):
1. public Action:RoundEnd(Handle:event, const String:name], bool:dontBroadcast)
2. {
3. CheckWinCondition(true);
4. }
5.
6. CheckWinCondition(bool:round_end = false)
7. {
8. // ...
9. if (!round_end)
10. {
11. SetVariantInt(TEAM_BLU)
12. AcceptEntityInput(master_cp, "SetWinner")
13. }
14. }
15.
16. StartBeacon(client) {
17. // ...
18. }
Using this begin/end
<dict>
<key>begin</key>
<string>\w+\s*\(^)]*\)</string>
<key>name</key>
<string>support.function.sourcepawn</string>
<key>end</key>
<string>{</string>
</dict>
doesn’t work because it also captures function calls and consumes everything between the function call and the next ‘{’. So, it will capture everything between lines 3 and 7 and lines 11 and 16.
Is there any way to make this work? I’m currently generating completions using a plugin, but there is no API to allow a plugin to populate the symbol list so there is no way to easily navigate to function definitions.