lisp.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. const LISP_IDENT_RE = '[a-zA-Z_\\-+\\*\\/<=>&#][a-zA-Z0-9_\\-+*\\/<=>&#!]*';
  9. const MEC_RE = '\\|[^]*?\\|';
  10. const LISP_SIMPLE_NUMBER_RE = '(-|\\+)?\\d+(\\.\\d+|\\/\\d+)?((d|e|f|l|s|D|E|F|L|S)(\\+|-)?\\d+)?';
  11. const LITERAL = {
  12. className: 'literal',
  13. begin: '\\b(t{1}|nil)\\b'
  14. };
  15. const NUMBER = {
  16. className: 'number',
  17. variants: [
  18. {
  19. begin: LISP_SIMPLE_NUMBER_RE,
  20. relevance: 0
  21. },
  22. { begin: '#(b|B)[0-1]+(/[0-1]+)?' },
  23. { begin: '#(o|O)[0-7]+(/[0-7]+)?' },
  24. { begin: '#(x|X)[0-9a-fA-F]+(/[0-9a-fA-F]+)?' },
  25. {
  26. begin: '#(c|C)\\(' + LISP_SIMPLE_NUMBER_RE + ' +' + LISP_SIMPLE_NUMBER_RE,
  27. end: '\\)'
  28. }
  29. ]
  30. };
  31. const STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null });
  32. const COMMENT = hljs.COMMENT(
  33. ';', '$',
  34. { relevance: 0 }
  35. );
  36. const VARIABLE = {
  37. begin: '\\*',
  38. end: '\\*'
  39. };
  40. const KEYWORD = {
  41. className: 'symbol',
  42. begin: '[:&]' + LISP_IDENT_RE
  43. };
  44. const IDENT = {
  45. begin: LISP_IDENT_RE,
  46. relevance: 0
  47. };
  48. const MEC = { begin: MEC_RE };
  49. const QUOTED_LIST = {
  50. begin: '\\(',
  51. end: '\\)',
  52. contains: [
  53. 'self',
  54. LITERAL,
  55. STRING,
  56. NUMBER,
  57. IDENT
  58. ]
  59. };
  60. const QUOTED = {
  61. contains: [
  62. NUMBER,
  63. STRING,
  64. VARIABLE,
  65. KEYWORD,
  66. QUOTED_LIST,
  67. IDENT
  68. ],
  69. variants: [
  70. {
  71. begin: '[\'`]\\(',
  72. end: '\\)'
  73. },
  74. {
  75. begin: '\\(quote ',
  76. end: '\\)',
  77. keywords: { name: 'quote' }
  78. },
  79. { begin: '\'' + MEC_RE }
  80. ]
  81. };
  82. const QUOTED_ATOM = { variants: [
  83. { begin: '\'' + LISP_IDENT_RE },
  84. { begin: '#\'' + LISP_IDENT_RE + '(::' + LISP_IDENT_RE + ')*' }
  85. ] };
  86. const LIST = {
  87. begin: '\\(\\s*',
  88. end: '\\)'
  89. };
  90. const BODY = {
  91. endsWithParent: true,
  92. relevance: 0
  93. };
  94. LIST.contains = [
  95. {
  96. className: 'name',
  97. variants: [
  98. {
  99. begin: LISP_IDENT_RE,
  100. relevance: 0,
  101. },
  102. { begin: MEC_RE }
  103. ]
  104. },
  105. BODY
  106. ];
  107. BODY.contains = [
  108. QUOTED,
  109. QUOTED_ATOM,
  110. LIST,
  111. LITERAL,
  112. NUMBER,
  113. STRING,
  114. COMMENT,
  115. VARIABLE,
  116. KEYWORD,
  117. MEC,
  118. IDENT
  119. ];
  120. return {
  121. name: 'Lisp',
  122. illegal: /\S/,
  123. contains: [
  124. NUMBER,
  125. hljs.SHEBANG(),
  126. LITERAL,
  127. STRING,
  128. COMMENT,
  129. QUOTED,
  130. QUOTED_ATOM,
  131. LIST,
  132. IDENT
  133. ]
  134. };
  135. }
  136. export { lisp as default };