basic.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Language: BASIC
  3. Author: Raphaël Assénat <raph@raphnet.net>
  4. Description: Based on the BASIC reference from the Tandy 1000 guide
  5. Website: https://en.wikipedia.org/wiki/Tandy_1000
  6. */
  7. /** @type LanguageFn */
  8. function basic(hljs) {
  9. return {
  10. name: 'BASIC',
  11. case_insensitive: true,
  12. illegal: '^\.',
  13. // Support explicitly typed variables that end with $%! or #.
  14. keywords: {
  15. $pattern: '[a-zA-Z][a-zA-Z0-9_$%!#]*',
  16. keyword:
  17. 'ABS ASC AND ATN AUTO|0 BEEP BLOAD|10 BSAVE|10 CALL CALLS CDBL CHAIN CHDIR CHR$|10 CINT CIRCLE ' +
  18. 'CLEAR CLOSE CLS COLOR COM COMMON CONT COS CSNG CSRLIN CVD CVI CVS DATA DATE$ ' +
  19. 'DEFDBL DEFINT DEFSNG DEFSTR DEF|0 SEG USR DELETE DIM DRAW EDIT END ENVIRON ENVIRON$ ' +
  20. 'EOF EQV ERASE ERDEV ERDEV$ ERL ERR ERROR EXP FIELD FILES FIX FOR|0 FRE GET GOSUB|10 GOTO ' +
  21. 'HEX$ IF THEN ELSE|0 INKEY$ INP INPUT INPUT# INPUT$ INSTR IMP INT IOCTL IOCTL$ KEY ON ' +
  22. 'OFF LIST KILL LEFT$ LEN LET LINE LLIST LOAD LOC LOCATE LOF LOG LPRINT USING LSET ' +
  23. 'MERGE MID$ MKDIR MKD$ MKI$ MKS$ MOD NAME NEW NEXT NOISE NOT OCT$ ON OR PEN PLAY STRIG OPEN OPTION ' +
  24. 'BASE OUT PAINT PALETTE PCOPY PEEK PMAP POINT POKE POS PRINT PRINT] PSET PRESET ' +
  25. 'PUT RANDOMIZE READ REM RENUM RESET|0 RESTORE RESUME RETURN|0 RIGHT$ RMDIR RND RSET ' +
  26. 'RUN SAVE SCREEN SGN SHELL SIN SOUND SPACE$ SPC SQR STEP STICK STOP STR$ STRING$ SWAP ' +
  27. 'SYSTEM TAB TAN TIME$ TIMER TROFF TRON TO USR VAL VARPTR VARPTR$ VIEW WAIT WHILE ' +
  28. 'WEND WIDTH WINDOW WRITE XOR'
  29. },
  30. contains: [
  31. hljs.QUOTE_STRING_MODE,
  32. hljs.COMMENT('REM', '$', {
  33. relevance: 10
  34. }),
  35. hljs.COMMENT('\'', '$', {
  36. relevance: 0
  37. }),
  38. {
  39. // Match line numbers
  40. className: 'symbol',
  41. begin: '^[0-9]+ ',
  42. relevance: 10
  43. },
  44. {
  45. // Match typed numeric constants (1000, 12.34!, 1.2e5, 1.5#, 1.2D2)
  46. className: 'number',
  47. begin: '\\b\\d+(\\.\\d+)?([edED]\\d+)?[#\!]?',
  48. relevance: 0
  49. },
  50. {
  51. // Match hexadecimal numbers (&Hxxxx)
  52. className: 'number',
  53. begin: '(&[hH][0-9a-fA-F]{1,4})'
  54. },
  55. {
  56. // Match octal numbers (&Oxxxxxx)
  57. className: 'number',
  58. begin: '(&[oO][0-7]{1,6})'
  59. }
  60. ]
  61. };
  62. }
  63. module.exports = basic;