syntax keywords with '[' character

33 views
Skip to first unread message

Ron Aaron

unread,
Sep 3, 2023, 8:33:22 AM9/3/23
to vim_dev
I was just given a bug report for a new version of my syntax file, and  the problem is that a syntax keyword with a lone '[' doesn't work (it causes an error  message  E789)

I have 'syn iskeyword 33-255' (because everything except a space is a valid keyword identifier) but the syntax parser in vim doesn't like it.

I have other keywords with [ but they pair with a ], and my guess is that these are being (improperly) treated as character classes.

How can I get a keyword like SQL[ to be recognized?

Ron Aaron

unread,
Sep 3, 2023, 9:44:39 AM9/3/23
to vim_dev
Hmm. This works:    SQL[[]
However, a keyword like exec[] if I try exec[[]] complains about the trailing ]  

I would have expected syntax keywords to be matched "as is" and not like regexes. 

James McCoy

unread,
Sep 3, 2023, 10:03:22 AM9/3/23
to vim...@googlegroups.com
On Sun, Sep 03, 2023 at 05:33:22AM -0700, Ron Aaron wrote:
> I was just given a bug report for a new version of my syntax file, and  the
> problem is that a syntax keyword with a lone '[' doesn't work (it causes an
> error  message  E789)

See ":help E789":

< *E789* *E890*
When you have a keyword with an optional tail, like Ex commands in
Vim, you can put the optional characters inside [], to define all the
variations at once: >
:syntax keyword vimCommand ab[breviate] n[ext]

So it seems like there needs to be a mechanism to opt out of this
syntax for your case.

Cheers,
--
James
GPG Key: 4096R/91BF BF4D 6956 BD5D F7B7 2D23 DFE6 91AE 331B A3DB

Ron Aaron

unread,
Sep 3, 2023, 10:09:57 AM9/3/23
to vim_dev
Thank you; I didn't know that about the 'optional tail'. So my 'fix' actually means that both SQL and SQL[ will be recognized as keywords, which isn't what's wanted.

The user who pointed out the issue is actually using 'neovim', so it would be great (for me) if a solution which worked with the existing code were possible.

Doug Kearns

unread,
Sep 3, 2023, 2:04:47 PM9/3/23
to vim...@googlegroups.com
G'day Ron,

I don't believe you can.  We ran into the same issue with the Forth syntax file and just use syn-match for words that include '['.

The [...] matches an optional sequence like %[..] in a pattern.  There's actually a help entry for E789.

It could be changed to respect the 'isk' value(s) over the optional sequence but I'm not sure one is better than the other.  It's not inconceivable that the pattern might be heavily used even though '[' is included in 'isk' for a small number of keywords.

Regards,
Doug

Ron Aaron

unread,
Sep 4, 2023, 4:28:44 AM9/4/23
to vim_dev
Thank you, that's where I'm going as well.
Reply all
Reply to author
Forward
0 new messages