You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
13 KiB

  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. /*
  4. Gherkin mode - http://www.cukes.info/
  5. Report bugs/issues here: https://github.com/codemirror/CodeMirror/issues
  6. */
  7. // Following Objs from Brackets implementation: https://github.com/tregusti/brackets-gherkin/blob/master/main.js
  8. //var Quotes = {
  9. // SINGLE: 1,
  10. // DOUBLE: 2
  11. //};
  12. //var regex = {
  13. // keywords: /(Feature| {2}(Scenario|In order to|As|I)| {4}(Given|When|Then|And))/
  14. //};
  15. (function(mod) {
  16. if (typeof exports == "object" && typeof module == "object") // CommonJS
  17. mod(require("../../lib/codemirror"));
  18. else if (typeof define == "function" && define.amd) // AMD
  19. define(["../../lib/codemirror"], mod);
  20. else // Plain browser env
  21. mod(CodeMirror);
  22. })(function(CodeMirror) {
  23. "use strict";
  24. CodeMirror.defineMode("gherkin", function () {
  25. return {
  26. startState: function () {
  27. return {
  28. lineNumber: 0,
  29. tableHeaderLine: false,
  30. allowFeature: true,
  31. allowBackground: false,
  32. allowScenario: false,
  33. allowSteps: false,
  34. allowPlaceholders: false,
  35. allowMultilineArgument: false,
  36. inMultilineString: false,
  37. inMultilineTable: false,
  38. inKeywordLine: false
  39. };
  40. },
  41. token: function (stream, state) {
  42. if (stream.sol()) {
  43. state.lineNumber++;
  44. state.inKeywordLine = false;
  45. if (state.inMultilineTable) {
  46. state.tableHeaderLine = false;
  47. if (!stream.match(/\s*\|/, false)) {
  48. state.allowMultilineArgument = false;
  49. state.inMultilineTable = false;
  50. }
  51. }
  52. }
  53. stream.eatSpace();
  54. if (state.allowMultilineArgument) {
  55. // STRING
  56. if (state.inMultilineString) {
  57. if (stream.match('"""')) {
  58. state.inMultilineString = false;
  59. state.allowMultilineArgument = false;
  60. } else {
  61. stream.match(/.*/);
  62. }
  63. return "string";
  64. }
  65. // TABLE
  66. if (state.inMultilineTable) {
  67. if (stream.match(/\|\s*/)) {
  68. return "bracket";
  69. } else {
  70. stream.match(/[^\|]*/);
  71. return state.tableHeaderLine ? "header" : "string";
  72. }
  73. }
  74. // DETECT START
  75. if (stream.match('"""')) {
  76. // String
  77. state.inMultilineString = true;
  78. return "string";
  79. } else if (stream.match("|")) {
  80. // Table
  81. state.inMultilineTable = true;
  82. state.tableHeaderLine = true;
  83. return "bracket";
  84. }
  85. }
  86. // LINE COMMENT
  87. if (stream.match(/#.*/)) {
  88. return "comment";
  89. // TAG
  90. } else if (!state.inKeywordLine && stream.match(/@\S+/)) {
  91. return "tag";
  92. // FEATURE
  93. } else if (!state.inKeywordLine && state.allowFeature && stream.match(/(機能|功能|フィーチャ|기능|โครงหลัก|ความสามารถ|ความต้องการทางธุรกิจ|ಹೆಚ್ಚಳ|గుణము|ਮੁਹਾਂਦਰਾ|ਨਕਸ਼ ਨੁਹਾਰ|ਖਾਸੀਅਤ|रूप लेख|وِیژگی|خاصية|תכונה|Функціонал|Функция|Функционалност|Функционал|Үзенчәлеклелек|Свойство|Особина|Мөмкинлек|Могућност|Λειτουργία|Δυνατότητα|Właściwość|Vlastnosť|Trajto|Tính năng|Savybė|Pretty much|Požiadavka|Požadavek|Potrzeba biznesowa|Özellik|Osobina|Ominaisuus|Omadus|OH HAI|Mogućnost|Mogucnost|Jellemző|Hwæt|Hwaet|Funzionalità|Funktionalitéit|Funktionalität|Funkcja|Funkcionalnost|Funkcionalitāte|Funkcia|Fungsi|Functionaliteit|Funcționalitate|Funcţionalitate|Functionalitate|Funcionalitat|Funcionalidade|Fonctionnalité|Fitur|Fīča|Feature|Eiginleiki|Egenskap|Egenskab|Característica|Caracteristica|Business Need|Aspekt|Arwedd|Ahoy matey!|Ability):/)) {
  94. state.allowScenario = true;
  95. state.allowBackground = true;
  96. state.allowPlaceholders = false;
  97. state.allowSteps = false;
  98. state.allowMultilineArgument = false;
  99. state.inKeywordLine = true;
  100. return "keyword";
  101. // BACKGROUND
  102. } else if (!state.inKeywordLine && state.allowBackground && stream.match(/(背景|배경|แนวคิด|ಹಿನ್ನೆಲೆ|నేపథ్యం|ਪਿਛੋਕੜ|पृष्ठभूमि|زمینه|الخلفية|רקע|Тарих|Предыстория|Предистория|Позадина|Передумова|Основа|Контекст|Кереш|Υπόβαθρο|Założenia|Yo\-ho\-ho|Tausta|Taust|Situācija|Rerefons|Pozadina|Pozadie|Pozadí|Osnova|Latar Belakang|Kontext|Konteksts|Kontekstas|Kontekst|Háttér|Hannergrond|Grundlage|Geçmiş|Fundo|Fono|First off|Dis is what went down|Dasar|Contexto|Contexte|Context|Contesto|Cenário de Fundo|Cenario de Fundo|Cefndir|Bối cảnh|Bakgrunnur|Bakgrunn|Bakgrund|Baggrund|Background|B4|Antecedents|Antecedentes|Ær|Aer|Achtergrond):/)) {
  103. state.allowPlaceholders = false;
  104. state.allowSteps = true;
  105. state.allowBackground = false;
  106. state.allowMultilineArgument = false;
  107. state.inKeywordLine = true;
  108. return "keyword";
  109. // SCENARIO OUTLINE
  110. } else if (!state.inKeywordLine && state.allowScenario && stream.match(/(場景大綱|场景大纲|劇本大綱|剧本大纲|テンプレ|シナリオテンプレート|シナリオテンプレ|シナリオアウトライン|시나리오 개요|สรุปเหตุการณ์|โครงสร้างของเหตุการณ์|ವಿವರಣೆ|కథనం|ਪਟਕਥਾ ਰੂਪ ਰੇਖਾ|ਪਟਕਥਾ ਢਾਂਚਾ|परिदृश्य रूपरेखा|سيناريو مخطط|الگوی سناریو|תבנית תרחיש|Сценарийның төзелеше|Сценарий структураси|Структура сценарію|Структура сценария|Структура сценарија|Скица|Рамка на сценарий|Концепт|Περιγραφή Σεναρίου|Wharrimean is|Template Situai|Template Senario|Template Keadaan|Tapausaihio|Szenariogrundriss|Szablon scenariusza|Swa hwær swa|Swa hwaer swa|Struktura scenarija|Structură scenariu|Structura scenariu|Skica|Skenario konsep|Shiver me timbers|Senaryo taslağı|Schema dello scenario|Scenariomall|Scenariomal|Scenario Template|Scenario Outline|Scenario Amlinellol|Scenārijs pēc parauga|Scenarijaus šablonas|Reckon it's like|Raamstsenaarium|Plang vum Szenario|Plan du Scénario|Plan du scénario|Osnova scénáře|Osnova Scenára|Náčrt Scenáru|Náčrt Scénáře|Náčrt Scenára|MISHUN SRSLY|Menggariskan Senario|Lýsing Dæma|Lýsing Atburðarásar|Konturo de la scenaro|Koncept|Khung tình huống|Khung kịch bản|Forgatókönyv vázlat|Esquema do Cenário|Esquema do Cenario|Esquema del escenario|Esquema de l'escenari|Esbozo do escenario|Delineação do Cenário|Delineacao do Cenario|All y'all|Abstrakt Scenario|Abstract Scenario):/)) {
  111. state.allowPlaceholders = true;
  112. state.allowSteps = true;
  113. state.allowMultilineArgument = false;
  114. state.inKeywordLine = true;
  115. return "keyword";
  116. // EXAMPLES
  117. } else if (state.allowScenario && stream.match(/(例子|例|サンプル|예|ชุดของเหตุการณ์|ชุดของตัวอย่าง|ಉದಾಹರಣೆಗಳು|ఉదాహరణలు|ਉਦਾਹਰਨਾਂ|उदाहरण|نمونه ها|امثلة|דוגמאות|Үрнәкләр|Сценарији|Примеры|Примери|Приклади|Мисоллар|Мисаллар|Σενάρια|Παραδείγματα|You'll wanna|Voorbeelden|Variantai|Tapaukset|Se þe|Se the|Se ðe|Scenarios|Scenariji|Scenarijai|Przykłady|Primjeri|Primeri|Příklady|Príklady|Piemēri|Példák|Pavyzdžiai|Paraugs|Örnekler|Juhtumid|Exemplos|Exemples|Exemple|Exempel|EXAMPLZ|Examples|Esempi|Enghreifftiau|Ekzemploj|Eksempler|Ejemplos|Dữ liệu|Dead men tell no tales|Dæmi|Contoh|Cenários|Cenarios|Beispiller|Beispiele|Atburðarásir):/)) {
  118. state.allowPlaceholders = false;
  119. state.allowSteps = true;
  120. state.allowBackground = false;
  121. state.allowMultilineArgument = true;
  122. return "keyword";
  123. // SCENARIO
  124. } else if (!state.inKeywordLine && state.allowScenario && stream.match(/(場景|场景|劇本|剧本|シナリオ|시나리오|เหตุการณ์|ಕಥಾಸಾರಾಂಶ|సన్నివేశం|ਪਟਕਥਾ|परिदृश्य|سيناريو|سناریو|תרחיש|Сценарій|Сценарио|Сценарий|Пример|Σενάριο|Tình huống|The thing of it is|Tapaus|Szenario|Swa|Stsenaarium|Skenario|Situai|Senaryo|Senario|Scenaro|Scenariusz|Scenariu|Scénario|Scenario|Scenarijus|Scenārijs|Scenarij|Scenarie|Scénář|Scenár|Primer|MISHUN|Kịch bản|Keadaan|Heave to|Forgatókönyv|Escenario|Escenari|Cenário|Cenario|Awww, look mate|Atburðarás):/)) {
  125. state.allowPlaceholders = false;
  126. state.allowSteps = true;
  127. state.allowBackground = false;
  128. state.allowMultilineArgument = false;
  129. state.inKeywordLine = true;
  130. return "keyword";
  131. // STEPS
  132. } else if (!state.inKeywordLine && state.allowSteps && stream.match(/(那麼|那么|而且|當|当|并且|同時|同时|前提|假设|假設|假定|假如|但是|但し|並且|もし|ならば|ただし|しかし|かつ|하지만|조건|먼저|만일|만약|단|그리고|그러면|และ |เมื่อ |แต่ |ดังนั้น |กำหนดให้ |ಸ್ಥಿತಿಯನ್ನು |ಮತ್ತು |ನೀಡಿದ |ನಂತರ |ಆದರೆ |మరియు |చెప్పబడినది |కాని |ఈ పరిస్థితిలో |అప్పుడు |ਪਰ |ਤਦ |ਜੇਕਰ |ਜਿਵੇਂ ਕਿ |ਜਦੋਂ |ਅਤੇ |यदि |परन्तु |पर |तब |तदा |तथा |जब |चूंकि |किन्तु |कदा |और |अगर |و |هنگامی |متى |لكن |عندما |ثم |بفرض |با فرض |اما |اذاً |آنگاه |כאשר |וגם |בהינתן |אזי |אז |אבל |Якщо |Һәм |Унда |Тоді |Тогда |То |Также |Та |Пусть |Припустимо, що |Припустимо |Онда |Но |Нехай |Нәтиҗәдә |Лекин |Ләкин |Коли |Когда |Когато |Када |Кад |К тому же |І |И |Задато |Задати |Задате |Если |Допустим |Дано |Дадено |Вә |Ва |Бирок |Әмма |Әйтик |Әгәр |Аммо |Али |Але |Агар |А також |А |Τότε |Όταν |Και |Δεδομένου |Αλλά |Þurh |Þegar |Þa þe |Þá |Þa |Zatati |Zakładając |Zadato |Zadate |Zadano |Zadani |Zadan |Za předpokladu |Za predpokladu |Youse know when youse got |Youse know like when |Yna |Yeah nah |Y'know |Y |Wun |Wtedy |When y'all |When |Wenn |WEN |wann |Ve |Và |Und |Un |ugeholl |Too right |Thurh |Thì |Then y'all |Then |Tha the |Tha |Tetapi |Tapi |Tak |Tada |Tad |Stel |Soit |Siis |Și |Şi |Si |Sed |Se |Så |Quando |Quand |Quan |Pryd |Potom |Pokud |Pokiaľ |Però |Pero |Pak |Oraz |Onda |Ond |Oletetaan |Og |Och |O zaman |Niin |Nhưng |När |Når |Mutta |Men |Mas |Maka |Majd |Mając |Mais |Maar |mä |Ma |Lorsque |Lorsqu'|Logo |Let go and haul |Kun |Kuid |Kui |Kiedy |Khi |Ketika |Kemudian |Keď |Když |Kaj |Kai |Kada |Kad |Jeżeli |Jeśli |Ja |It's just unbelievable |Ir |I CAN HAZ |I |Ha |Givun |Givet |Given y'all |Given |Gitt |Gegeven |Gegeben seien |Gegeben sei |Gdy |Gangway! |Fakat |Étant donnés |Etant donnés |Étant données |Etant données |Étant donnée |Etant donnée |Étant donné |Etant donné |Et |És |Entonces |Entón |Então |Entao |En |Eğer ki |Ef |Eeldades |E |Ðurh |Duota |Dun |Donitaĵo |Donat |Donada |Do |Diyelim ki |Diberi |Dengan |Den youse gotta |DEN |De |Dato |Dați fiind |Daţi fiind |Dati fiind |Dati |Date fiind |Date |Data |Dat fiind |Dar |Dann |dann |Dan |Dados |Dado |Dadas |Dada |Ða ðe |Ða |Cuando |Cho |Cando |Când |Cand |Cal |But y'all |But at the end of the day I reckon |BUT |But |Buh |Blimey! |Biết |Bet |Bagi |Aye |awer |Avast! |Atunci |Atesa |Atès |Apabila |Anrhegedig a |Angenommen |And y'all |And |AN |An |an |Amikor |Amennyiben |Ama |Als |Alors |Allora |Ali |Aleshores |Ale |Akkor |Ak |Adott |Ac |Aber |A zároveň |A tiež |A taktiež |A také |A |a |7 |\* )/)) {
  133. state.inStep = true;
  134. state.allowPlaceholders = true;
  135. state.allowMultilineArgument = true;
  136. state.inKeywordLine = true;
  137. return "keyword";
  138. // INLINE STRING
  139. } else if (stream.match(/"[^"]*"?/)) {
  140. return "string";
  141. // PLACEHOLDER
  142. } else if (state.allowPlaceholders && stream.match(/<[^>]*>?/)) {
  143. return "variable";
  144. // Fall through
  145. } else {
  146. stream.next();
  147. stream.eatWhile(/[^@"<#]/);
  148. return null;
  149. }
  150. }
  151. };
  152. });
  153. CodeMirror.defineMIME("text/x-feature", "gherkin");
  154. });