2
votes

I had a question as to whether or not it was possible to get either the minted package, or the texments package, to syntax color like you would see in xcode. Not necessarily the same colors, that does not matter, but to get all of the variable types and things like that to highlight.

An example of this would be that when I used minted, things like @synthesize, float, int, all highlight but NSArray or NSMutableDictionary do not.

Does anyone know how to change this or possibly add more formatting to the package. I have searched, but nothing has been too helpful.

Thanks in advance for any assistance!

1

1 Answers

1
votes

Unfortunately, that’s not (easily) possible.

minted and texments rely on lexical analysis of the code. Lexical analysis is comparably easy and efficient but it is only the first stage of parsing a source code.

As a result, lexical analysis can recognise keywords, strings, comments and identifiers but it cannot tell identifiers apart. To do that, a parser would need to parse the whole code basis (comprising multiple files) and build an abstract syntax tree.

This is much more complex and time-consuming, and generally too inefficient for syntax colouring. For that reason, most code highlighting tools don’t perform such an in-depth analysis.

Xcode needs to fully parse the code anyway (for error messages, debugging and other things) and maintains a database of parsing information for each project. This allows it to provide more sophisticated code highlighting and still perform well. You might notice that if you load a single code file (not part of a project) in Xcode, no full syntax colouring of variable names will be performed either.