May 24, 2021 Vim
We can even open another book for the grammar highlights in Vim.
We'll cover its final content here, and then move on to something else.
If you want to learn more,
:help syntax
read the syntax files written by others.
Potion, like most programming languages, supports things
"Hello,world!"
T
he literal amount of the string. W
e should highlight these into strings. T
o do this we
syntax region
command.
Add the following to your Potion syntax file:
syntax region potionString start=/\v"/ skip=/\v\\./ end=/\v"/
highlight link potionString String
Close and reopen your factorial.pn
factorial.pn
see the string at the end of the file highlighted!
The last line should be familiar. If you don't understand, reread the first two chapters.
The first line adds a syntax type grouping with a "region". R egions have a "start" mode and an "end" mode to specify the start and end positions. Here, a Potion string starts with one double quote and ends with another double quote.
syntax region
allows us to handle escape strings such as
"She said: \"Vimscript is tricky, but useful\"!"
If you
skip
provide the
"
skip parameter, Vim will
Vimscript
that's not what we want!"
To put it succincically, the
skip
parameter
syntax region
tells Vim: "Once you start matching this area, I want you to ignore
skip
match, even if it will be treated as a sign of the end of the zone."
Take a few minutes to think it through. W
hat if
"foo \\" bar"
bar? W
ould that be the right thing to do? I
s that always the right thing to do?
Put down the book and take a few minutes
to think about it!
Highlight the single quote string with syntax.
Read
:help syn-region
.
Read:
:help syn-region
take more time than reading this chapter.
Pour yourself a drink, you deserve it!