properties.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. Language: .properties
  3. Contributors: Valentin Aitken <valentin@nalisbg.com>, Egor Rogov <e.rogov@postgrespro.ru>
  4. Website: https://en.wikipedia.org/wiki/.properties
  5. Category: common, config
  6. */
  7. function properties(hljs) {
  8. // whitespaces: space, tab, formfeed
  9. var WS0 = '[ \\t\\f]*';
  10. var WS1 = '[ \\t\\f]+';
  11. // delimiter
  12. var EQUAL_DELIM = WS0+'[:=]'+WS0;
  13. var WS_DELIM = WS1;
  14. var DELIM = '(' + EQUAL_DELIM + '|' + WS_DELIM + ')';
  15. var KEY_ALPHANUM = '([^\\\\\\W:= \\t\\f\\n]|\\\\.)+';
  16. var KEY_OTHER = '([^\\\\:= \\t\\f\\n]|\\\\.)+';
  17. var DELIM_AND_VALUE = {
  18. // skip DELIM
  19. end: DELIM,
  20. relevance: 0,
  21. starts: {
  22. // value: everything until end of line (again, taking into account backslashes)
  23. className: 'string',
  24. end: /$/,
  25. relevance: 0,
  26. contains: [
  27. { begin: '\\\\\\\\'},
  28. { begin: '\\\\\\n' }
  29. ]
  30. }
  31. };
  32. return {
  33. name: '.properties',
  34. case_insensitive: true,
  35. illegal: /\S/,
  36. contains: [
  37. hljs.COMMENT('^\\s*[!#]', '$'),
  38. // key: everything until whitespace or = or : (taking into account backslashes)
  39. // case of a "normal" key
  40. {
  41. returnBegin: true,
  42. variants: [
  43. { begin: KEY_ALPHANUM + EQUAL_DELIM, relevance: 1 },
  44. { begin: KEY_ALPHANUM + WS_DELIM, relevance: 0 }
  45. ],
  46. contains: [
  47. {
  48. className: 'attr',
  49. begin: KEY_ALPHANUM,
  50. endsParent: true,
  51. relevance: 0
  52. }
  53. ],
  54. starts: DELIM_AND_VALUE
  55. },
  56. // case of key containing non-alphanumeric chars => relevance = 0
  57. {
  58. begin: KEY_OTHER + DELIM,
  59. returnBegin: true,
  60. relevance: 0,
  61. contains: [
  62. {
  63. className: 'meta',
  64. begin: KEY_OTHER,
  65. endsParent: true,
  66. relevance: 0
  67. }
  68. ],
  69. starts: DELIM_AND_VALUE
  70. },
  71. // case of an empty key
  72. {
  73. className: 'attr',
  74. relevance: 0,
  75. begin: KEY_OTHER + WS0 + '$'
  76. }
  77. ]
  78. };
  79. }
  80. module.exports = properties;