prolog.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. Language: Prolog
  3. Description: Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.
  4. Author: Raivo Laanemets <raivo@infdot.com>
  5. Website: https://en.wikipedia.org/wiki/Prolog
  6. */
  7. function prolog(hljs) {
  8. const ATOM = {
  9. begin: /[a-z][A-Za-z0-9_]*/,
  10. relevance: 0
  11. };
  12. const VAR = {
  13. className: 'symbol',
  14. variants: [
  15. {
  16. begin: /[A-Z][a-zA-Z0-9_]*/
  17. },
  18. {
  19. begin: /_[A-Za-z0-9_]*/
  20. }
  21. ],
  22. relevance: 0
  23. };
  24. const PARENTED = {
  25. begin: /\(/,
  26. end: /\)/,
  27. relevance: 0
  28. };
  29. const LIST = {
  30. begin: /\[/,
  31. end: /\]/
  32. };
  33. const LINE_COMMENT = {
  34. className: 'comment',
  35. begin: /%/,
  36. end: /$/,
  37. contains: [ hljs.PHRASAL_WORDS_MODE ]
  38. };
  39. const BACKTICK_STRING = {
  40. className: 'string',
  41. begin: /`/,
  42. end: /`/,
  43. contains: [ hljs.BACKSLASH_ESCAPE ]
  44. };
  45. const CHAR_CODE = {
  46. className: 'string', // 0'a etc.
  47. begin: /0'(\\'|.)/
  48. };
  49. const SPACE_CODE = {
  50. className: 'string',
  51. begin: /0'\\s/ // 0'\s
  52. };
  53. const PRED_OP = { // relevance booster
  54. begin: /:-/
  55. };
  56. const inner = [
  57. ATOM,
  58. VAR,
  59. PARENTED,
  60. PRED_OP,
  61. LIST,
  62. LINE_COMMENT,
  63. hljs.C_BLOCK_COMMENT_MODE,
  64. hljs.QUOTE_STRING_MODE,
  65. hljs.APOS_STRING_MODE,
  66. BACKTICK_STRING,
  67. CHAR_CODE,
  68. SPACE_CODE,
  69. hljs.C_NUMBER_MODE
  70. ];
  71. PARENTED.contains = inner;
  72. LIST.contains = inner;
  73. return {
  74. name: 'Prolog',
  75. contains: inner.concat([
  76. { // relevance booster
  77. begin: /\.$/
  78. }
  79. ])
  80. };
  81. }
  82. module.exports = prolog;