lisp.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. module.exports = function(hljs) {
  2. var LISP_IDENT_RE = '[a-zA-Z_\\-\\+\\*\\/\\<\\=\\>\\&\\#][a-zA-Z0-9_\\-\\+\\*\\/\\<\\=\\>\\&\\#!]*';
  3. var MEC_RE = '\\|[^]*?\\|';
  4. var LISP_SIMPLE_NUMBER_RE = '(\\-|\\+)?\\d+(\\.\\d+|\\/\\d+)?((d|e|f|l|s|D|E|F|L|S)(\\+|\\-)?\\d+)?';
  5. var SHEBANG = {
  6. className: 'meta',
  7. begin: '^#!', end: '$'
  8. };
  9. var LITERAL = {
  10. className: 'literal',
  11. begin: '\\b(t{1}|nil)\\b'
  12. };
  13. var NUMBER = {
  14. className: 'number',
  15. variants: [
  16. {begin: LISP_SIMPLE_NUMBER_RE, relevance: 0},
  17. {begin: '#(b|B)[0-1]+(/[0-1]+)?'},
  18. {begin: '#(o|O)[0-7]+(/[0-7]+)?'},
  19. {begin: '#(x|X)[0-9a-fA-F]+(/[0-9a-fA-F]+)?'},
  20. {begin: '#(c|C)\\(' + LISP_SIMPLE_NUMBER_RE + ' +' + LISP_SIMPLE_NUMBER_RE, end: '\\)'}
  21. ]
  22. };
  23. var STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null});
  24. var COMMENT = hljs.COMMENT(
  25. ';', '$',
  26. {
  27. relevance: 0
  28. }
  29. );
  30. var VARIABLE = {
  31. begin: '\\*', end: '\\*'
  32. };
  33. var KEYWORD = {
  34. className: 'symbol',
  35. begin: '[:&]' + LISP_IDENT_RE
  36. };
  37. var IDENT = {
  38. begin: LISP_IDENT_RE,
  39. relevance: 0
  40. };
  41. var MEC = {
  42. begin: MEC_RE
  43. };
  44. var QUOTED_LIST = {
  45. begin: '\\(', end: '\\)',
  46. contains: ['self', LITERAL, STRING, NUMBER, IDENT]
  47. };
  48. var QUOTED = {
  49. contains: [NUMBER, STRING, VARIABLE, KEYWORD, QUOTED_LIST, IDENT],
  50. variants: [
  51. {
  52. begin: '[\'`]\\(', end: '\\)'
  53. },
  54. {
  55. begin: '\\(quote ', end: '\\)',
  56. keywords: {name: 'quote'}
  57. },
  58. {
  59. begin: '\'' + MEC_RE
  60. }
  61. ]
  62. };
  63. var QUOTED_ATOM = {
  64. variants: [
  65. {begin: '\'' + LISP_IDENT_RE},
  66. {begin: '#\'' + LISP_IDENT_RE + '(::' + LISP_IDENT_RE + ')*'}
  67. ]
  68. };
  69. var LIST = {
  70. begin: '\\(\\s*', end: '\\)'
  71. };
  72. var BODY = {
  73. endsWithParent: true,
  74. relevance: 0
  75. };
  76. LIST.contains = [
  77. {
  78. className: 'name',
  79. variants: [
  80. {begin: LISP_IDENT_RE},
  81. {begin: MEC_RE}
  82. ]
  83. },
  84. BODY
  85. ];
  86. BODY.contains = [QUOTED, QUOTED_ATOM, LIST, LITERAL, NUMBER, STRING, COMMENT, VARIABLE, KEYWORD, MEC, IDENT];
  87. return {
  88. illegal: /\S/,
  89. contains: [
  90. NUMBER,
  91. SHEBANG,
  92. LITERAL,
  93. STRING,
  94. COMMENT,
  95. QUOTED,
  96. QUOTED_ATOM,
  97. LIST,
  98. IDENT
  99. ]
  100. };
  101. };