# Custom syntax highlighting for PythonNETParser

**URL:** https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458
**Category:** AlterNET Studio Support
**Tags:** python, editor
**Created:** [May 23, 2024, 4:52am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458 "2024-05-23T04:52:39Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Hamish](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/h/606060/32.png) [@Hamish](https://forum.alternetsoft.com/u/Hamish)
#### Post date: [May 23, 2024, 4:52am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458/1 "2024-05-23T04:52:39Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)
#### Post date: [May 23, 2024, 9:35am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458/2 "2024-05-23T09:35:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Hamish](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/h/606060/32.png) [@Hamish](https://forum.alternetsoft.com/u/Hamish)
#### Post date: [May 24, 2024, 1:11am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458/3 "2024-05-24T01:11:17Z")

</div>

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](https://forum.alternetsoft.com/uploads/default/original/1X/4f7adfeb80d5168d550015250cb9197e3b17a074.png)

Thanks,  
Hamish

---

<div class="post-metadata">

### Author: ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)
#### Post date: [May 24, 2024, 7:18am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458/4 "2024-05-24T07:18:40Z")

</div>

Hi Hamish,

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

> **[CustomPythonDemo.zip](https://drive.google.com/file/d/1HkWidbUirU-5ZejoP6h-IhgNVpyDTqOI/view?usp=sharing)**
>
> Google Drive file.

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

Kind regards,  
Dmitry

---

<div class="post-metadata">

### Author: ![Hamish](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/h/606060/32.png) [@Hamish](https://forum.alternetsoft.com/u/Hamish)
#### Post date: [May 27, 2024, 3:14am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458/5 "2024-05-27T03:14:56Z")

</div>

Great thanks Dmitry, this works perfectly

---

<div class="post-metadata">

### Author: ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)
#### Post date: [May 27, 2024, 3:29am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458/6 "2024-05-27T03:29:20Z")

</div>

Hi Hamish,

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

Kind regards,  
Dmitry

---

<div class="post-metadata">

### Author: ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)
#### Post date: [June 18, 2024, 5:39am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458/7 "2024-06-18T05:39:30Z")

</div>

Hi Hamish,

We’ve just released an update (version 9.5.6), it’s available via [NuGet](https://www.nuget.org/profiles/Alternet) and can also be downloaded from our [website](https://www.alternetsoft.com/download).

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

Dmitry

---

<div class="post-metadata">

### Author: ![Hamish](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/h/606060/32.png) [@Hamish](https://forum.alternetsoft.com/u/Hamish)
#### Post date: [June 18, 2024, 5:50am UTC](https://forum.alternetsoft.com/t/custom-syntax-highlighting-for-pythonnetparser/458/8 "2024-06-18T05:50:51Z")

</div>

Thanks Dmitry, we’ll try that out
