prolog.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. module.exports = function(hljs) {
  2. var ATOM = {
  3. begin: /[a-z][A-Za-z0-9_]*/,
  4. relevance: 0
  5. };
  6. var VAR = {
  7. className: 'symbol',
  8. variants: [
  9. {begin: /[A-Z][a-zA-Z0-9_]*/},
  10. {begin: /_[A-Za-z0-9_]*/},
  11. ],
  12. relevance: 0
  13. };
  14. var PARENTED = {
  15. begin: /\(/,
  16. end: /\)/,
  17. relevance: 0
  18. };
  19. var LIST = {
  20. begin: /\[/,
  21. end: /\]/
  22. };
  23. var LINE_COMMENT = {
  24. className: 'comment',
  25. begin: /%/, end: /$/,
  26. contains: [hljs.PHRASAL_WORDS_MODE]
  27. };
  28. var BACKTICK_STRING = {
  29. className: 'string',
  30. begin: /`/, end: /`/,
  31. contains: [hljs.BACKSLASH_ESCAPE]
  32. };
  33. var CHAR_CODE = {
  34. className: 'string', // 0'a etc.
  35. begin: /0\'(\\\'|.)/
  36. };
  37. var SPACE_CODE = {
  38. className: 'string',
  39. begin: /0\'\\s/ // 0'\s
  40. };
  41. var PRED_OP = { // relevance booster
  42. begin: /:-/
  43. };
  44. var inner = [
  45. ATOM,
  46. VAR,
  47. PARENTED,
  48. PRED_OP,
  49. LIST,
  50. LINE_COMMENT,
  51. hljs.C_BLOCK_COMMENT_MODE,
  52. hljs.QUOTE_STRING_MODE,
  53. hljs.APOS_STRING_MODE,
  54. BACKTICK_STRING,
  55. CHAR_CODE,
  56. SPACE_CODE,
  57. hljs.C_NUMBER_MODE
  58. ];
  59. PARENTED.contains = inner;
  60. LIST.contains = inner;
  61. return {
  62. contains: inner.concat([
  63. {begin: /\.$/} // relevance booster
  64. ])
  65. };
  66. };