I went down the considerable rabbit hole of making a syntax highlighter for ZX BASIC for the Linux/Mac/Windows code editor Sublime Text. It'll highlight regular .bas files too since it's a superset of Sinclair BASIC. It's nice to program for the Speccy on a modern editor at last
https://github.com/patters-syno/zx-basic-syntax
ZX BASIC syntax highlighter
-
- Drutt
- Posts: 5
- Joined: Sat Jan 23, 2021 5:34 pm
Re: ZX BASIC syntax highlighter
Awesome, will use that!
Re: ZX BASIC syntax highlighter
Brilliant.
I can't get it to work though. It's not highlighting anything. I followed the instructions. I've never used sublime before, am.i doing something stupid? Please help
I can't get it to work though. It's not highlighting anything. I followed the instructions. I've never used sublime before, am.i doing something stupid? Please help
Re: ZX BASIC syntax highlighter
I've just gone through the motions and it works for me, even on a completely fresh downloaded copy of Sublime.
Did you definitely put the syntax file inside the User folder, and not one level up?
And can you see ZX BASIC as a choice in the View > Syntax menu?
Did you definitely put the syntax file inside the User folder, and not one level up?
And can you see ZX BASIC as a choice in the View > Syntax menu?
Re: ZX BASIC syntax highlighter
Technically I suppose you need slightly different rules for different models, e.g. on a +3 you can do COPY "..." TO SPECTRUM FORMAT, and on a 48k you can use the buggy MOVE a$,b$ (which I slipped into my CSSCGC entry) but that doesn't work on a +2a or +3. And of course the grey +2 has that weird exclamation-mark RAM-disc syntax, ERASE ! "myfile"
Re: ZX BASIC syntax highlighter
As per the blurb on my GitHub the aim isn't to highlight all BASIC keywords though. Doing that just highlights most of the entire screen full of code in pink or purple which really isn't helpful. The compiler is already good at catching misspellings etc., so the real value this adds is code legibility and clarity. Since I copied the contexts from the built-in language support it offers some really neat stuff like if you hover the mouse over a function name you can jump to where it's defined, or to each mention of it in the code.
GitHub description wrote:ZX BASIC is an updated BASIC dialect which compiles to optimised Z80 machine code for the ZX Spectrum computer. The Sublime Text editor, like the ZX BASIC compiler, runs on Linux, Mac OS, and Windows.
This syntax highlighter does not exhaustively match all BASIC keywords, rather its focus is code clarity. Mariana colour scheme (pictured) is recommended over the default Monokai, since some highlights are invisible in Monokai.
Highlighting Scope:
- Comment lines, comment blocks, inline assembly comments
- Strings including all escaped characters
- To avoid over-colouring, keywords are limited to conditionals and those controlling execution flow
- Sub and Function definitions and calls, although their calls are indistinguishable from array references (and strings without sigils) since the parser does not track objects
- Variable types, numbers, separators, operator symbols, and compiler keywords
Re: ZX BASIC syntax highlighter
After exchanging PMs with [mention]Jbizzel[/mention] he confirmed he's got the syntax highlighter working. I have improved the instructions on the GitHub repo to make it easier to download the raw syntax file.
Last edited by patters on Sun Feb 14, 2021 10:21 pm, edited 1 time in total.
Re: ZX BASIC syntax highlighter
many thanks for your help - This works like a treat. Brilliant work. CGC2021 won't know what hit it lol
Re: ZX BASIC syntax highlighter
Very nifty.
I don't suppose there's a way of supporting other text editors, like Geany?
I don't suppose there's a way of supporting other text editors, like Geany?
Re: ZX BASIC syntax highlighter
Hi
I installed subliemeditor and the 2 sets of highlite
testing on a pure basic file it show the line number in BLUE but only up to 999
from 1000 and above they become orange like the INT values
is it ment to be that all line numbers are blue then you have a small typo/bug some where
i use linux mint21.
btw the INT value after a GO TO is orange aswell, is there a change that an INT after a GO TO or GO SUB is set in blue aswell?
cheers
EDIT:
if have another colour request, I use Fuse with +D emulation. the +D has a problem with printing CHR$ above 127, it wil send the IMAGE VALUE instead as a hex/dec value in the file that FUSE makes with "emulate printer" , next line holds severall UDG's as you can 'see'
in subliem it look like
<0x1b>K<0x08>
and those hex values are printed in darkgrey, which is hard to read using a "darktheme". probably i can find that my self
about those characters above 127, i looked for a PC zx spectrum FONT but few have the correct blockgrafic-images 128 to 143.
if those where include perhaps a different solution is possible, but is supose thats a "subliem" request.
or even for the OS as its about system fonts. an realy adaptable UDG part is probably fantasy
I installed subliemeditor and the 2 sets of highlite
testing on a pure basic file it show the line number in BLUE but only up to 999
from 1000 and above they become orange like the INT values
is it ment to be that all line numbers are blue then you have a small typo/bug some where
i use linux mint21.
btw the INT value after a GO TO is orange aswell, is there a change that an INT after a GO TO or GO SUB is set in blue aswell?
cheers
EDIT:
if have another colour request, I use Fuse with +D emulation. the +D has a problem with printing CHR$ above 127, it wil send the IMAGE VALUE instead as a hex/dec value in the file that FUSE makes with "emulate printer" , next line holds severall UDG's as you can 'see'
the characters CHANGE here inside the forum display, maybe its my linux1500 LET q$="=>?@K\00\00\00\00\00\00\00\00\00K\00\00\00\00\00\00\00\00\00K\00\00\00\00\00\00\00\00\00K\00\00\00\00\00\00\00\00\00K\00\00\00\00\00\00 \C0@K\00\00\00\00\00\00\00\00\00K\00\00\00\00\00\00\00\00\00K\00 \00\00\00\00\00\00\00K\00\00\00\00\00\00\00\00\00K\00\00`auQa=": GO SUB aa: PRINT #n;AT n,VAL "8";q$: GO SUB ui: PRINT #n;AT e,VAL "5";"Radio RefleXed Crystal": GO SUB aa
in subliem it look like
<0x1b>K<0x08>
and those hex values are printed in darkgrey, which is hard to read using a "darktheme". probably i can find that my self
about those characters above 127, i looked for a PC zx spectrum FONT but few have the correct blockgrafic-images 128 to 143.
if those where include perhaps a different solution is possible, but is supose thats a "subliem" request.
or even for the OS as its about system fonts. an realy adaptable UDG part is probably fantasy