prism-purebasic.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Original Code by Bas Groothedde
  3. !!MANY THANKS!! I never would have made this, regex and me will never be best friends ;)
  4. ==> https://codepen.io/ImagineProgramming/details/JYydBy/
  5. slightly changed to pass all tests
  6. */
  7. // PureBasic support, steal stuff from ansi-c
  8. Prism.languages.purebasic = Prism.languages.extend('clike', {
  9. 'comment': /;.*/,
  10. 'keyword': /\b(?:align|and|as|break|calldebugger|case|compilercase|compilerdefault|compilerelse|compilerelseif|compilerendif|compilerendselect|compilererror|compilerif|compilerselect|continue|data|datasection|debug|debuglevel|declare|declarec|declarecdll|declaredll|declaremodule|default|define|dim|disableasm|disabledebugger|disableexplicit|else|elseif|enableasm|enabledebugger|enableexplicit|end|enddatasection|enddeclaremodule|endenumeration|endif|endimport|endinterface|endmacro|endmodule|endprocedure|endselect|endstructure|endstructureunion|endwith|enumeration|extends|fakereturn|for|foreach|forever|global|gosub|goto|if|import|importc|includebinary|includefile|includepath|interface|macro|module|newlist|newmap|next|not|or|procedure|procedurec|procedurecdll|proceduredll|procedurereturn|protected|prototype|prototypec|read|redim|repeat|restore|return|runtime|select|shared|static|step|structure|structureunion|swap|threaded|to|until|wend|while|with|xincludefile|xor)\b/i,
  11. 'function': /\b\w+(?:\.\w+)?\s*(?=\()/,
  12. 'number': /(?:\$[\da-f]+|\b-?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\b/i,
  13. 'operator': /(?:@\*?|\?|\*)\w+\$?|-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*/@]/
  14. });
  15. Prism.languages.insertBefore('purebasic', 'keyword', {
  16. 'tag': /#\w+\$?/,
  17. 'asm': {
  18. pattern: /(^[\t ]*)!.*/m,
  19. lookbehind: true,
  20. alias: 'tag',
  21. inside: {
  22. 'comment': /;.*/,
  23. 'string': {
  24. pattern: /(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/,
  25. greedy: true
  26. },
  27. // Anonymous label references, i.e.: jmp @b
  28. 'label-reference-anonymous': {
  29. pattern: /(!\s*j[a-z]+\s+)@[fb]/i,
  30. lookbehind: true,
  31. alias: 'fasm-label'
  32. },
  33. // Named label reference, i.e.: jne label1
  34. 'label-reference-addressed': {
  35. pattern: /(!\s*j[a-z]+\s+)[A-Z._?$@][\w.?$@~#]*/i,
  36. lookbehind: true,
  37. alias: 'fasm-label'
  38. },
  39. 'keyword': [
  40. /\b(?:extern|global)\b[^;\r\n]*/i,
  41. /\b(?:CPU|DEFAULT|FLOAT)\b.*/
  42. ],
  43. 'function': {
  44. pattern: /^([\t ]*!\s*)[\da-z]+(?=\s|$)/im,
  45. lookbehind: true
  46. },
  47. 'function-inline': {
  48. pattern: /(:\s*)[\da-z]+(?=\s)/i,
  49. lookbehind: true,
  50. alias: 'function'
  51. },
  52. 'label': {
  53. pattern: /^([\t ]*!\s*)[A-Za-z._?$@][\w.?$@~#]*(?=:)/m,
  54. lookbehind: true,
  55. alias: 'fasm-label'
  56. },
  57. 'register': /\b(?:st\d|[xyz]mm\d\d?|[cdt]r\d|r\d\d?[bwd]?|[er]?[abcd]x|[abcd][hl]|[er]?(?:bp|di|si|sp)|[cdefgs]s|mm\d+)\b/i,
  58. 'number': /(?:\b|-|(?=\$))(?:0[hx](?:[\da-f]*\.)?[\da-f]+(?:p[+-]?\d+)?|\d[\da-f]+[hx]|\$\d[\da-f]*|0[oq][0-7]+|[0-7]+[oq]|0[by][01]+|[01]+[by]|0[dt]\d+|(?:\d+(?:\.\d+)?|\.\d+)(?:\.?e[+-]?\d+)?[dt]?)\b/i,
  59. 'operator': /[\[\]*+\-/%<>=&|$!,.:]/
  60. }
  61. }
  62. });
  63. delete Prism.languages.purebasic['class-name'];
  64. delete Prism.languages.purebasic['boolean'];
  65. Prism.languages.pbfasm = Prism.languages['purebasic'];