prism-robotframework.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. (function (Prism) {
  2. var comment = {
  3. pattern: /(^[ \t]*| {2}|\t)#.*/m,
  4. lookbehind: true,
  5. greedy: true
  6. };
  7. var variable = {
  8. pattern: /((?:^|[^\\])(?:\\{2})*)[$@&%]\{(?:[^{}\r\n]|\{[^{}\r\n]*\})*\}/,
  9. lookbehind: true,
  10. inside: {
  11. 'punctuation': /^[$@&%]\{|\}$/
  12. }
  13. };
  14. function createSection(name, inside) {
  15. var extendecInside = {};
  16. extendecInside['section-header'] = {
  17. pattern: /^ ?\*{3}.+?\*{3}/,
  18. alias: 'keyword'
  19. };
  20. // copy inside tokens
  21. for (var token in inside) {
  22. extendecInside[token] = inside[token];
  23. }
  24. extendecInside['tag'] = {
  25. pattern: /([\r\n](?: {2}|\t)[ \t]*)\[[-\w]+\]/,
  26. lookbehind: true,
  27. inside: {
  28. 'punctuation': /\[|\]/
  29. }
  30. };
  31. extendecInside['variable'] = variable;
  32. extendecInside['comment'] = comment;
  33. return {
  34. pattern: RegExp(/^ ?\*{3}[ \t]*<name>[ \t]*\*{3}(?:.|[\r\n](?!\*{3}))*/.source.replace(/<name>/g, function () { return name; }), 'im'),
  35. alias: 'section',
  36. inside: extendecInside
  37. };
  38. }
  39. var docTag = {
  40. pattern: /(\[Documentation\](?: {2}|\t)[ \t]*)(?![ \t]|#)(?:.|(?:\r\n?|\n)[ \t]*\.{3})+/,
  41. lookbehind: true,
  42. alias: 'string'
  43. };
  44. var testNameLike = {
  45. pattern: /([\r\n] ?)(?!#)(?:\S(?:[ \t]\S)*)+/,
  46. lookbehind: true,
  47. alias: 'function',
  48. inside: {
  49. 'variable': variable
  50. }
  51. };
  52. var testPropertyLike = {
  53. pattern: /([\r\n](?: {2}|\t)[ \t]*)(?!\[|\.{3}|#)(?:\S(?:[ \t]\S)*)+/,
  54. lookbehind: true,
  55. inside: {
  56. 'variable': variable
  57. }
  58. };
  59. Prism.languages['robotframework'] = {
  60. 'settings': createSection('Settings', {
  61. 'documentation': {
  62. pattern: /([\r\n] ?Documentation(?: {2}|\t)[ \t]*)(?![ \t]|#)(?:.|(?:\r\n?|\n)[ \t]*\.{3})+/,
  63. lookbehind: true,
  64. alias: 'string'
  65. },
  66. 'property': {
  67. pattern: /([\r\n] ?)(?!\.{3}|#)(?:\S(?:[ \t]\S)*)+/,
  68. lookbehind: true
  69. }
  70. }),
  71. 'variables': createSection('Variables'),
  72. 'test-cases': createSection('Test Cases', {
  73. 'test-name': testNameLike,
  74. 'documentation': docTag,
  75. 'property': testPropertyLike
  76. }),
  77. 'keywords': createSection('Keywords', {
  78. 'keyword-name': testNameLike,
  79. 'documentation': docTag,
  80. 'property': testPropertyLike
  81. }),
  82. 'tasks': createSection('Tasks', {
  83. 'task-name': testNameLike,
  84. 'documentation': docTag,
  85. 'property': testPropertyLike
  86. }),
  87. 'comment': comment
  88. };
  89. Prism.languages.robot = Prism.languages['robotframework'];
  90. }(Prism));