mercury.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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, { relevance: 0 });
  42. const STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, { relevance: 0 });
  43. const 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. const IMPLICATION = {
  51. className: 'built_in',
  52. variants: [
  53. { begin: '<=>' },
  54. {
  55. begin: '<=',
  56. relevance: 0
  57. },
  58. {
  59. begin: '=>',
  60. relevance: 0
  61. },
  62. { begin: '/\\\\' },
  63. { begin: '\\\\/' }
  64. ]
  65. };
  66. const HEAD_BODY_CONJUNCTION = {
  67. className: 'built_in',
  68. variants: [
  69. { begin: ':-\\|-->' },
  70. {
  71. begin: '=',
  72. relevance: 0
  73. }
  74. ]
  75. };
  76. return {
  77. name: 'Mercury',
  78. aliases: [
  79. 'm',
  80. 'moo'
  81. ],
  82. keywords: KEYWORDS,
  83. contains: [
  84. IMPLICATION,
  85. HEAD_BODY_CONJUNCTION,
  86. COMMENT,
  87. hljs.C_BLOCK_COMMENT_MODE,
  88. NUMCODE,
  89. hljs.NUMBER_MODE,
  90. ATOM,
  91. STRING,
  92. { // relevance booster
  93. begin: /:-/ },
  94. { // relevance booster
  95. begin: /\.$/ }
  96. ]
  97. };
  98. }
  99. export { mercury as default };