basic.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. Category: system
  7. */
  8. /** @type LanguageFn */
  9. function basic(hljs) {
  10. const KEYWORDS = [
  11. "ABS",
  12. "ASC",
  13. "AND",
  14. "ATN",
  15. "AUTO|0",
  16. "BEEP",
  17. "BLOAD|10",
  18. "BSAVE|10",
  19. "CALL",
  20. "CALLS",
  21. "CDBL",
  22. "CHAIN",
  23. "CHDIR",
  24. "CHR$|10",
  25. "CINT",
  26. "CIRCLE",
  27. "CLEAR",
  28. "CLOSE",
  29. "CLS",
  30. "COLOR",
  31. "COM",
  32. "COMMON",
  33. "CONT",
  34. "COS",
  35. "CSNG",
  36. "CSRLIN",
  37. "CVD",
  38. "CVI",
  39. "CVS",
  40. "DATA",
  41. "DATE$",
  42. "DEFDBL",
  43. "DEFINT",
  44. "DEFSNG",
  45. "DEFSTR",
  46. "DEF|0",
  47. "SEG",
  48. "USR",
  49. "DELETE",
  50. "DIM",
  51. "DRAW",
  52. "EDIT",
  53. "END",
  54. "ENVIRON",
  55. "ENVIRON$",
  56. "EOF",
  57. "EQV",
  58. "ERASE",
  59. "ERDEV",
  60. "ERDEV$",
  61. "ERL",
  62. "ERR",
  63. "ERROR",
  64. "EXP",
  65. "FIELD",
  66. "FILES",
  67. "FIX",
  68. "FOR|0",
  69. "FRE",
  70. "GET",
  71. "GOSUB|10",
  72. "GOTO",
  73. "HEX$",
  74. "IF",
  75. "THEN",
  76. "ELSE|0",
  77. "INKEY$",
  78. "INP",
  79. "INPUT",
  80. "INPUT#",
  81. "INPUT$",
  82. "INSTR",
  83. "IMP",
  84. "INT",
  85. "IOCTL",
  86. "IOCTL$",
  87. "KEY",
  88. "ON",
  89. "OFF",
  90. "LIST",
  91. "KILL",
  92. "LEFT$",
  93. "LEN",
  94. "LET",
  95. "LINE",
  96. "LLIST",
  97. "LOAD",
  98. "LOC",
  99. "LOCATE",
  100. "LOF",
  101. "LOG",
  102. "LPRINT",
  103. "USING",
  104. "LSET",
  105. "MERGE",
  106. "MID$",
  107. "MKDIR",
  108. "MKD$",
  109. "MKI$",
  110. "MKS$",
  111. "MOD",
  112. "NAME",
  113. "NEW",
  114. "NEXT",
  115. "NOISE",
  116. "NOT",
  117. "OCT$",
  118. "ON",
  119. "OR",
  120. "PEN",
  121. "PLAY",
  122. "STRIG",
  123. "OPEN",
  124. "OPTION",
  125. "BASE",
  126. "OUT",
  127. "PAINT",
  128. "PALETTE",
  129. "PCOPY",
  130. "PEEK",
  131. "PMAP",
  132. "POINT",
  133. "POKE",
  134. "POS",
  135. "PRINT",
  136. "PRINT]",
  137. "PSET",
  138. "PRESET",
  139. "PUT",
  140. "RANDOMIZE",
  141. "READ",
  142. "REM",
  143. "RENUM",
  144. "RESET|0",
  145. "RESTORE",
  146. "RESUME",
  147. "RETURN|0",
  148. "RIGHT$",
  149. "RMDIR",
  150. "RND",
  151. "RSET",
  152. "RUN",
  153. "SAVE",
  154. "SCREEN",
  155. "SGN",
  156. "SHELL",
  157. "SIN",
  158. "SOUND",
  159. "SPACE$",
  160. "SPC",
  161. "SQR",
  162. "STEP",
  163. "STICK",
  164. "STOP",
  165. "STR$",
  166. "STRING$",
  167. "SWAP",
  168. "SYSTEM",
  169. "TAB",
  170. "TAN",
  171. "TIME$",
  172. "TIMER",
  173. "TROFF",
  174. "TRON",
  175. "TO",
  176. "USR",
  177. "VAL",
  178. "VARPTR",
  179. "VARPTR$",
  180. "VIEW",
  181. "WAIT",
  182. "WHILE",
  183. "WEND",
  184. "WIDTH",
  185. "WINDOW",
  186. "WRITE",
  187. "XOR"
  188. ];
  189. return {
  190. name: 'BASIC',
  191. case_insensitive: true,
  192. illegal: '^\.',
  193. // Support explicitly typed variables that end with $%! or #.
  194. keywords: {
  195. $pattern: '[a-zA-Z][a-zA-Z0-9_$%!#]*',
  196. keyword: KEYWORDS
  197. },
  198. contains: [
  199. hljs.QUOTE_STRING_MODE,
  200. hljs.COMMENT('REM', '$', { relevance: 10 }),
  201. hljs.COMMENT('\'', '$', { relevance: 0 }),
  202. {
  203. // Match line numbers
  204. className: 'symbol',
  205. begin: '^[0-9]+ ',
  206. relevance: 10
  207. },
  208. {
  209. // Match typed numeric constants (1000, 12.34!, 1.2e5, 1.5#, 1.2D2)
  210. className: 'number',
  211. begin: '\\b\\d+(\\.\\d+)?([edED]\\d+)?[#\!]?',
  212. relevance: 0
  213. },
  214. {
  215. // Match hexadecimal numbers (&Hxxxx)
  216. className: 'number',
  217. begin: '(&[hH][0-9a-fA-F]{1,4})'
  218. },
  219. {
  220. // Match octal numbers (&Oxxxxxx)
  221. className: 'number',
  222. begin: '(&[oO][0-7]{1,6})'
  223. }
  224. ]
  225. };
  226. }
  227. export { basic as default };