jmzambon / libreoffice-code-highlighter

Code snippet highlighter for LibreOffice.
https://extensions.libreoffice.org/en/extensions/show/5814
Other
79 stars 5 forks source link

LibreOffice Basic Code Style #6

Closed flywire closed 2 years ago

flywire commented 2 years ago

It looks like there is no style to match lo basic and a new style is needed:

jmzambon commented 2 years ago

Hi,

Thank you for the relevant source files. I would be happy to try to suggest specific lexer and style, as soon as I have some free time.

flywire commented 2 years ago

The following file is probably good enough for the styles folder as described in: https://pygments.org/docs/styledevelopment/

star.py

from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
     Number, Operator, Generic

class StarStyle(Style):
    default_style = ""
    styles = {
        Comment:                '#808080',   # Gray
        Keyword:                '#0000FF',   # Blue
        Name:                   '#008000',   # Green
        Name.Function:          '#008000',   # Green
        Name.Class:             '#008000',   # Green
        String:                 '#FF0000'    # Red
    }
jmzambon commented 2 years ago

Just in case:

flywire commented 2 years ago

VbNetLexer is good enough. Need alias for LibreOfficeBasic, OpenOfficeBasic and StarOfficeBasic, maybe lobas, oobas and sobas.

flywire commented 2 years ago

I don't know how to implement the lexer solution but something like one of these two options should work:

  1. Modify dotnet.py
 class VbNetLexer(RegexLexer):
     """
     For Visual Basic.NET source code.
+    Also LibreOffice Basic, OpenOffice Basic, and StarOffice Basic.
     """

     name = 'VB.net'
     url = 'https://docs.microsoft.com/en-us/dotnet/visual-basic/'
-    aliases = ['vb.net', 'vbnet']
+    aliases = ['vb.net', 'vbnet', 'lobas', 'oobas', 'sobas']
  1. starofficebasic.py - New lexer calling another (but I don't know how)
from pygments.lexer import VbNetLexer
from pygments.token import *

class StarOfficeBasicLexer(VbNetLexer):
    name = 'sobas'
    aliases = ['oobas', 'lobas']

    def get_tokens_unprocessed(self, text):
        for index, token, value in VbNetLexer.get_tokens_unprocessed(self, text):
            yield index, token, value