854270fd5eed6a71f6dbe805f07dd21f5fd3c8bafd3fc94ec47bd269a2ad13d505f97de171204130f52594129a90366c0e3b19bbf3a6773f04e002dee6dc40 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Language: Brainfuck
  3. Author: Evgeny Stepanischev <imbolk@gmail.com>
  4. Website: https://esolangs.org/wiki/Brainfuck
  5. */
  6. /** @type LanguageFn */
  7. function brainfuck(hljs) {
  8. const LITERAL = {
  9. className: 'literal',
  10. begin: /[+-]+/,
  11. relevance: 0
  12. };
  13. return {
  14. name: 'Brainfuck',
  15. aliases: [ 'bf' ],
  16. contains: [
  17. hljs.COMMENT(
  18. /[^\[\]\.,\+\-<> \r\n]/,
  19. /[\[\]\.,\+\-<> \r\n]/,
  20. {
  21. contains: [
  22. {
  23. match: /[ ]+[^\[\]\.,\+\-<> \r\n]/,
  24. relevance: 0
  25. }
  26. ],
  27. returnEnd: true,
  28. relevance: 0
  29. }
  30. ),
  31. {
  32. className: 'title',
  33. begin: '[\\[\\]]',
  34. relevance: 0
  35. },
  36. {
  37. className: 'string',
  38. begin: '[\\.,]',
  39. relevance: 0
  40. },
  41. {
  42. // this mode works as the only relevance counter
  43. // it looks ahead to find the start of a run of literals
  44. // so only the runs are counted as relevant
  45. begin: /(?=\+\+|--)/,
  46. contains: [ LITERAL ]
  47. },
  48. LITERAL
  49. ]
  50. };
  51. }
  52. export { brainfuck as default };