erlang-repl.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @param {string} value
  3. * @returns {RegExp}
  4. * */
  5. /**
  6. * @param {RegExp | string } re
  7. * @returns {string}
  8. */
  9. function source(re) {
  10. if (!re) return null;
  11. if (typeof re === "string") return re;
  12. return re.source;
  13. }
  14. /**
  15. * @param {...(RegExp | string) } args
  16. * @returns {string}
  17. */
  18. function concat(...args) {
  19. const joined = args.map((x) => source(x)).join("");
  20. return joined;
  21. }
  22. /*
  23. Language: Erlang REPL
  24. Author: Sergey Ignatov <sergey@ignatov.spb.su>
  25. Website: https://www.erlang.org
  26. Category: functional
  27. */
  28. /** @type LanguageFn */
  29. function erlangRepl(hljs) {
  30. return {
  31. name: 'Erlang REPL',
  32. keywords: {
  33. built_in:
  34. 'spawn spawn_link self',
  35. keyword:
  36. 'after and andalso|10 band begin bnot bor bsl bsr bxor case catch cond div end fun if ' +
  37. 'let not of or orelse|10 query receive rem try when xor'
  38. },
  39. contains: [
  40. {
  41. className: 'meta',
  42. begin: '^[0-9]+> ',
  43. relevance: 10
  44. },
  45. hljs.COMMENT('%', '$'),
  46. {
  47. className: 'number',
  48. begin: '\\b(\\d+(_\\d+)*#[a-fA-F0-9]+(_[a-fA-F0-9]+)*|\\d+(_\\d+)*(\\.\\d+(_\\d+)*)?([eE][-+]?\\d+)?)',
  49. relevance: 0
  50. },
  51. hljs.APOS_STRING_MODE,
  52. hljs.QUOTE_STRING_MODE,
  53. {
  54. begin: concat(
  55. /\?(::)?/,
  56. /([A-Z]\w*)/, // at least one identifier
  57. /((::)[A-Z]\w*)*/ // perhaps more
  58. )
  59. },
  60. {
  61. begin: '->'
  62. },
  63. {
  64. begin: 'ok'
  65. },
  66. {
  67. begin: '!'
  68. },
  69. {
  70. begin: '(\\b[a-z\'][a-zA-Z0-9_\']*:[a-z\'][a-zA-Z0-9_\']*)|(\\b[a-z\'][a-zA-Z0-9_\']*)',
  71. relevance: 0
  72. },
  73. {
  74. begin: '[A-Z][a-zA-Z0-9_\']*',
  75. relevance: 0
  76. }
  77. ]
  78. };
  79. }
  80. module.exports = erlangRepl;