Python editor: syntax highlighting ignores string/comment context ('#' in a string, '"""' in a comment) · Issue #660 · emsec/hal · GitHub
Skip to content

Python editor: syntax highlighting ignores string/comment context ('#' in a string, '"""' in a comment) #660

Open

Description

@horhulenko

Describe the bug
The Python editor's syntax highlighting doesn't keep track of where a string or a comment actually starts and ends. Two cases I ran into:

  1. A # inside a string literal is highlighted as if it started a comment — the rest of the line turns the comment color, even though it's still part of the string and normal code.
  2. A """ inside a real comment opens a docstring for the highlighter — every line after the comment is colored as string, for the rest of the file.

The scripts run fine, it just looks wrong and makes the code hard to read.

To Reproduce

  1. Open HAL and load any netlist.
  2. Open the Python Editor.
  3. Type:
    print("Normal string and after hashtag (#)" + " this part must not be green.")
    Everything from the # on is colored as a comment, including the closing quote and the rest of the line.
  4. Type:
    # docstrings are crazy """
    print("hello")
    x = 5
    
    print("hello") and x = 5 are colored as if they were inside a string, and so is everything below them.

Expected behavior
A # inside a string should be colored as part of the string, and only a # outside a string should start a comment. Quotes inside a comment — including """ — should be ignored, and the lines after the comment should keep their normal colors.

Screenshots
Image

Image

Desktop (please complete the following information):

  • OS: Windows 11 Pro (10.0.26300)
  • Version: 4.5.0 (v4.5.0-147-gff98e36c6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions