"state-sensitive" syntax highlighing?

11 views
Skip to first unread message

Ron Aaron

unread,
Sep 27, 2019, 12:54:47 AM9/27/19
to vim_dev
AFAICT, the syntax highlighting engine operates solely by means of regex matches. That's fine as far as it goes, but one of my users has implemented a more useful kind of syntax highlighting in "VSCode" for my "8th" language.

Essentially, in 8th (as in most Forths), you can be in either "interpret" or "compile" mode, and some words (functions) are illegal in one or the other modes.  It is very useful to be able to flag such a case in the editor, to alert the programmer of a likely error.

So, for example, the word "if" is illegal in 8th, in 'interpret' mode.

There are a few words which signal that the mode is 'compile' and a few others which turn it off.

Is there a reasonable way to get the vim syntax highlighter to recognize this kind of situation?

Bram Moolenaar

unread,
Sep 27, 2019, 7:32:53 AM9/27/19
to vim...@googlegroups.com, Ron Aaron
Probably the simplest is to recognize all the syntax items, and then
only define highlighting for what you want to see. You could provide a
user command to switch between states.

To still allow for user defined highlighting, you would add or remove
links with "hi link MyLangItem DoHighlight" and "hi link MyLangItem
NONE".

--
You know you use Vim too much when you have this alias in your
~/.bashrc file: alias :e=/bin/vim (Eljay Love-Jensen)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages