[vim/vim] Regular expression no longer matching when used in a syntax command (Issue #14908)

12 views
Skip to first unread message

adrianconstantin-leroy

unread,
Jun 3, 2024, 7:50:14 PM6/3/24
to vim/vim, Subscribed

Steps to reproduce

Open new Vim window and paste this (a pdoc (php) man page header):

ARRAY(3)                                                   1                                                   ARRAY(3)

array - Create an array

SYNOPSIS
       array array ([mixed  $...])

DESCRIPTION
        Creates an array. Read the section on the array type for more information on what an array is.

PARAMETERS
              o $...
                -  Syntax  "index => values", separated by commas, define index and values. index may be of type string

Search for the following pattern, that matches the first non-empty lines in the synopsis header

:set hls
/\v^SYNOPSIS\r?\n\zs.*\ze\r?\n\r?\n

Notice how the first line of the synopsis header gets highlighted.

Now use the same regular expression in a :syntax match command:

:set nohls
:syntax clear
:syntax match pdocSynopsisHeader /\v^SYNOPSIS\r?\n\zs.*\ze\r?\n\r?\n/
:highlight link pdocSynopsisHeader Special

Notice how the syntax does not change, and there is no match for the :syntax match command, despite the same regular expression is used as before.

You can double-check by moving the input cursor to the line in question (line 6) and calling synstack() function:

6G
:echo synstack(line('.'), col('.'))->map( { _, val -> synIDattr(val, "name") })
:syntax list pdocSynopsisHeader

What am I missing ? Some multi-line flag for the regexp ... ?

Expected behaviour

The regexp should match the same way in when used for a search (with / ) or when used in the :syntax command.
Or otherwise any differences should be documented as such.

Version of Vim

9.1 (patches 1-445)

Environment

Windows 10 GUI (gvim.exe)

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14908@github.com>

Christian Brabandt

unread,
Jun 4, 2024, 2:50:53 AM6/4/24
to vim/vim, Subscribed

This seems more like a usage question and not necessarily a bug (at least not yet).

I see several issues here:

  • first of all, your use of \r?\n is not required, you can always use \n to match a linebreak, independently of what the fileformat option is set.
  • I seem to remember some issues with \zs and zero-width matches for syntax matches (not sure if this is documented). The following change works however: syn match Special /\(^SYNOPSIS\n\)\@<=.*$/. I think the difference is where the syntax engine is trying to start the match.
  • finally, I think using multi-line patterns as a :syn-match is not necessarily best-practice for syntax scripts. Better it is to define a region start and end patterns and then explicitly try to match within that region. So try this one instead (which is also more simpler to read:
syn region SYNOPSIS start="^SYNOPSIS" end="^$" contains=phpDescription
syn match phpDescription /^\s\+.*$/ contained
hi def link phpDescription Special


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/14908/2146741422@github.com>

Christian Brabandt

unread,
Jun 4, 2024, 2:50:59 AM6/4/24
to vim/vim, Subscribed

@chrisbra converted this issue into discussion #14909.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/14908/issue_event/13030994573@github.com>

Reply all
Reply to author
Forward
0 new messages