mercury.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. Language: Mercury
  3. Author: mucaho <mkucko@gmail.com>
  4. Description: Mercury is a logic/functional programming language which combines the clarity and expressiveness of declarative programming with advanced static analysis and error detection features.
  5. Website: https://www.mercurylang.org
  6. */
  7. function mercury(hljs) {
  8. const KEYWORDS = {
  9. keyword:
  10. 'module use_module import_module include_module end_module initialise ' +
  11. 'mutable initialize finalize finalise interface implementation pred ' +
  12. 'mode func type inst solver any_pred any_func is semidet det nondet ' +
  13. 'multi erroneous failure cc_nondet cc_multi typeclass instance where ' +
  14. 'pragma promise external trace atomic or_else require_complete_switch ' +
  15. 'require_det require_semidet require_multi require_nondet ' +
  16. 'require_cc_multi require_cc_nondet require_erroneous require_failure',
  17. meta:
  18. // pragma
  19. 'inline no_inline type_spec source_file fact_table obsolete memo ' +
  20. 'loop_check minimal_model terminates does_not_terminate ' +
  21. 'check_termination promise_equivalent_clauses ' +
  22. // preprocessor
  23. 'foreign_proc foreign_decl foreign_code foreign_type ' +
  24. 'foreign_import_module foreign_export_enum foreign_export ' +
  25. 'foreign_enum may_call_mercury will_not_call_mercury thread_safe ' +
  26. 'not_thread_safe maybe_thread_safe promise_pure promise_semipure ' +
  27. 'tabled_for_io local untrailed trailed attach_to_io_state ' +
  28. 'can_pass_as_mercury_type stable will_not_throw_exception ' +
  29. 'may_modify_trail will_not_modify_trail may_duplicate ' +
  30. 'may_not_duplicate affects_liveness does_not_affect_liveness ' +
  31. 'doesnt_affect_liveness no_sharing unknown_sharing sharing',
  32. built_in:
  33. 'some all not if then else true fail false try catch catch_any ' +
  34. 'semidet_true semidet_false semidet_fail impure_true impure semipure'
  35. };
  36. const COMMENT = hljs.COMMENT('%', '$');
  37. const NUMCODE = {
  38. className: 'number',
  39. begin: "0'.\\|0[box][0-9a-fA-F]*"
  40. };
  41. const ATOM = hljs.inherit(hljs.APOS_STRING_MODE, {
  42. relevance: 0
  43. });
  44. const STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, {
  45. relevance: 0
  46. });
  47. const STRING_FMT = {
  48. className: 'subst',
  49. begin: '\\\\[abfnrtv]\\|\\\\x[0-9a-fA-F]*\\\\\\|%[-+# *.0-9]*[dioxXucsfeEgGp]',
  50. relevance: 0
  51. };
  52. STRING.contains = STRING.contains.slice(); // we need our own copy of contains
  53. STRING.contains.push(STRING_FMT);
  54. const IMPLICATION = {
  55. className: 'built_in',
  56. variants: [
  57. {
  58. begin: '<=>'
  59. },
  60. {
  61. begin: '<=',
  62. relevance: 0
  63. },
  64. {
  65. begin: '=>',
  66. relevance: 0
  67. },
  68. {
  69. begin: '/\\\\'
  70. },
  71. {
  72. begin: '\\\\/'
  73. }
  74. ]
  75. };
  76. const HEAD_BODY_CONJUNCTION = {
  77. className: 'built_in',
  78. variants: [
  79. {
  80. begin: ':-\\|-->'
  81. },
  82. {
  83. begin: '=',
  84. relevance: 0
  85. }
  86. ]
  87. };
  88. return {
  89. name: 'Mercury',
  90. aliases: [
  91. 'm',
  92. 'moo'
  93. ],
  94. keywords: KEYWORDS,
  95. contains: [
  96. IMPLICATION,
  97. HEAD_BODY_CONJUNCTION,
  98. COMMENT,
  99. hljs.C_BLOCK_COMMENT_MODE,
  100. NUMCODE,
  101. hljs.NUMBER_MODE,
  102. ATOM,
  103. STRING,
  104. { // relevance booster
  105. begin: /:-/
  106. },
  107. { // relevance booster
  108. begin: /\.$/
  109. }
  110. ]
  111. };
  112. }
  113. module.exports = mercury;