Syntax colours

Here you can talk about anything related to BBC BASIC, not covered in another category
svein
Posts: 26
Joined: Tue 03 Apr 2018, 19:34

Syntax colours

Post by svein » Wed 11 Apr 2018, 17:05

I noticed a lack of syntax colours here, so i wrote a colorizer for the wiki pages.
The wiki is almost finished, just need to double check the result.
Maybe i should have asked if you want this first, do you ?
No hard feelings if not.

Svein

guest
Posts: 268
Joined: Mon 02 Apr 2018, 09:12

Re: Syntax colours

Post by guest » Wed 11 Apr 2018, 19:04

svein wrote:
Wed 11 Apr 2018, 17:05
I noticed a lack of syntax colours here, so i wrote a colorizer for the wiki pages.
In that case there's been a duplication of effort, because I'm doing the same! I've also emailed Jon to see if he would release his version (which of course is tried and tested). So that's potentially three different versions. :o

I would be interested to know how you've been testing yours. I am having trouble persuading GeSHi to flush its language cache, and as a result I have to change the name of my language file every time I make a change; not very convenient! Have you discovered a way to force it to re-parse the file after it has been changed?

I'd be interested in comparing yours with mine, but I'm reasonably happy with the progress I am making. Does yours do everything Jon's does?

Richard.

svein
Posts: 26
Joined: Tue 03 Apr 2018, 19:34

Re: Syntax colours

Post by svein » Wed 11 Apr 2018, 21:09

My program is written in BB4W.
Just completed browsing thru the 393 pages !
A few minor errors corrected.
I'll send you the result in a ZIP file.
Some of the folders are empty because of different html or no code found :
manual, tools_and_utilities, tutorials.

Svein

guest
Posts: 268
Joined: Mon 02 Apr 2018, 09:12

Re: Syntax colours

Post by guest » Wed 11 Apr 2018, 21:34

svein wrote:
Wed 11 Apr 2018, 21:09
My program is written in BB4W.
I'm not sure that I understand. The new wiki uses GeSHi for syntax highlighting, as did the old one. GeSHi language files are written in a subset of PHP; I don't think there is any way that BB4W could be used (not least because it can't easily be made to run on the server). This is what I've got so far, I'm sure it can be improved:

Code: Select all

<?php
/*************************************************************************************
 * bb4w.php
 * ----------
 * Author: Richard Russell (info@rtrussell.co.uk)
 * Copyright: (c) 2018  R.T.Russell (http://www.rtrussell.co.uk)
 * Release Version: 1.0.0.5
 * Date Started: 2018-04-13
 *
 * BBC BASIC language file for GeSHi.
 *
 * CHANGES
 * -------
 * Added a few common 'compound keywords' so they are highlighted correctly.
 * Corrected line number highlighting.
 *
 *************************************************************************************
 *
 *     This file is part of GeSHi.
 *
 *   GeSHi is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   GeSHi is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with GeSHi; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 ************************************************************************************/

$language_data = array (
    'LANG_NAME' => 'BBC BASIC',
    'COMMENT_SINGLE' => array(1 => 'REM', 2 => '*|'),
    'COMMENT_MULTI' => array(),
    'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
    'QUOTEMARKS' => array('"'),
    'ESCAPE_CHAR' => '',
    'KEYWORDS' => array(
// Keywords that must be followed by whitespace or a delimiter:
        1 => array('1dummy'),
        2 => array('2dummy'),
        3 => array('3dummy'),
        4 => array('ASCMID$','VALMID$',
            'BGET','BPUT','BY','CLEAR','CLG','CLOSE','CLS','COUNT',
            'END','ENDCASE','ENDIF','ENDPROC','ENDWHILE','EOF','ERL','ERR','EXIT',
            'EXT','FALSE','HIMEM','LEFT$','LOMEM','MID$','OFF','OF','PAGE','PI',
            'POINT','POS','PTR','QUIT','REPORT','RETURN','RIGHT$','RND','RUN',
            'STOP','STRING$','TAB','TIME','TRUE','VPOS','WAIT')
        ),
    'SYMBOLS' => array(
        ),
    'CASE_SENSITIVE' => array(
            GESHI_COMMENTS => false,
            1 => true,
            2 => true,
            3 => true,
            4 => true
            ),
    'STYLES' => array(
        'KEYWORDS' => array(
            1 => 'color: #ff8000;',
            2 => 'color: #ff8000;',
            3 => 'color: #ff8000;',
            4 => 'color: #ff8000;'
            ),
        'COMMENTS' => array(
            1 => 'color: #008000;',
            2 => 'color: #008000;'
            ),
        'BRACKETS' => array(
            0 => 'color: #000000;'
            ),
        'STRINGS' => array(
            0 => 'color: #ff00ff;'
            ),
        'NUMBERS' => array(
            0 => 'color: #000000;'
            ),
        'METHODS' => array(
            ),
        'SYMBOLS' => array(
            0 => 'color: #000000;'
            ),
        'ESCAPE_CHAR' => array(
            0 => 'color: #000000;'
            ),
        'SCRIPT' => array(
            ),
        'REGEXPS' => array(
            1 => 'color: #0000ff;',
            2 => 'color: #ff8000;',
            3 => 'color: #ff0000;'
            )
        ),
    'URLS' => array(
        1 => '',
        2 => '',
        3 => '',
        4 => ''
        ),
    'OOLANG' => false,
    'OBJECT_SPLITTERS' => array(
        ),
    'REGEXPS' => array(
// Line numbers:
        1 => array(
            GESHI_SEARCH => '(^ *|\n *)([0-9]+)',
            GESHI_REPLACE => '\\2',
            GESHI_MODIFIERS => '',
            GESHI_BEFORE => '\\1',
            GESHI_AFTER => ''
            ),
// Keywords that need not be followed by whitespace or a delimiter:
        2 => array(
            GESHI_SEARCH => "(\b)(COSRAD|SINRAD|TANRAD|DEGACS|DEGASN|DEGATN|"
                            ."ABS|ACS|ADVAL|AND|ASC|ASN|ATN|CALL|CASE|CHAIN|"
                            ."CHR[$]|CIRCLE|COLOR|COLOUR|COS|DATA|DEG|DIM|DIV|DRAW|"
                            ."ELLIPSE|ELSE|ENVELOPE|EOR|ERROR|EVAL|EXP|FILL|FN|FOR|"
                            ."GCOL|GET[$]|GET|GOSUB|GOTO|IF|INKEY[$]|INKEY|INPUT|"
                            ."INSTALL|INSTR|INT|LEN|LET|LINE|LN|LOCAL|LOG|"
                            ."MODE|MOD|MOUSE|MOVE|NEXT|NOT|ON|OPENIN|OPENOUT|"
                            ."OPENUP|ORIGIN|OR|OSCLI|OTHERWISE|PLOT|PRINT|"
                            ."PRIVATE|PROC|RAD|READ|RECTANGLE|REPEAT|RESTORE|"
                            ."SGN|SIN|SOUND|SPC|SQR|STEP|STR[$]|SUM|SWAP|SYS|"
                            ."TAN|THEN|TINT|TO|TRACE|UNTIL|USR|"
                            ."VAL|VDU|WHEN|WHILE|WIDTH)",
            GESHI_REPLACE => '\\2',
            GESHI_MODIFIERS => '',
            GESHI_BEFORE => '\\1',
            GESHI_AFTER => ''
            ),
        3 => array(
            GESHI_SEARCH => "(\b)(DEFFN|DEFPROC|DEF)",
            GESHI_REPLACE => '\\2',
            GESHI_MODIFIERS => '',
            GESHI_BEFORE => '\\1',
            GESHI_AFTER => ''
            )
        ),
    'PARSER_CONTROL' => array(
        'ENABLE_FLAGS' => array(
            'SCRIPT' => GESHI_NEVER,
            'SYMBOLS' => GESHI_NEVER,
            'NUMBERS' => GESHI_NEVER,
            'ESCAPE_CHAR' => GESHI_NEVER,
            'BRACKETS' => GESHI_NEVER,
            )
        ),
    'STRICT_MODE_APPLIES' => GESHI_NEVER,
    'SCRIPT_DELIMITERS' => array(
        ),
    'HIGHLIGHT_STRICT_BLOCK' => array(
        )
);

?>
Richard.

svein
Posts: 26
Joined: Tue 03 Apr 2018, 19:34

Re: Syntax colours

Post by svein » Wed 11 Apr 2018, 22:18

<I'm just wondering, do you perhaps misunderstand how wikis work?>

Absolutely, did not know, have only used standard html stuff.

Was an interesting project though.

Svein

guest
Posts: 268
Joined: Mon 02 Apr 2018, 09:12

Re: Syntax colours

Post by guest » Wed 11 Apr 2018, 22:29

svein wrote:
Wed 11 Apr 2018, 21:57
The idea was that maybe it is possible to simply replace the source files (wiki,manual), and that doku.php would happily output it.
A wiki is a user-contributed, user-editable, resource, where anybody can submit new pages or edit existing ones. There are no HTML files stored on the server: the HTML code that is sent to your browser is generated 'on the fly' from the Wiktext pages that have been entered or edited by visitors.

Most wikis support Syntax Highlighting, and the DokuWiki software that I am using is no exception. It uses the popular GeSHi (Generic Syntax Highlighter) engine - as indeed did our old Wikispaces wiki - and comes with support for a large number of languages. For example pages containing Liberty BASIC code can be automatically highlighted like this one. But unfortunately BBC BASIC is not one of those, so to provide support it is necessary to write a GeSHi 'language file' (effectively a plugin) which is what I have been doing.

I might as well list the code.
Thanks, but I'm unclear how you were hoping it could be used. I wrote, and published, a BBC BASIC to HTML converter program many years ago. It is what was used to create the coloured listings at the examples section of the website.

Richard.

guest
Posts: 268
Joined: Mon 02 Apr 2018, 09:12

Re: Syntax colours

Post by guest » Thu 12 Apr 2018, 16:05

I've got stuck with the syntax colouring at the moment. I've created a GeSHi language file according to my understanding of the syntax (see earlier post), but whilst it works (sort of) the wiki is highlighting one more character than it should. So for example what should appear as:

PROCsendmail

is instead appearing as:

PROCsendmail

which is rather annoying! The syntax colouring at the old wiki (also GeSHi) didn't have this characteristic so either Jon Ripley found a workaround, I am doing something wrong, or the version of GeSHi is different. It's difficult to know which of these it is. :(

If anybody has a clue what I can do about this I would be very interested.

Richard.

svein
Posts: 26
Joined: Tue 03 Apr 2018, 19:34

Re: Syntax colours

Post by svein » Thu 12 Apr 2018, 18:32

Thanks, but I'm unclear how you were hoping it could be used.
In short, given that i thought that pages already written was stored in a normal html format.

1. Write a colorizer in basic.
2. Use the basic program to insert the colour information into the existing pages.
3. Translate the working basic code into php script. (not GeHSi but regular php)
4. Experiment further with the php script for the rest of the forum. (somehow)

More or less, my thoughts.
Don't think i can be of any help with GeHSi, sorry.

Svein

guest
Posts: 268
Joined: Mon 02 Apr 2018, 09:12

Re: Syntax colours

Post by guest » Fri 13 Apr 2018, 12:06

I'm pleased to report that I seem to have got the wiki Syntax Highlighting working, at least to an acceptable extent. To use it, enclose your wiki code listing(s) in <code> tags with the language name specified as bb4w, as follows:

<code bb4w>
      REM Your BASIC code goes here
</code>

(note that the wiki uses angle brackets for the code tags, unlike the forum which uses square brackets).

As was the case at the old Wikispaces wiki, the highlighting cannot catch all the nuances of BBC BASIC's syntax but that is not likely to be important so long as your code is not too 'compressed' (for example running keywords together is likely to result in incorrect highlighting, but you should not be doing that in code intended for the wiki). It is, of course, essential to use CAPITAL keywords!

It would obviously be highly desirable for the existing articles at the wiki - and there are a lot of them! - to be edited to take advantage of the syntax highlighting. This is too big a task for one person; I have edited the articles in the Assembler section but that's all. Could I ask for volunteers to take on this task please? Choose an article, view it to see if it has already been adapted and if not make the necessary changes yourself. Please be careful to use the Preview facility to make sure it displays correctly before saving it.

Richard.

Kjell
Posts: 6
Joined: Fri 13 Apr 2018, 11:58

Re: Syntax colours

Post by Kjell » Fri 13 Apr 2018, 12:26

Thanks, but I'm unclear how you were hoping it could be used. I wrote, and published, a BBC BASIC to HTML converter program many years ago. It is what was used to create the coloured listings at the examples section of the website.
Looking at one line from example

Code: Select all

SYS "GetWindowLong", @hwnd%, GWL_STYLE TO ws%
"GetWindowLong" is highlighted as String
SYS and TO are highlighted as Keywords
Then no more highlighting (?)

Maybe one of the existing highlighters will also work on BB4W as they will all highlight
1. Numbers
2. Strings
3. Some delimiters

Using Perl highlighting (UltraEdit editor) on this snippet worked fine

Code: Select all

  670 def procCopyToClipboard(text$)
  680 
  690 sys "GlobalAlloc", &2000, len(text$)+1 to hdata%
  700 sys "GlobalLock", hdata% to tmp%
  710 $$tmp% 1:text$
  720 sys "GlobalUnlock", hdata%
  730 sys "OpenClipboard", @hwnd%
  740 sys "EmptyClipboard"
  750 sys "SetClipboardData", 1, hdata%
  760 sys "CloseClipboard"
  770 endproc

Post Reply