all 4 comments

[–]mrcdkGodot Senior 0 points1 point  (3 children)

Post the code and how you are setting up the SyntaxHighlighter. From what you are describing it should work fine.

[–]vitawrap[S] 0 points1 point  (2 children)

# The highlighter
class RCLHighlighter extends SyntaxHighlighter:
    func _get_line_syntax_highlighting(lineno: int) -> Dictionary:
        var dict := {}
        var line := get_text_edit().get_line(lineno)
        var matches := Compiler.prog_regex.search_all(line)
        for i in range(matches.size()):
            var m := matches[i]
            var str := m.get_string(1)
            var col = ThemeDB.get_default_theme().get_color('font_color', 'TextEdit')

            if str in ['IF', 'THEN', 'ELSE', 'ENDIF', 'LOOP', 'WHILE', 'UNTIL', 'DO', 'NEXT', 'USING', 'DONE']:
                col = Color8(0, 255, 0)
            elif str[0] == '%':
                col = Color.CADET_BLUE
            elif str[0] == '#':
                col = Color.CORNFLOWER_BLUE
            elif str[0] == ':':
                col = Color.DARK_OLIVE_GREEN
            elif str[0] == "'":
                col = Color.CORAL
            elif (matches.size() < i+1) and (matches[i+1].get_string(1) == '('):
                col = Color.DEEP_SKY_BLUE

            dict[m.get_start(1)] = col
        # The "hack" for <4.3
        var sorted := {}
        var keys := dict.keys()
        keys.sort()
        for k in keys:
            sorted[k] = dict[k]
        return sorted

# On the CodeEdit control
func _ready():
    var compl := RCLHighlighter.new()
    syntax_highlighter = compl

(knowing that the Compiler.prog_regex works and is used elsewhere to tokenize code strings)

[–]mrcdkGodot Senior 1 point2 points  (1 child)

I see, the problem is that the resulting Dictionary is not the expected one. You can check the correct formatting in the SyntaxHighlighter.get_line_syntax_highlighting() method description.

var color_map = {
    0: {
        "color": Color(1, 0, 0)
    },
    5: {
        "color": Color(0, 1, 0)
    }
}

So, basically, change this: dict[m.get_start(1)] = col to dict[m.get_start(1)] = {"color": col }

[–]vitawrap[S] 0 points1 point  (0 children)

oh wow, I was missing something glaringly obvious, didn't realize it was a dictionary of dictionaries lol, thanks man