micro icon indicating copy to clipboard operation
micro copied to clipboard

[Bug] Bash's syntax highlighting mishandles `'` in comments

Open cyqsimon opened this issue 2 years ago • 1 comments

Description of the problem or steps to reproduce

Paste the following into a file and open it with micro:

#!/usr/bin/bash

echo "this example demonstrates the mishandling of \'" # by micro's syntax highlighting
echo "this part is highlighted incorrectly as of v2.0.10" # and now after another '
echo "back to normal"

Observe that the text between the first ' in the comments of line 3 and the next ' in the comments of line 5 is highlighted as if it's a big string.

Screenshot

bug

Specifications

Version: 2.0.10 Commit hash: b9763856 OS: Manjaro Terminal: Alacritty

cyqsimon avatar Jun 15 '22 08:06 cyqsimon

Problem is this line in the shell syntax definition: https://github.com/zyedidia/micro/blob/03ae049c0fe5862ca6010474dd775656bd6e5b86/runtime/syntax/sh.yaml#L61

The highlighter is not smart enough to handle (^|\\s) -- it just checks if it can match the beginning of a line beginning when it sees ^ anywhere inside the token regexp, even though it is inside an optional group in this case.

To fix this on your end you can override the built-in broken syntax by copying the sh.yaml file to ~/.config/micro/syntax/sh.yaml and making two different definitions for a comment like this:

    - comment:
        start: "^#"
        end: "$"
        rules:
            - todo: "(TODO|XXX|FIXME):?"

    - comment:
        start: "\\s#"
        end: "$"
        rules:
            - todo: "(TODO|XXX|FIXME):?"

Andriamanitra avatar Jun 18 '22 01:06 Andriamanitra

image

ICHx avatar Nov 23 '22 03:11 ICHx