icsharpcode / AvalonEdit

The WPF-based text editor component used in SharpDevelop
http://avalonedit.net/
MIT License
1.87k stars 470 forks source link

Regex doesn't work in syntax highlighting #364

Open NotroDev opened 2 years ago

NotroDev commented 2 years ago

Hi. I have this regex: https://regex101.com/r/P3WGak/1 And everywhere it works, but not in syntax highlighting. I have this:

<Span foreground="#FF5555">
    <Begin>(&amp;[clkmno])+</Begin>
    <End>((?&lt;!&quot;)&quot;(?!&quot;))|((?&lt;=&quot;&quot;)&quot;(?!&quot;))</End>
</Span>

And, as you can see: obraz It doesn't work. Why?

siegfriedpammer commented 2 years ago

I don't have the time to look at the regex, but I can tell you how to achieve your goal:

https://github.com/icsharpcode/AvalonEdit/blob/ed6f2b5d66dda9a7fc609de672c55ec0ada06d00/ICSharpCode.AvalonEdit/Highlighting/Resources/VB-Mode.xshd#L24-L30

This matches "" as it's own nested span.

Hope this helps.

NotroDev commented 2 years ago

I don't have the time to look at the regex, but I can tell you how to achieve your goal:

https://github.com/icsharpcode/AvalonEdit/blob/ed6f2b5d66dda9a7fc609de672c55ec0ada06d00/ICSharpCode.AvalonEdit/Highlighting/Resources/VB-Mode.xshd#L24-L30

This matches "" as it's own nested span.

Hope this helps.

Thanks, but I really can't get it to work. Where should I do this? What should I change in "" regex?

siegfriedpammer commented 2 years ago

I am not yet sure what you are trying to achieve... Can you post a screenshot of what the colors and text should look like? Thanks!

NotroDev commented 2 years ago

I am not yet sure what you are trying to achieve... Can you post a screenshot of what the colors and text should look like? Thanks!

Hey, It should be like this obraz

// Maybe I could somehow do "end on LAST quot" regex/something else?

NotroDev commented 2 years ago

// Maybe I could somehow do "end on LAST quot" regex/something else?

Hmm... It was probably a good idea! obraz

siegfriedpammer commented 2 years ago

I will post a working example of what I had in mind in the evening.

siegfriedpammer commented 2 years ago

I am not sure if I understand your use-case correctly, but this is what I would have used:

<?xml version="1.0"?>
<SyntaxDefinition name="Custom Highlighting" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
    <Color name="String" foreground="Blue" />

    <RuleSet>
        <Span color="String">
            <Begin foreground="Red">"</Begin>
            <End foreground="Red">"</End>
            <RuleSet>
                <Span begin="&quot;&quot;" end="" foreground="Orange" />
            </RuleSet>
        </Span>
    </RuleSet>
</SyntaxDefinition>

Example: image

Yes, I am not sure why you want to start the span on (&amp;[clkmno])+

By setting foreground directly on the Begin and End attributes of Span you can customize the color directly.

NotroDev commented 2 years ago

Yes, I am not sure why you want to start the span on (&[clkmno])+

It's the color, &c = \ Yeah, thanks for it, but I think that my regex is a better solution. Thanks for taking your time!

NotroDev commented 2 years ago

Hey. Oh my god, it was 24 days! I returned to my project and I need to reopen this 😢 When I get the idea to get the last quote, I didn't think of one situation: two or more "". It breaks completely in it... obraz

I can't use your solution. E.g. &c is the color code, and in my editor it previews it.