Custom syntax highlighting for PythonNETParser

Hi,

We’re using the PythonNETParser alongside PythonNET to provide a editor (DebugCodeEdit) in our application.

Are we able to pass in specific keywords that we want highlighted? Similar to how Python keywords are highlighted blue.

Also I’ve noticed the PythonParserEmbedded has a lot more syntax highlighting based on the parsed token’s datatype. I haven’t been able to get the PythonParserEmbedded to work well with the PythonNET bindings to our .NET code with CodeCompletion. Do you know if this is possible at all?

Thanks,
Hamish

Hi Hamish,

Could you please specify which keywords you need to highlight? We wrote PythonNetParser ourselves, so it should be possible to extend it to highlight extra keywords (but they still need to be treated as identifiers, right)?

PythonParserEmbedded - this one is based on LSP parser technology where code completion is provided by an LSP provider (Python itself, in this case). For it to provide code completion for your .NET objects, it needs to know about them (and for that, we need to generate Python interface files containing all properties/methods of your .NET objects). We’ve done it for TypeScript, so it might be possible to do the same for Python; however this has not been implemented yet.

We use TextMate-based syntax highlighting for LSP parsers, which works similarly to Visual Studio code.

Kind regards,
Dmitry

Hi Dmitry,

We have added two GlobalItems to our script which access our .NET objects named “plates” and “liquids”.

Ideally it would be nice if we could get these highlighting blue e.g. ‘pass’ keyword or ‘def’. So maybe a function or property to add specific keywords with specific colours?

Thanks for that info! The PythonNETParser does most of what we need but it would also be nice if it was capable of highlighting variables inside of f-strings. At the moment it’s all the same colour for anything inside the quote characters. This is how VSCode (I assume the TextMate highlighting you mentioned) handles these.

image

Thanks,
Hamish

Hi Hamish,

I’ve uploaded a demo project that shows how to modify syntax highlighting for your custom identifiers.

Supporting f-strings will require a bit more time, and we’re looking into it.

Kind regards,
Dmitry

Great thanks Dmitry, this works perfectly

Hi Hamish,

We will include support for f-strings in Python in the next update. I will keep you posted.

Kind regards,
Dmitry

Hi Hamish,

We’ve just released an update (version 9.5.6), it’s available via NuGet and can also be downloaded from our website.

We’ve added support for custom identifiers (via pythonParser.Classifier.CustomIdentifiers property), and basic handling of f-strings.

Dmitry

Thanks Dmitry, we’ll try that out