mercury.js 3.3 KB

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