micro-editor / micro-editor/micro

Region strings' syntax highlighting is broken when they're defined as part of another region themselves

Open
#4,148 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug triage
Dominant language
Go
Stars
29.6k
Forks
1.4k
Avg merge
2d 18h
Merged PRs (30d)
10

Description

Description

I was attempting to do something like the following to add syntax highlighting for PHP's attributes:

# ~/.config/micro/syntax/php.yaml

# Other rules above
- special:
    start: "#\\["
    end: "\\]"
    rules:
        - constant.string:
            start: "'"
            end: "'"
            skip: "\\\\."
# Other rules below

When defined as a above, attributes themselves will be highlighted properly in a PHP file (when placed above the one-line comment definition), but if the attribute contains a string, the string will only be highlighted properly until it matches any other rule in the file, even if it's not defined within the string region itself, as well as the closing quotation mark. For example, in the following code:

#[SomeAttribute('A very !long string *here with /some +symbols')]

Since the exclamation mark character is defined in another, unrelated rule as an operator in the same file, Micro will only highlight the initial 'A very ! and the final ' as a string. The text in between will be highlighted as regular text, following rules defined outside of the attribute region, even before it in the file (when the colors help file states that rules further down in the file should have more priority than rules above them). So string will be highlighted as a type, and *, / and + will be highlighted as operators.

I have tried the same with other region rule definitions, and it seems to be a generalized problem for strings defined as regions within regions. Perhaps other rule definitions besides strings would suffer from this problem. It's worth testing further.

It is worth noting that changing the above YAML configuration to the following does not have this effect:

# ~/.config/micro/syntax/php.yaml

# Other rules above
- special:
    start: "#\\["
    end: "\\]"
    rules:
        - constant.string: "'.*?'"
# Other rules below

The code above doesn't present the same problem, and in this case, strings will only be overwritten based on rules defined below them as part of the same attribute region.

Environment
  • Version: 2.0.13
  • OS: Linux Mint 22.3
  • Terminal: GNOME Terminal

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with ~/.config/micro/syntax/php.yaml and the nested region example, then compare it with the constant.string regex form using the provided PHP snippet. Trace how Micro applies rules inside nested regions and verify that strings keep their boundaries and precedence until the enclosing attribute region closes.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, php, yaml
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.