mercury.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. var 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. var COMMENT = hljs.COMMENT('%', '$');
  37. var NUMCODE = {
  38. className: 'number',
  39. begin: "0'.\\|0[box][0-9a-fA-F]*"
  40. };
  41. var ATOM = hljs.inherit(hljs.APOS_STRING_MODE, {relevance: 0});
  42. var STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, {relevance: 0});
  43. var STRING_FMT = {
  44. className: 'subst',
  45. begin: '\\\\[abfnrtv]\\|\\\\x[0-9a-fA-F]*\\\\\\|%[-+# *.0-9]*[dioxXucsfeEgGp]',
  46. relevance: 0
  47. };
  48. STRING.contains = STRING.contains.slice(); // we need our own copy of contains
  49. STRING.contains.push(STRING_FMT);
  50. var IMPLICATION = {
  51. className: 'built_in',
  52. variants: [
  53. {begin: '<=>'},
  54. {begin: '<=', relevance: 0},
  55. {begin: '=>', relevance: 0},
  56. {begin: '/\\\\'},
  57. {begin: '\\\\/'}
  58. ]
  59. };
  60. var HEAD_BODY_CONJUNCTION = {
  61. className: 'built_in',
  62. variants: [
  63. {begin: ':-\\|-->'},
  64. {begin: '=', relevance: 0}
  65. ]
  66. };
  67. return {
  68. name: 'Mercury',
  69. aliases: ['m', 'moo'],
  70. keywords: KEYWORDS,
  71. contains: [
  72. IMPLICATION,
  73. HEAD_BODY_CONJUNCTION,
  74. COMMENT,
  75. hljs.C_BLOCK_COMMENT_MODE,
  76. NUMCODE,
  77. hljs.NUMBER_MODE,
  78. ATOM,
  79. STRING,
  80. {begin: /:-/}, // relevance booster
  81. {begin: /\.$/} // relevance booster
  82. ]
  83. };
  84. }
  85. module.exports = mercury;