properties.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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: config
  6. */
  7. /** @type LanguageFn */
  8. function properties(hljs) {
  9. // whitespaces: space, tab, formfeed
  10. const WS0 = '[ \\t\\f]*';
  11. const WS1 = '[ \\t\\f]+';
  12. // delimiter
  13. const EQUAL_DELIM = WS0 + '[:=]' + WS0;
  14. const WS_DELIM = WS1;
  15. const DELIM = '(' + EQUAL_DELIM + '|' + WS_DELIM + ')';
  16. const KEY = '([^\\\\:= \\t\\f\\n]|\\\\.)+';
  17. const 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. disableAutodetect: true,
  35. case_insensitive: true,
  36. illegal: /\S/,
  37. contains: [
  38. hljs.COMMENT('^\\s*[!#]', '$'),
  39. // key: everything until whitespace or = or : (taking into account backslashes)
  40. // case of a key-value pair
  41. {
  42. returnBegin: true,
  43. variants: [
  44. { begin: KEY + EQUAL_DELIM },
  45. { begin: KEY + WS_DELIM }
  46. ],
  47. contains: [
  48. {
  49. className: 'attr',
  50. begin: KEY,
  51. endsParent: true
  52. }
  53. ],
  54. starts: DELIM_AND_VALUE
  55. },
  56. // case of an empty key
  57. {
  58. className: 'attr',
  59. begin: KEY + WS0 + '$'
  60. }
  61. ]
  62. };
  63. }
  64. export { properties as default };