I have a function definition like this:
FunctionName(Argument) ; function definition
{
; do something in function body
}
And a function call like this:
FunctionName(Argument) ; function call
Syntax highlighting cannot see past line boundaries, so I cannot properly highlight FunctionName and Argument here using the language’s .sublime-syntax file (Autohotkey’s), because a line with a function call looks exactly the same as a line with a function definition where the braces only come at the next line.
So I’m trying to solve this by creating a plug-in. What would be the best way to approach it?
I have been thinking of having the plug-in add an invisible character at the end of a function-definition line, in order to trigger proper highlighting (the sublime-syntax file will have to recognise this character in a regex). But I really don’t like to mess up people’s code with invisible characters. What if they copy-paste it somewhere and it causes undetectable problems?
I could add a comment like ’ ; {’ to the line, again to be caught by the sublime-syntax regex. But it looks messy, and it still changes people’s code.
I could somehow highlight regions ‘manually’ through the plug-in and add the function name to the list of symbols. I’d have to create a kind of parser in the plug-in, to distinguish between function definition and reference, and to find the arguments to highlight. That seems like a lot of work, and it may not work reliably. In addition, because I may have to set the colours in the plug-in, it may work only well with one colour scheme (Monokai in my case). (This sub-point may be solvable.) Lastly, anything that other plug-ins or colour schemes do using scopes would fail with these function definitions, as they will have the wrong scopes.
If only there were a way to assign scopes in a plug-in! But I believe that is not possible?