sml.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Language: SML (Standard ML)
  3. Author: Edwin Dalorzo <edwin@dalorzo.org>
  4. Description: SML language definition.
  5. Website: https://www.smlnj.org
  6. Origin: ocaml.js
  7. Category: functional
  8. */
  9. function sml(hljs) {
  10. return {
  11. name: 'SML (Standard ML)',
  12. aliases: [ 'ml' ],
  13. keywords: {
  14. $pattern: '[a-z_]\\w*!?',
  15. keyword:
  16. /* according to Definition of Standard ML 97 */
  17. 'abstype and andalso as case datatype do else end eqtype '
  18. + 'exception fn fun functor handle if in include infix infixr '
  19. + 'let local nonfix of op open orelse raise rec sharing sig '
  20. + 'signature struct structure then type val with withtype where while',
  21. built_in:
  22. /* built-in types according to basis library */
  23. 'array bool char exn int list option order real ref string substring vector unit word',
  24. literal:
  25. 'true false NONE SOME LESS EQUAL GREATER nil'
  26. },
  27. illegal: /\/\/|>>/,
  28. contains: [
  29. {
  30. className: 'literal',
  31. begin: /\[(\|\|)?\]|\(\)/,
  32. relevance: 0
  33. },
  34. hljs.COMMENT(
  35. '\\(\\*',
  36. '\\*\\)',
  37. { contains: [ 'self' ] }
  38. ),
  39. { /* type variable */
  40. className: 'symbol',
  41. begin: '\'[A-Za-z_](?!\')[\\w\']*'
  42. /* the grammar is ambiguous on how 'a'b should be interpreted but not the compiler */
  43. },
  44. { /* polymorphic variant */
  45. className: 'type',
  46. begin: '`[A-Z][\\w\']*'
  47. },
  48. { /* module or constructor */
  49. className: 'type',
  50. begin: '\\b[A-Z][\\w\']*',
  51. relevance: 0
  52. },
  53. { /* don't color identifiers, but safely catch all identifiers with ' */
  54. begin: '[a-z_]\\w*\'[\\w\']*' },
  55. hljs.inherit(hljs.APOS_STRING_MODE, {
  56. className: 'string',
  57. relevance: 0
  58. }),
  59. hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null }),
  60. {
  61. className: 'number',
  62. begin:
  63. '\\b(0[xX][a-fA-F0-9_]+[Lln]?|'
  64. + '0[oO][0-7_]+[Lln]?|'
  65. + '0[bB][01_]+[Lln]?|'
  66. + '[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)',
  67. relevance: 0
  68. },
  69. { begin: /[-=]>/ // relevance booster
  70. }
  71. ]
  72. };
  73. }
  74. export { sml as default };