prolog.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. Category: functional
  7. */
  8. function prolog(hljs) {
  9. const ATOM = {
  10. begin: /[a-z][A-Za-z0-9_]*/,
  11. relevance: 0
  12. };
  13. const VAR = {
  14. className: 'symbol',
  15. variants: [
  16. { begin: /[A-Z][a-zA-Z0-9_]*/ },
  17. { begin: /_[A-Za-z0-9_]*/ }
  18. ],
  19. relevance: 0
  20. };
  21. const PARENTED = {
  22. begin: /\(/,
  23. end: /\)/,
  24. relevance: 0
  25. };
  26. const LIST = {
  27. begin: /\[/,
  28. end: /\]/
  29. };
  30. const LINE_COMMENT = {
  31. className: 'comment',
  32. begin: /%/,
  33. end: /$/,
  34. contains: [ hljs.PHRASAL_WORDS_MODE ]
  35. };
  36. const BACKTICK_STRING = {
  37. className: 'string',
  38. begin: /`/,
  39. end: /`/,
  40. contains: [ hljs.BACKSLASH_ESCAPE ]
  41. };
  42. const CHAR_CODE = {
  43. className: 'string', // 0'a etc.
  44. begin: /0'(\\'|.)/
  45. };
  46. const SPACE_CODE = {
  47. className: 'string',
  48. begin: /0'\\s/ // 0'\s
  49. };
  50. const PRED_OP = { // relevance booster
  51. begin: /:-/ };
  52. const inner = [
  53. ATOM,
  54. VAR,
  55. PARENTED,
  56. PRED_OP,
  57. LIST,
  58. LINE_COMMENT,
  59. hljs.C_BLOCK_COMMENT_MODE,
  60. hljs.QUOTE_STRING_MODE,
  61. hljs.APOS_STRING_MODE,
  62. BACKTICK_STRING,
  63. CHAR_CODE,
  64. SPACE_CODE,
  65. hljs.C_NUMBER_MODE
  66. ];
  67. PARENTED.contains = inner;
  68. LIST.contains = inner;
  69. return {
  70. name: 'Prolog',
  71. contains: inner.concat([
  72. { // relevance booster
  73. begin: /\.$/ }
  74. ])
  75. };
  76. }
  77. export { prolog as default };