lisp.js 2.3 KB

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