sml.js 2.0 KB

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