Skip to content

Valid char literals in C source files are highlighted as errors #3765

@Andriamanitra

Description

@Andriamanitra

Given a C source file with a character literal, the character always gets highlighter with error color unless it's a valid escape sequence:

char str[]  = "a";
char broken = 'a';    // should be the same color as the "a" above
char escape = '\x11'

Image

The error highlighting comes from this rule in c.yaml, which makes me think the bounds of highlight regions with start/end are slightly off:

    - constant.string:
        start: "'"
        end: "'"
        skip: "\\\\."
        rules:
            - error: "..+"
            - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})"

This used to work properly in v2.0.11, but is broken in v2.0.12 and newer. I used git bisect to track down the commit which changed the behavior: ceaa143

I also tried with a build from PR #3127 and it would fix this issue.

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