Multiple characters bracket

Hi there!

I just made an extension for OCaml since the existing one doesn’t work.
While defining the syntax for OCaml, I came across the issue of brackets. I’m defining brackets for OCaml, since there is more than {, (, [.
Yes! There’s also these: [|, |] for arrays… And you might have guessed it, these brackets are two characters long.

I’m defining them that way in the OCaml.xml syntax file:

    <brackets>
        <pair open="{" close="}" />
        <pair open="[|" close="|]" />
        <pair open="[" close="]" />
        <pair open="(" close=")" />
    </brackets>
    <surrounding-pairs>
        <pair open="{" close="}" />
        <pair open="[|" close="|]" />
        <pair open="[" close="]" />
        <pair open="(" close=")" />
        <pair open="'" close="'" />
        <pair open="\" close="\" />
        <pair open="`" close="`" />
    </surrounding-pairs>

However, it doesn’t really work when it comes to highlighting:
Array highlighting
The opening bracket is correctly highlighted, but not the closing one.

Here are screenshots for respectively opening and closing brackets using inspector tool:


Is there something I did wrong when defining the brackets, or is that a bug due to 2 characters forming the bracket?

Thanks in advance,
Gubeka

2 Likes

Yea… that is the same problem with php Blade extension. {{php stuff}}, or {!! php stuff !!}. It would be nice for Nova to support the multiple characters tbh.

There was a hack that was mentioned in an issue raised on github for the Blade. Basically removing the pair and going for singles.

  • changing <pair open="{{" close="}}" /> :arrow_right: <pair open="{" close="}" /> which is actually a default by Nova anyways.
  • This was more pleasant and symmetric but Nova coloured each { and } separately as if it is nested

In your case I would suggest trying each individually? Basically breaking [| x |]:

<brackets>
        <pair open="[" close="]" />
        <pair open="|" close="|" />
</brackets>
 <surrounding-pairs>
        <pair open="[" close="]" />
        <pair open="|" close="|" />
 </surrounding-pairs>

Let me know if it works, or if you come across a better way to bypass this :sweat_smile:
Emran

1 Like

That was a genius idea, but there must be something in the background preventing this, because | are not matched automatically, no matter if using them in an array or testing them alone.

1 Like

Mmm I gave it a shot myself but it actually sounds like a bug :thinking:
I would suggest marking this as a bug :lady_beetle: here by changing the category.

The editor picks up the fact that | x | is wrapping but fails to highlight…, funny enough if you use [| x |] it only paints half of it.
Screenshot 2023-05-22 at 13.17.14

Also again Nova should autoclose automatically but it does not… :expressionless:
One way you could maybe bypass, could be maybe using the tree-sitter [Autoclose] feature (Tree-sitter - Nova)

In terms of colour situation I managed to find a way to fix but these are all hacky and I wished Nova had a better support for brackets and so fort, considering weird combos are very common across all frameworks

The hack I did was using the tree-sitter highlighter, and grabbing the brackets, here is an example. But for it work you have to uncheck the rainbow bracket… :expressionless:

1 Like

Thank you for the bug reports. We will investigate.