Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Syntax file for BASIC

1 view
Skip to first unread message

Carlo Zanziba

unread,
Nov 17, 2009, 2:26:31 AM11/17/09
to
Hi, using gvim 7.2 for win32.

I'm trying to build a BASIC vim syntax file to use for my own basic
files, but I cannot highlight keywords followed by $ or by #

Can you suggest me how to do it for instance with CHR$ or with WRITE#,
as to have all the FOUR characters of CHR$ and the SIX characters of
WRITE# being colored?

I've tried with syn match ... /CHR\$/
or with syn keyword ... CHR\$

or in many many other ways but gvim doesn't color them. The BASIC syntax
files given with gvim don't offer a solution, since they don't work either.

Thanks in advance.

-- Carlo

M. Soyka

unread,
Nov 17, 2009, 7:29:37 PM11/17/09
to
Carlo,

The main problem is that neither "$" nor "#" is a valid keyword
character. Lookup the 'iskeyword' option.

The second problem is (I think) that "syntax keyword" does not take a
regular expression (I could be wrong).

I think this will satisfy:

:set iskeyword+=#,$
:syntax keyword Function MID$
:syntax keyword Function WRITE#

Mike

Carlo Zanziba

unread,
Nov 18, 2009, 4:16:51 AM11/18/09
to
M. Soyka ha scritto:

You were right in both cases. Thanks a lot.

Now, since you seem to be very competent into the subject (or at least
your instinct does work) can you suggest me how to do the following:

I'd like the following patterns:

FILE#1,...
FILE #1,...
FILE# 1,...
FILE # 1,...

to color both FILE (or whatever statement following the same pattern)
AND #, but NOT the channel number, the comma and the rest.

I tried with

syntax match FileStatement /FILE\s*#\s*/
or
syntax match FileStatement /\a\+\s*#\s*/ (for a more general case)

and tried with and without the escape char in all situations, but it
doesn't seem to work. match does use regexp, doesn't it?

Any suggestion?

Thanks in advance, Mike.

-- Carlo

M. Soyka

unread,
Nov 18, 2009, 8:32:12 PM11/18/09
to
Carlo,

First of all, I'm not familiar with the "FILE" keyword nor is it
included in Vim's syntax file for basic. So I'll assume you mean it as
a generic replacement for "OPEN", "PRINT", "WRITE", and so on.

Given that, let's talk about the "WRITE" keyword. The reason you can't
get "syntax match" to work is because "syntax keyword" operates a higher
priority (see :help syn-priority), that is, "WRITE" is classified as a
keyword first. Once that happens, "WRITE" can no longer be matched.

So, if you remove "WRITE" as a keyword, the following works for me:
:syntax match FileStatement /WRITE\s*#\?/

Mike

0 new messages