Re: GtkSourceView: RegEx issues



I get the same (bad) results even if I write the RegEx in one line, like this:

    <context id="note">
      <match extended="true">
        ^(\[\^)([^\]\s\p{C}]+)(\])\ (\P{C}*(?:\n(?!\n[\[\n])\P{C}*)*)
      </match>

      <include>
        <context sub-pattern="1" class="no-spell-check" style-ref="note-marker"/>
        <context sub-pattern="2" class="no-spell-check" style-ref="note-name"/>
        <context sub-pattern="3" class="no-spell-check" style-ref="note-marker"/>
        <context sub-pattern="4" style-ref="note-body"/>
      </include>
    </context>

However if I try to search for that regular _expression_ using Gedit's "Find and Replace" dialog (Ctrl-h) then it is captured properly. Does Gedit's "Find and Replace" dialog uses different regex engine, not that of GtkSourceView? Or the engine's configuration is different?

Thank you!


On Tue, Aug 31, 2021 at 12:43 AM Sim Tov <smntov gmail com> wrote:
The language definition file in question is here:

https://gitlab.com/pninim.org/dar/dar-syntax/-/blob/master/dar.lang

The problematic line is here:

https://gitlab.com/pninim.org/dar/dar-syntax/-/blob/master/dar.lang#L293

Example syntax file to test the RegEx (see screenshot in the first email):

https://gitlab.com/pninim.org/dar/dar-syntax/-/blob/master/syntax.dar


Thank you!




On Mon, Aug 30, 2021 at 8:18 PM Sim Tov <smntov gmail com> wrote:
Also tried this RegEx:

^(\[\^)([^\]\s\p{C}]+)(\])\ (\P{C}*(?:\n(?!\n[\[\n])\P{C}*)*)

and again here it works:


But inside GtkSourceView it doesn't (i.e. provides the same results as in the picture above):


    <!-- Examples:
        [^note_name] note body

       RegEx: ^(\[\^)([^\]\s\p{C}]+)(\])\ (\P{C}*(?:\n(?!\n[\[\n])\P{C}*)*)
    -->
    <context id="note">
      <match extended="true">
        ^(\[\^)                               # Opening bracket and the caret at line begin.
        ([^\]\s\p{C}]+)                       # note_name.
        (\])                                  # Closing bracket.
        \ (\P{C}*(?:\n(?!\n[\[\n])\P{C}*)*)   # One space and note body; till a new note (i.e. new line + opening bracket) or three new lines or end of string.
      </match>

      <include>
        <context sub-pattern="1" class="no-spell-check" style-ref="note-marker"/>
        <context sub-pattern="2" class="no-spell-check" style-ref="note-name"/>
        <context sub-pattern="3" class="no-spell-check" style-ref="note-marker"/>
        <context sub-pattern="4" style-ref="note-body"/>
      </include>
    </context>


On Mon, Aug 30, 2021 at 6:53 PM Sim Tov <smntov gmail com> wrote:
Hello,

I try to implement in GtkSourceView this (properly working) RegEx:


As you can see there the second footnote [^1] ... spans over several paragraphs and all are captured by the RegEx.

I tried to implement the same RegEx in GtkSourceView as follows ( https://paste.debian.net/1209662/ )  :

    <!-- Examples:
        [^note_name] note body

       RegEx: ^(\[\^)([^\s\p{C}\]]+)(\])\ ([\P{C}\n]*?)(?=\n\[|\n\n\n|\Z)
    -->
    <context id="note">
      <match extended="true">
        ^(\[\^)              # Opening bracket and the caret at line begin.
        ([^\s\p{C}\]]+)      # note_name.
        (\])                 # Closing bracket.
        \ ([\P{C}\n]*?)      # One space and note body.
        (?=\n\[|\n\n\n|\Z)   # Till a new note (i.e. new line + opening bracket) or three new lines or end of string.
      </match>

      <include>
        <context sub-pattern="1" class="no-spell-check" style-ref="note-marker"/>
        <context sub-pattern="2" class="no-spell-check" style-ref="note-name"/>
        <context sub-pattern="3" class="no-spell-check" style-ref="note-marker"/>
        <context sub-pattern="4" style-ref="note-body"/>
      </include>
    </context>

However only the first paragraph of [^1]... is captured and not the rest... Here is how it looks:


Is it a bug in GtkSourceView or me doing something wrong?

Thank you!


Screenshot from 2021-08-30 18-13-22.png





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]