Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlighting categories #21

Open
hackerb9 opened this issue Oct 26, 2022 · 6 comments
Open

Syntax highlighting categories #21

hackerb9 opened this issue Oct 26, 2022 · 6 comments

Comments

@hackerb9
Copy link
Contributor

hackerb9 commented Oct 26, 2022

What are the conventions for syntax highlighting of BASIC code? While working on issue #20 (derived modes), I have run into a problem that I do not know the meaning of groupings like basic-builtin-regexp and basic-keyword-regexp.

If there is a "typical" convention, it would be helpful to have it in the comments in basic-mode.el. If there is not, and I suspect there isn't yet, it may be good to see what others have done and look at what makes sense.


Note that not all of the categories are confusing. Comments, constants, strings, and so on are self-explanatory. The ones that I'd like to get nailed down are:

  • functions: this one seems to be for the keywords (like SIN()) which return a value. The definition of it makes sense, but there is some question about whether things like PEEK() and TIME$ belong. And is this distinction even helpful to a programmer?
  • keywords: currently appears to be the bones which lay the structure of a BASIC program. Includes control-flow and function/subroutine definitions. There are few confusing entries, though, like AS and RANDOMIZE. And wouldn't it make more sense for data type declarations like DEFINT to be highlighted as a type?
  • builtins: appears to be the meat: all the other statements which do something. PRINT, PEEK, POKE, etc. But there are several counter examples to that idea. DATA and LET seem to be more structural. AND, MOD, NOT, OR, and XOR are operators and I would have expected them to be highlighted differently.
@hackerb9
Copy link
Contributor Author

hackerb9 commented Oct 26, 2022

Possibly of use: I see that the QuickBasic manual breaks its statements into the following groups:

  • Control-Flow Statements
  • Statements Used in BASIC Procedures
  • Standard I/O Statements
  • File I/O Statements
  • String-Processing Statements and Functions
  • Graphics Statements and Functions
  • Trapping Statements and Functions

I do not know if these categories overlap or if they have any relationship to what is actually used in syntax highlighting systems. I will say that I think it is a very good feature that basic-mode makes control-flow distinct.


Update: after reading through that chapter, I think it actually contains some very useful divisions for syntax highlighting and it is not too different from how basic-mode currently works. In particular, Control-Flow (GOTO, IF...THEN, FOR..NEXT) is fundamental to BASIC programmers and is already prominently shown.

Less common, but perhaps even more important to shine a spotlight on are the Trapping Statements (ON ERR GOTO...) which can change a program's flow of control asynchronously. (For example, ON COM GOSUB is used on the Tandy 200 to run a BASIC routine when data comes in on the serial port.) Currently traps are shown the same as control-flow in basic-mode, but I suggest that they ought to be even more vivid.

Statements Used in Procedures (SUB, FUNCTION, DEF FN) are also currently shown in the same face as Control-Flow, but if there are any spare font-lock categories left, it may look better if they were subtly different.

I do not have problem with mushing together Standard I/O and File I/O and Graphics Statements, but I'm not opposed to keeping them separate as the QuickBasic manual has them either. String-Processing Functions do make some sense to show with a slight variation from normal statements, but I do not know if it is worth going out of the way to do.

@hackerb9
Copy link
Contributor Author

hackerb9 commented Oct 26, 2022

Samples of other syntax highlighting for BASIC:

Github GFM

Github's MarkDown attempts to syntax highlight fenced code blocks. For example:

```BASIC
0 DEFINT X=32768, Y=RND(-1)  ' SALT
10 PRINT "HELLO, WORLD! "; TIME$; 
20 Y=(31*Y+PEEK(X)) MOD 257: REM PRIME HASH
30 X=X+1: GOSUB 10
```

Becomes,

0 DEFINT X=32768, Y=RND(-1)  ' SALT
10 PRINT "HELLO, WORLD! "; TIME$; 
20 Y=(31*Y+PEEK(X)) MOD 257: REM PRIME HASH
30 X=X+1: GOSUB 10

Telnet23's language-basic

Github actually relies on telnet23's language-basic syntax highlighting. Like basic-mode.el, it properly marks control-flow as being important. Unfortunately, the way Github has used it, control-flow and operators are both shown in red, so in practice, control-flow is not distinct.

One feature it has that basic-mode.el should steal acquire is highlighting line numbers when they are referenced by statements like GOTO 10 in the line number color.

The main categories appear to be BASIC's typical functions, statements, and operators, but interestingly, it separates string functions from other functions. I suppose the reasoning is that it shows the type the function is returning. Is that an idea that would be helpful to programmers?

The regexps are succinctly defined in .CSON format:

Click to see the regexps
scopeName: 'source.basic'
name: 'BASIC'
fileTypes: [ 'bas' ]
patterns: [
  {
    # line number definition
    match: '^\\s*\\d+'
    name: 'entity.name.tag.basic'
  }
  {
    # line number reference
    match: '\\b((?i)THEN|ELSE|GO\\s*TO|GOSUB)\\s*(\\d+)'
    captures:
      1: name: 'keyword.control.basic'
      2: name: 'entity.name.tag.basic'
  }
  {
    # number
    match: '\\b(?:\\d\\.|\\d+\\.\\d+|\\.\\d+|\\d+)(?:[Ee][-+]?\\d+)?\\b'
    name: 'constant.numeric.basic'
  }
  {
    # string
    match: '"[^"]*"'
    name: 'string.quoted.double.basic'
  }
  {
    # comment
    match: '(?i:REM.*)'
    name: 'comment.line.basic'
  }
  {
    # flow control statement
    match: '\\b(?i:FOR|TO|NEXT|IF|THEN|ELSE|GO\\s*TO|GOSUB|RETURN)\\b'
    name: 'keyword.control.basic'
  }
  {
    # other statement
    match: '\\b(?i:\\?|\\&|\\!|\'|ABSOLUTE|ACCESS|AS|BASE|BEEP|BLOAD|BSAVE|CALL|CASE|CHAIN|CHDIR|CIRCLE|CLEAR|CLOSE|CLS|COLOR|COM|COMMON|CONST|DATA|DECLARE|DEF|DEFDBL|DEFINT|DEFLNG|DEFSNG|DEFSTR|DIM|DO|DRAW|END|ENVIRON|ERASE|ERROR|EXIT|FIELD|FILES|FUNCTION|GET|HOME|IF|INPUT|INPUT#|IOCTL|KEY|KILL|LET|LINE|LOCATE|LOCK|LOOP|LPRINT|LSET|MKDIR|NAME|NEW|ON|OPEN|OPTION|OUT|PAINT|PALETTE|PCLEAR0|PCLEAR1|PCOPY|PEN|PLAY|PMAP|PMODE0|POKE|PRESET|PRINT|PRINT#|PSET|PUT|RANDOMIZE|READ|REDIM|REM|RESET|RESTORE|RESUME|RMDIR|RSET|RUN|SCREEN|SEEK|SELECT|SHARED|SHELL|SLEEP|SOUND|SOUNDRND|STATIC|STOP|STRIG|SUB|SWAP|SYSTEM|TIMER|TROFF|TRON|TYPE|UNLOCK|USING|VIEW|WAIT|WEND|WHILE|WINDOW|WRITE)\\b'
    name: 'entity.name.type.basic'
  }
  {
    # string function
    match: '\\b(?i:BIN|CHR|COMMAND|DATE|ENVIRON|ERDEV|HEX|INKEY|INPUT|IOCTL|LAFT|LCASES|LEFT|LTRIM|MID|MKD|MKDMBF|MKI|MKL|MKS|MKSMBF|OCT|RIGHT|RTRIM|SPACE|SPC|STR|STRING|TAB|TIME|UCASE|UPS|VARPTR)\\$'
    name: 'entity.name.function.basic'
  }
  {
    # non-string function
    match: '\\b(?i:ABS|ASC|ATN|BRK|CDBL|CINT|CLNG|COS|CSNG|CSRLIN|CTL|CVD|CVDMBF|CVI|CVL|CVS|CVSMBF|D2R|EOF|ERDEV|ERL|ERR|EXP|FILEATTR|FIX|FRE|FREEFILE|HEIGHT|INP|INSTR|INT|ITM|LBOUND|LEN|LG|LIN|LN|LOC|LOF|LOG|LOG10|LPOS|NINT|NUM|PEEK|PEN|POINT|POS|R2D|REC|RND|SADD|SCREEN|SEEK|SETMEM|SGN|SIN|SPA|SPC|SQR|SQRT|STICK|STRIG|SYS|TAB|TAN|TIM|TIMER|TYP|UBOUND|VAL|VALPTR|VALSEG|VARPTR|VARSEG|WIDTH)\\b'
    name: 'entity.name.function.basic'
  }
#  {
#    # other function
#    match: '\\b(\\w+[\\$%!]?)\\('
#    captures:
#      1: name: 'entity.name.function.basic'
#  }
  {
    # operator
    match: '\\^|\\+|-|\\*\\*|\\*|/|=|<>|<=|=<|>=|=>|<|>|\\b(?i:MOD|NOT|AND|OR)\\b'
    name: 'keyword.operator.basic'
  }
]

KATE editor

@hackerb9
Copy link
Contributor Author

hackerb9 commented Oct 26, 2022

Just for reference, here are the categories into which Bill Crider's “BASIC Programming Conversion” puts the reserved words from several dialects of BASIC. Actually, "tags" would be a better description, as each word can fit in multiple boxes.

  1. INPUT
    1. Human: Keyboard, Joystick, Paddle, Light Pen
      1. CMD
      2. GET
      3. GET#
      4. IN#
      5. INKEY$
      6. INPUT
      7. INPUT LINE
      8. INPUT#
      9. INPUT$
      10. JOYSTK
      11. KEY
      12. KEY$
      13. LINE INPUT
      14. LINE INPUT#
      15. PDL
      16. PEEK
      17. PEN
      18. POKE (for input?)
      19. PR#
      20. READ
      21. READ#
      22. STICK
      23. STRIG
    2. Storage: Cassette, Sequential/Random file access, Disk
      1. APPEND
      2. AUDIO
      3. B-A:
      4. B-F:
      5. B-P:
      6. B-R:
      7. B-W:
      8. BACKUP
      9. BLOAD
      10. BLOCK-ALLOCATE:
      11. BLOCK-EXECUTE:
      12. BLOCK-FREE:
      13. BLOCK-READ:
      14. BLOCK-WRITE:
      15. BSAVE
      16. BUFFER-POINTER
      17. CATALOG
      18. CHAIN
      19. CHDIR
      20. CLOAD
      21. CLOADM
      22. CLOSE
      23. CMD
      24. COPY
      25. CSAVE
      26. CSAVEM
      27. DCLOSE
      28. DELETE
      29. DIR
      30. DIRECTORY
      31. DLOAD
      32. DLOADM
      33. DOPEN
      34. DRIVE
      35. DSAVE
      36. DSKI$
      37. DSKINI
      38. DSKO$
      39. EOF
      40. ERASE
      41. FIELD
      42. FILE
      43. FILES
      44. FORMAT
      45. FRE
      46. FREE
      47. GET
      48. GET#
      49. IN#
      50. INP
      51. INPUT
      52. INPUT #
      53. INPUT$
      54. KILL
      55. LINE INPUT
      56. LINE INPUT#
      57. LOAD
      58. LOADM
      59. LOF
      60. LPOS
      61. M-E:
      62. M-R:
      63. M-W:
      64. MEMORY-EXECUTE:
      65. MEMORY-READ:
      66. MEMORY-WRITE:
      67. MERGE
      68. MKDIR
      69. MOTOR
      70. NAME
      71. NEW
      72. OPEN
      73. OUT
      74. OUTPUT
      75. POINTER
      76. PR #
      77. PRINT
      78. PRINT #
      79. PRINT #USING
      80. PRINT USING
      81. PUT
      82. PUT#
      83. READ
      84. READ#
      85. RECALL
      86. RECORD
      87. RESTORE
      88. RMDIR
      89. RUN
      90. SAVE
      91. SAVEM
      92. SCRATCH
      93. SHLOAD
      94. SKIPF
      95. ST
      96. STATUS
      97. STORE
      98. UNLOAD
      99. WRITE
      100. WRITE#
    3. External Input: Display, Serial/Modem, Printer, A/D Converter
      1. COM
      2. CMD
      3. CSRLIN
      4. IN#
      5. IN
      6. INP
      7. LPOS
      8. PEEK
      9. POINT
      10. POSN
      11. PPOINT
      12. ST
      13. STATUS
      14. WAIT
      15. SCREEN
  2. PROCESSING
    1. Program Flow
      1. AUTO
      2. BUFFER-POINTER
      3. CHAIN
      4. CHDIR
      5. CMD
      6. DATA
      7. DELETE
      8. ELSE
      9. END
      10. ERASE
      11. ERL
      12. ERR
      13. ERROR
      14. ERRS$
      15. FOR
      16. GOSUB
      17. GOTO
      18. IF
      19. IF-THEN
      20. IF-THEN-ELSE
      21. KILL
      22. LIST
      23. LLIST
      24. M-E
      25. ON ERR
      26. POINTER
      27. REM
      28. REN
      29. RENAME
      30. RENUM
      31. RENUMBER
      32. RESTORE
      33. RESUME
      34. MEMORY-EXECUTE
      35. RESUME NEXT
      36. RETURN
      37. RMDIR
      38. MKDIR
      39. NEXT
      40. NOTRACE
      41. ON ERR GOTO
      42. ON ERROR GOTO
      43. RUN
      44. SCRATCH
      45. SHELL
      46. SKIPF
      47. SPEED=
      48. STOP
      49. THEN
      50. TO
      51. TRACE OFF
      52. TRACE ON
      53. TRACE
      54. TROFF
      55. TRON
      56. WAIT
      57. WEND
      58. WHILE
    2. Functions
      1. ABS
      2. ASC
      3. ATN
      4. CDBL
      5. CHR$
      6. CINT
      7. COS
      8. CSRLIN
      9. CVD
      10. CVI
      11. CVN
      12. CVS
      13. EOF
      14. ERL
      15. ERR
      16. ERRS$
      17. EXP
      18. FIX
      19. FRE
      20. HEXS
      21. INKEY$
      22. INP
      23. INPUT$
      24. JOYSTK
      25. LEFT$
      26. LOC
      27. LOF
      28. LOG
      29. LPOS
      30. M-R:
      31. MEM
      32. MEMORY-READ:
      33. MID$
      34. MKD$
      35. MKI$
      36. MKN$
      37. MKS$
      38. OCT$
      39. PDL
      40. PEEK
      41. PEN
      42. POINT
      43. POS
      44. PPOINT
      45. RIGHT$
      46. RND
      47. ROW
      48. SCREEN
      49. SGN
      50. SQR
      51. STRIG
      52. TIME$
      53. SIN
      54. SPACE$
      55. STATUS
      56. STICK
      57. STRING$
      58. TANVAL
      59. VARPTR
      60. SPC(
      61. STR$
      62. TI$
      63. VARPTR$
    3. Operators
      1. ^ Exponentiation
      2. - Negation
      3. * Multiplication
      4. / Floating-Point Division
      5. \ Integer Division
      6. MOD Modulo Arithmetic
      7. + Addition
      8. - Subtraction
      9. = Equality
      10. < Less Than
      11. > Greater Than
      12. NOT
      13. AND
      14. OR
      15. XOR
      16. EQV
      17. IMP
    4. Data Types: Constants, Variables, Strings, Numerics, Arrays
      1. CDBL
      2. CHR$
      3. CINT
      4. COMMON
      5. CONCAT
      6. CSNG
      7. CVD
      8. CVI
      9. CVN
      10. CVS
      11. DATA
      12. DEFDBL
      13. DEFFN
      14. DEFINT
      15. DEFSNG
      16. DEFSTR
      17. DIM
      18. FIX
      19. HEX$
      20. INT
      21. LET
      22. MKD$
      23. MKI$
      24. MKN$
      25. MKS$
      26. OCT$
      27. OPTION BASE
      28. STR$
      29. STRING$
      30. SWAP
      31. VAL
      32. VARPTR
      33. VARPTR$
    5. Machine & Memory Interface
      1. B-A:
      2. B-F:
      3. B-P:
      4. B-R:
      5. B-W:
      6. BLOAD
      7. BLOCK-ALLOCATE:
      8. BLOCK-EXECUTE:
      9. BLOCK-FREE:
      10. BLOCK-READ:
      11. BLOCK-WRITE:
      12. BSAVE
      13. BUFFER-POINTER:
      14. CALL
      15. DEF SEG
      16. FRE
      17. HIMEM:
      18. INP
      19. LOADM
      20. LOMEM:
      21. M-E:
      22. M-R:
      23. M-W:
      24. MEM
      25. MEMORY-EXECUTE:
      26. MEMORY-READ:
      27. MEMORY-WRITE:
      28. OUT
      29. PCLEAR
      30. PCLS
      31. PCOPY
      32. PEEK
      33. PMODE
      34. POKE
      35. POP
      36. PR #
      37. SAVEM
      38. SHLOAD
      39. SPEED=
      40. STATUS
      41. SYS
      42. SYSTEM
      43. UNLOAD
      44. USER
      45. USR
      46. VARPTR
      47. VARPTR$
  3. OUTPUT
    1. Display output
      1. CIRCLE
      2. CLS
      3. CMD
      4. COLOR
      5. COLOR=
      6. CSRLIN
      7. DRAW
      8. DRAWTO
      9. FLASH
      10. GET
      11. GR
      12. HCOLOR
      13. HCOLOR=
      14. HGR
      15. HGR2
      16. HLIN
      17. HLIN-AT
      18. HPLOT
      19. HTAB
      20. INVERSE
      21. KEY
      22. LINE
      23. LOCATE
      24. NORMAL
      25. PAGE
      26. PAINT
      27. PALETTE
      28. PALETTE USING
      29. PCLEAR
      30. PCLS
      31. PCOPY
      32. PEEK
      33. PEN
      34. PLOT
      35. PMAP
      36. PMODE
      37. POINT
      38. POINTER
      39. POKE
      40. PPOINT
      41. PR #
      42. PRESET
      43. PRINT
      44. PRINT #
      45. PRINT #USING
      46. PRINT @
      47. PRINT AT
      48. PRINT USING
      49. PSET
      50. PUT
      51. RESET
      52. ROT=
      53. SCALE
      54. SCALE=
      55. SCREEN
      56. SCRN(
      57. SET
      58. SHLOAD
      59. VIEW
      60. VLIN
      61. VLIN-AT
      62. VPOS
      63. VTAB
      64. WIDTH
      65. WINDOW
      66. WRITE
      67. WRITE #
      68. XDRAW
      69. XPLOT
    2. Sound
      1. AUDIO
      2. BEEP
      3. MOTOR
      4. NOISE
      5. PEEK
      6. PLAY
      7. POKE
      8. SOUND
    3. Printer
      1. CMD
      2. LLIST
      3. LPOS
      4. LPRINT
      5. LPRINT USING
      6. POSN
      7. PR #
      8. PRINT
      9. PRINT @
      10. PRINT #
      11. PRINT #USING
      12. PRINT USING
      13. ST
      14. STATUS
      15. TAB
      16. TAB(
      17. WRITE
      18. WRITE#
    4. Storage output
      1. APPEND
      2. B-A:
      3. B-F:
      4. B-P:
      5. B-R:
      6. B-W:
      7. BACKUP
      8. BLOCK-READ:
      9. BLOCK-WRITE:
      10. BLOCK-ALLOCATE:
      11. BLOCK-EXECUTE:
      12. BLOCK-FREE:
      13. BUFFER-POINTER
      14. BSAVE
      15. CATALOG
      16. CHDIR
      17. CLOSE
      18. DSKI$
      19. DSKO$
      20. PRINT USING
      21. PUT
      22. CMD
      23. COLLECT
      24. COPY
      25. CSAVE
      26. CSAVEM
      27. DCLOSE
      28. DELETE
      29. DIR
      30. DIRECTORY
      31. DOPEN
      32. DRIVE
      33. DSAVE
      34. DSKINI
      35. ERASE
      36. FIELD
      37. FILES
      38. KILL
      39. LOF
      40. MKDIR
      41. MOTOR
      42. OPEN
      43. OUTPUT
      44. PR #
      45. PRINT
      46. PUT #
      47. PRINT #
      48. PRINT #USING
      49. RENAME
      50. RMDIR
      51. SAVE
      52. SAVEM
      53. SCRATCH
      54. SYSTEM
      55. TAB
      56. TAB(
      57. STORE
      58. UNLOAD
      59. WRITE
      60. WRITE#
    5. External Communications
      1. AUDIO
      2. CMD
      3. COM
      4. MOTOR
      5. OFF
      6. ON
      7. OUT
      8. PEEK
      9. POKE
      10. PR #
      11. WAIT

Crider says that he is covering BASIC for "Apple, IBM PC, IBM PCjr, Commodore 64, TRS-80 Model III, and TRS-80 Color Computer". However, I noticed that his list of all 551 reserved words one should avoid using in identifiers as they are defined in one BASIC or another actually includes more keywords than were listed in the categories above. They appear to be from Atari BASIC (e.g., PTRIG) and Tektronix 4051 Graphic System BASIC Language (e.g., BAPPEN).

ABS
ACS
ACSD
ACSG
ADR
AND
APPEND
ARCOS
ARCSIN
ARCTAN
ASC
ASCII
ASN
ASND
ASNG
AT
ATAN
ATN
ATND
ATNG
AUDIO
AUTO
AXIS
B-A:
B-F:
B-P:
B-R:
B-W:
BACKUP
BAPPEN
BASE
BEEP
BGET
BLOAD
BLOCK-ALLOCATE:
BLOCK-EXECUTE:
BLOCK-FREE:
BLOCK-READ:
BLOCK-WRITE:
BUFFER-POINTER
BOLD
BPUT
BREAK
BRIGHTNESS
BSAVE
BUTTON
BYE
CALL
CATALOG
CDBL
CH
CHAIN
CHANGE
CHAR
CHAR$
CHARSIZE
CHDIR
CHR
CHR$
CINT
CIRCLE
CLEAR
CLG
CLK$
CLK
CLOAD
CLOADM
CLOCK
CLOG
CLOSE
CLR
CLRDOT
CLS
CMD
CO
CODE
COLLECT
COLOR
COLOR=
COM
COMMON
CON
CONCAT
CONSOLE
CONT
COPY
COS
COSD
COSG
COSH
COUNT
CSAVE
CSAVEM
CSH
CSNG
CSRLIN
CUR
CVD
CVI
CVN
CVS
CVT$%
CVT$F
CVT%$
CVTF$
DASH
DAT
DATA
DATE$
DCLOSE
DEBUG
DEF
DEFDBL
DEFFN
DEFINT
DEF SEG
DEFSNG
DEFSTR
DEFUSR
DEG
DEGREE
DEL
DELETE
DET
DIGITS
DIM
DIR
DIRECTORY
DLOAD
DLOADM
DMS
DOPEN
DOS
DOT
DRAW
DRAWTO
DRIVE
DS
DSAVE
DSKI$
DSKINI
DSKO$
DSP
EDIT
ELSE
END
ENTER
ENVIRON
ENVIRON$
EOF
EQ
EQV
ERASE
ERDEV
ERDEV$
ERL
ERR
ERRL
ERRN
ERROR
ERRS$
EXAM
EXCHANGE
EXEC
EXIT
EXP
EXT
FDIM
FETCH
FGET
FIELD
FIF
FILE
FILES
FILL
FIN
FIND
FINPUT
FIX
FLASH
FLOW
FLT
FMT
FN
FNEND
FONT
FOR
FORMAT
FOUT
FPRINT
FPUT
FRAC
FRE
FREE
FUNTIL
FUZZ
GE
GET
GET#
GIN
GO
GO TO
GOODBYE
GOSUB
GOSUB-OF
GOT
GOTO
GOTO-OF
GR
GRAD
GRAPHICS
GT
HCOLOR
HCOLOR=
HEADER
HEX$
HGR
HGR2
HIMEM:
HLIN
HLIN-AT
HOME
HPLOT
HSCRN
HTAB
IF
IF-GOT
IF-GOTO
IF-LET
IF-THE
IF-THEN
IF-THEN-ELSE
IMAGE
IMP
IN#
INCH
INCHAR
INDEX
INIT
INKEY$
INP
INPUT
INPUT#
INPUT$
INPUT1
INPUTLINE
INSTR
INT
INTER$
INVERSE
IOCTL
IOCTL$
JOYSTK
KEY
KEY$
KILL
LE
LEFT
LEFT$
LEN
LET
LGT
LI
LIN
LINE
LINE INPUT#
LINEINPUT
LINK
LINPUT
LIS
LIST
LLIST
LN
LOAD
LOADM
LOC
LOCATE
LOF
LOG
LOG10
LOGE
LOMEM:
LPOS
LPRINT
LPRINTUSING
LSET
LT
M-E:
M-R:
M-W:
MAN
MARK
MAT *
MAT +
MAT -
MAT =
MAT CON
MAT IDN
MAT INPUT
MAT INV
MAT PRINT
MAT READ
MAT TRN
MAT ZER
MAX
MDD
MEM
MEMORY-EXECUTE:
MEMORY-READ:
MEMORY-WRITE:
MERGE
MID
MID$
MIN
MKD$
MKDIR
MKI$
MKN$
MKS$
MOD
MONITOR
MOTOR
MPY
MTPACK
NAME
NE
NEW
NEX
NEXT
NOFLOW
NOISE
NORMAL
NOT
NOTE
NOTRACE
NULL
NUM
NUM$
OCT$
OFF
OLD
ON
ON ERR GOTO
ON ERROR GOTO
ON-GOSUB
ON-GOT
ON-GOTO
ONERR
OPEN
OPTION
OPTION BASE
OR
OUT
OUTPUT
PADDLE
PAGE
PAINT
PALETTE
PALETTE USING
PAUSE
PCLEAR
PCLS
PCOPY
PDL
PEEK
PEN
PI
PIN
PLAY
PLOT
PMAP
PMODE
POINT
POINTER
POKE
POLL
POP
POS
POSITION
POSN
PPOINT
PR#
PRECISION
PRESET
PRI
PRINT
PRINT #USING
PRINT AT
PRINT USING
PRINT #
PRINT @
PSET
PTR
PTRIG
PUT
PUT#
RAD
RADIAN
RAN
RANDOM
RANDOMIZE
RBYTE
RDRAW
REA
READ
READ#
RECALL
RECORD
REM
REMARK
REN
RENAME
RENUM
RENUMBER
REP
REPEAT$
RES
RESET
RESTORE
RESUME
RESUME NEXT
RET
RETURN
RIGHT
RIGHT$
RMDIR
RMOVE
RND
ROT=
ROTATE
ROW
RSET
RU
RUN
SAVE
SAVEM
SCALE
SCALE=
SCR
SCRATCH
SCREEN
SCRN
SCRN(
SECRET
SEG
SEG$
SET
SETCOLOR
SETDOT
SGET
SGN
SHELL
SHLOAD
SHUT
SIN
SIND
SING
SINH
SKIPF
SLEEP
SNH
SORT
SOUND
SPA
SPACE
SPACE$
SPC
SPC(
SPEED=
SPUT
SQR
SQRT
ST
STATUS
STE
STEP
STICK
STO
STOP
STORE
STR
STR$
STRIG
STRING
STRING$
STUFF
SUB
SUBEND
SUM
SWAP
SYS
SYSTEM
TAB
TAB(
TAN
TAND
TANG
TANH
TAPPEND
TEXT
THE
THEN
TI
TI$
TIM
TIME
TIME$
TIMER
TLIST
TLOAD
TNH
TO
TOP
TRACE
TRACE OFF
TRACE ON
TRAP
TROFF
TRON
TSAVE
TYP
TYPE
UNLOAD
UNTIL
USER
USING
USR
VAL
VARPTR
VARPTR$
VERIFY
VIEW
VIEWPORT
VLIN
VLIN-AT
VPOS
VTAB
WAIT
WBYTE
WEAVE
WEND
WHILE
WIDTH
WINDOW
WRITE
WRITE#
XDRAW
XIO
XOR
XPLOT
XRA

@dykstrom
Copy link
Owner

dykstrom commented Dec 1, 2022

Statements Used in Procedures (SUB, FUNCTION, DEF FN) are also currently shown in the same face as Control-Flow, but if there are any spare font-lock categories left, it may look better if they were subtly different.

It is also possible to create new font-lock categories. I don't know if that is considered good style though. One could do something like this:

(defface font-lock-operator-face
  '((((class grayscale) (background light)) :foreground "Gray90" :weight bold)
    (((class grayscale) (background dark))  :foreground "DimGray" :weight bold)
    (((class color) (min-colors 88) (background light)) :foreground "ForestGreen")
    (((class color) (min-colors 88) (background dark))  :foreground "PaleGreen")
    (((class color) (min-colors 16) (background light)) :foreground "ForestGreen")
    (((class color) (min-colors 16) (background dark))  :foreground "PaleGreen")
    (((class color) (min-colors 8)) :foreground "green")
    (t :weight bold :underline t))
  "Font Lock mode face used to highlight operators."
  :group 'font-lock-faces)

(defvar font-lock-operator-face 'font-lock-operator-face
  "Face name to use for operators.")

@dykstrom
Copy link
Owner

dykstrom commented Dec 1, 2022

One feature it has that basic-mode.el should steal acquire is highlighting line numbers when they are referenced by statements like GOTO 10 in the line number color.

This is a good idea. But maybe it should be a separate issue, because it has nothing to do with highlighting categories?

@hackerb9
Copy link
Contributor Author

hackerb9 commented Dec 2, 2022

It is also possible to create new font-lock categories. I don't know if that is considered good style though.

I like that idea. I also don't know about the style guidelines, but I think it should be fine since it would only affect BASIC mode.

Creating new categories and aliasing the existing ones (functions/keywords/builtins) would allow categories that make sense for BASIC. I think the QBASIC manual is a good starting point, but I'd suggest merging some of the similar categories:

  • Control-Flow Statements (IF, THEN, FOR, NEXT)
    • Statements Used in BASIC Procedures (GOSUB, CALL, DECLARE)
      Inherits from Control-Flow, but subtly different.
    • Trapping Statements and Functions (ON ERR, RESUME, ERROR, ON event GOSUB)
      Inherits from Control-Flow, but more vivid to warn of surprising leaps.
  • I/O Statements (PRINT, INPUT, OPEN, SEEK)
    • Graphics Statements and Functions (SCREEN, PSET, LINE)
      Inherits from I/O, but I see no need to differentiate by default
  • String-Processing Statements and Functions (MID$, VAL, ASC, CHR$)

Of course, the categories from that particular appendix are not exhaustive as they do not cover the more day-to-day categories:

  • Functions
    • Returns a numeric value (ABS, FIX, MOD, FRE)
    • Returns a string value (MID$, TIME$, STRING$)
  • Operators (+, -, <>, AND, XOR)
    These are so common they should not be strongly highlighted, if at all
  • Types (CDBL, CONST)
  • General BASIC functions (PEEK, POKE, BEEP)
Click to see the full list of QBASIC reserved words.
ABS
ACCESS
ALIAS
AND
ANY
APPEND
AS
ASC
ATN
BASE
BEEP
BINARY
BLOAD
BSAVE
BYVAL
CALL
CALLS
CASE
CDBL
CDECL
CHAIN
CHDIR
CHR$
CINT
CIRCLE
CLEAR
CLNG
CLOSE
CLS
COLOR
COM
COMMANDS
COMMON
CONST
COS
CSNG
CSRLIN
CVD
CVDMBF
CVI
CVL
CVS
CVSMBF
DATA
DATES
DECLARE
DEF
DEFDBL
DEFINT
DEFLNG
DEFSNG
DEFSTR
DIM
DO
DOUBLE
DRAW
ELSE
ELSEIF
END
ENDIF
ENVIRON
ENVIRONS
EOF
EQV
ERASE
ERDEV
ERDEVS
ERL
ERR
ERROR
EXIT
EXP
FIELD
FILEATTR
FILES
FIX
FOR
FRE
FREEFILE
FUNCTION
GET
GOSUB
GOTO
HEX$
IF
IMP
INKEYS
INP
INPUT
INPUTS
INSTR
INT
INTEGER
IOCTL
IOCTLS
IS
KEY
KILL
LBOUND
LCASES
LEFTS
LEN
LET
LINE
LIST
LOC
LOCAL
LOCATE
LOCK
LOF
LOG
LONG
LOOP
LPOS
LPRINT
LSET
LTRIMS
MID$
MKD$
MKDIR
MKDMBFS
MKI$
MKL$
MKSMBFS
MKSS
MOD
NAME
NEXT
NOT
OCT$
OFF
ON
OPEN
OPTION
OR
OUT
OUTPUT
PAINT
PALETTE
PCOPY
PEEK
PEN
PLAY
PMAP
POINT
POKE
POS
PRESET
PRINT
PSET
PUT
RANDOM
RANDOMIZE
READ
REDIM
REM
RESET
RESTORE
RESUME
RETURN
RIGHTS
RMDIR
RND
RSET
RTRIMS
RUN
SADD
SCREEN
SEEK
SEG
SELECT
SETMEM
SGN
SHARED
SHELL
SIGNAL
SIN
SINGLE
SLEEP
SOUND
SPACES
SPC
SQR
STATIC
STEP
STICK
STOP
STR$
STRIG
STRING
STRINGS
SUB
SWAP
SYSTEM
TAB
TAN
THEN
TIMER
TIMES
TO
TROFF
TRON
TYPE
UBOUND
UCASES
UEVENT
UNLOCK
UNTIL
USING
VAL
VARPTR
VARPTRS
VARSEG
VIEW
WAIT
WEND
WHILE
WIDTH
WINDOW
WRITE
XOR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants