benhamill-gherkin 2.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.gitattributes +2 -0
  2. data/.gitignore +11 -0
  3. data/.mailmap +2 -0
  4. data/.rspec +1 -0
  5. data/.rvmrc +1 -0
  6. data/Gemfile +7 -0
  7. data/History.txt +363 -0
  8. data/LICENSE +20 -0
  9. data/README.rdoc +149 -0
  10. data/Rakefile +19 -0
  11. data/VERSION +1 -0
  12. data/build_native_gems.sh +8 -0
  13. data/cucumber.yml +3 -0
  14. data/features/escaped_pipes.feature +8 -0
  15. data/features/feature_parser.feature +237 -0
  16. data/features/json_formatter.feature +377 -0
  17. data/features/json_parser.feature +318 -0
  18. data/features/native_lexer.feature +19 -0
  19. data/features/parser_with_native_lexer.feature +205 -0
  20. data/features/pretty_formatter.feature +15 -0
  21. data/features/step_definitions/eyeball_steps.rb +3 -0
  22. data/features/step_definitions/gherkin_steps.rb +29 -0
  23. data/features/step_definitions/json_formatter_steps.rb +28 -0
  24. data/features/step_definitions/json_parser_steps.rb +20 -0
  25. data/features/step_definitions/pretty_formatter_steps.rb +84 -0
  26. data/features/steps_parser.feature +46 -0
  27. data/features/support/env.rb +38 -0
  28. data/gherkin.gemspec +61 -0
  29. data/ikvm/.gitignore +3 -0
  30. data/java/.gitignore +5 -0
  31. data/java/src/main/java/gherkin/lexer/i18n/.gitignore +1 -0
  32. data/java/src/main/resources/gherkin/.gitignore +1 -0
  33. data/js/lib/gherkin/lexer/i18n/ar.js +1094 -0
  34. data/js/lib/gherkin/lexer/i18n/bg.js +1308 -0
  35. data/js/lib/gherkin/lexer/i18n/ca.js +1236 -0
  36. data/js/lib/gherkin/lexer/i18n/cs.js +1090 -0
  37. data/js/lib/gherkin/lexer/i18n/cy_gb.js +958 -0
  38. data/js/lib/gherkin/lexer/i18n/da.js +974 -0
  39. data/js/lib/gherkin/lexer/i18n/de.js +1082 -0
  40. data/js/lib/gherkin/lexer/i18n/en.js +965 -0
  41. data/js/lib/gherkin/lexer/i18n/en_au.js +902 -0
  42. data/js/lib/gherkin/lexer/i18n/en_lol.js +859 -0
  43. data/js/lib/gherkin/lexer/i18n/en_pirate.js +1136 -0
  44. data/js/lib/gherkin/lexer/i18n/en_scouse.js +1289 -0
  45. data/js/lib/gherkin/lexer/i18n/en_tx.js +942 -0
  46. data/js/lib/gherkin/lexer/i18n/eo.js +916 -0
  47. data/js/lib/gherkin/lexer/i18n/es.js +1049 -0
  48. data/js/lib/gherkin/lexer/i18n/et.js +915 -0
  49. data/js/lib/gherkin/lexer/i18n/fi.js +894 -0
  50. data/js/lib/gherkin/lexer/i18n/fr.js +1116 -0
  51. data/js/lib/gherkin/lexer/i18n/he.js +1044 -0
  52. data/js/lib/gherkin/lexer/i18n/hr.js +994 -0
  53. data/js/lib/gherkin/lexer/i18n/hu.js +1043 -0
  54. data/js/lib/gherkin/lexer/i18n/id.js +884 -0
  55. data/js/lib/gherkin/lexer/i18n/it.js +1007 -0
  56. data/js/lib/gherkin/lexer/i18n/ja.js +1344 -0
  57. data/js/lib/gherkin/lexer/i18n/ko.js +1028 -0
  58. data/js/lib/gherkin/lexer/i18n/lt.js +972 -0
  59. data/js/lib/gherkin/lexer/i18n/lu.js +1057 -0
  60. data/js/lib/gherkin/lexer/i18n/lv.js +1092 -0
  61. data/js/lib/gherkin/lexer/i18n/nl.js +1036 -0
  62. data/js/lib/gherkin/lexer/i18n/no.js +986 -0
  63. data/js/lib/gherkin/lexer/i18n/pl.js +1140 -0
  64. data/js/lib/gherkin/lexer/i18n/pt.js +1000 -0
  65. data/js/lib/gherkin/lexer/i18n/ro.js +1089 -0
  66. data/js/lib/gherkin/lexer/i18n/ru.js +1560 -0
  67. data/js/lib/gherkin/lexer/i18n/sk.js +972 -0
  68. data/js/lib/gherkin/lexer/i18n/sr_cyrl.js +1728 -0
  69. data/js/lib/gherkin/lexer/i18n/sr_latn.js +1220 -0
  70. data/js/lib/gherkin/lexer/i18n/sv.js +997 -0
  71. data/js/lib/gherkin/lexer/i18n/tr.js +1014 -0
  72. data/js/lib/gherkin/lexer/i18n/uk.js +1572 -0
  73. data/js/lib/gherkin/lexer/i18n/uz.js +1302 -0
  74. data/js/lib/gherkin/lexer/i18n/vi.js +1124 -0
  75. data/js/lib/gherkin/lexer/i18n/zh_cn.js +902 -0
  76. data/js/lib/gherkin/lexer/i18n/zh_tw.js +940 -0
  77. data/lib/.gitignore +4 -0
  78. data/lib/gherkin.rb +2 -0
  79. data/lib/gherkin/c_lexer.rb +17 -0
  80. data/lib/gherkin/formatter/ansi_escapes.rb +95 -0
  81. data/lib/gherkin/formatter/argument.rb +16 -0
  82. data/lib/gherkin/formatter/escaping.rb +15 -0
  83. data/lib/gherkin/formatter/filter_formatter.rb +136 -0
  84. data/lib/gherkin/formatter/hashable.rb +19 -0
  85. data/lib/gherkin/formatter/json_formatter.rb +102 -0
  86. data/lib/gherkin/formatter/line_filter.rb +26 -0
  87. data/lib/gherkin/formatter/model.rb +236 -0
  88. data/lib/gherkin/formatter/pretty_formatter.rb +243 -0
  89. data/lib/gherkin/formatter/regexp_filter.rb +21 -0
  90. data/lib/gherkin/formatter/step_printer.rb +17 -0
  91. data/lib/gherkin/formatter/tag_count_formatter.rb +47 -0
  92. data/lib/gherkin/formatter/tag_filter.rb +19 -0
  93. data/lib/gherkin/i18n.rb +175 -0
  94. data/lib/gherkin/i18n.yml +588 -0
  95. data/lib/gherkin/json_parser.rb +137 -0
  96. data/lib/gherkin/lexer/i18n_lexer.rb +47 -0
  97. data/lib/gherkin/listener/event.rb +45 -0
  98. data/lib/gherkin/listener/formatter_listener.rb +113 -0
  99. data/lib/gherkin/native.rb +7 -0
  100. data/lib/gherkin/native/ikvm.rb +55 -0
  101. data/lib/gherkin/native/java.rb +55 -0
  102. data/lib/gherkin/native/null.rb +9 -0
  103. data/lib/gherkin/parser/meta.txt +5 -0
  104. data/lib/gherkin/parser/parser.rb +164 -0
  105. data/lib/gherkin/parser/root.txt +11 -0
  106. data/lib/gherkin/parser/steps.txt +4 -0
  107. data/lib/gherkin/rb_lexer.rb +8 -0
  108. data/lib/gherkin/rb_lexer/.gitignore +1 -0
  109. data/lib/gherkin/rb_lexer/README.rdoc +8 -0
  110. data/lib/gherkin/rubify.rb +24 -0
  111. data/lib/gherkin/tag_expression.rb +62 -0
  112. data/lib/gherkin/version.rb +3 -0
  113. data/ragel/i18n/.gitignore +1 -0
  114. data/ragel/lexer.c.rl.erb +439 -0
  115. data/ragel/lexer.java.rl.erb +208 -0
  116. data/ragel/lexer.rb.rl.erb +167 -0
  117. data/ragel/lexer_common.rl.erb +50 -0
  118. data/spec/gherkin/c_lexer_spec.rb +21 -0
  119. data/spec/gherkin/fixtures/1.feature +8 -0
  120. data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
  121. data/spec/gherkin/fixtures/complex.feature +45 -0
  122. data/spec/gherkin/fixtures/complex.json +143 -0
  123. data/spec/gherkin/fixtures/complex_for_filtering.feature +60 -0
  124. data/spec/gherkin/fixtures/complex_with_tags.feature +61 -0
  125. data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
  126. data/spec/gherkin/fixtures/hantu_pisang.feature +35 -0
  127. data/spec/gherkin/fixtures/i18n_fr.feature +14 -0
  128. data/spec/gherkin/fixtures/i18n_no.feature +7 -0
  129. data/spec/gherkin/fixtures/i18n_zh-CN.feature +9 -0
  130. data/spec/gherkin/fixtures/scenario_outline_with_tags.feature +13 -0
  131. data/spec/gherkin/fixtures/scenario_without_steps.feature +5 -0
  132. data/spec/gherkin/fixtures/simple_with_comments.feature +7 -0
  133. data/spec/gherkin/fixtures/simple_with_tags.feature +11 -0
  134. data/spec/gherkin/fixtures/with_bom.feature +3 -0
  135. data/spec/gherkin/formatter/ansi_escapes_spec.rb +19 -0
  136. data/spec/gherkin/formatter/filter_formatter_spec.rb +165 -0
  137. data/spec/gherkin/formatter/model_spec.rb +28 -0
  138. data/spec/gherkin/formatter/pretty_formatter_spec.rb +158 -0
  139. data/spec/gherkin/formatter/spaces.feature +9 -0
  140. data/spec/gherkin/formatter/step_printer_spec.rb +55 -0
  141. data/spec/gherkin/formatter/tabs.feature +9 -0
  142. data/spec/gherkin/formatter/tag_count_formatter_spec.rb +30 -0
  143. data/spec/gherkin/i18n_spec.rb +152 -0
  144. data/spec/gherkin/java_lexer_spec.rb +20 -0
  145. data/spec/gherkin/java_libs.rb +20 -0
  146. data/spec/gherkin/json_parser_spec.rb +113 -0
  147. data/spec/gherkin/lexer/i18n_lexer_spec.rb +43 -0
  148. data/spec/gherkin/output_stream_string_io.rb +20 -0
  149. data/spec/gherkin/parser/parser_spec.rb +16 -0
  150. data/spec/gherkin/rb_lexer_spec.rb +19 -0
  151. data/spec/gherkin/sexp_recorder.rb +56 -0
  152. data/spec/gherkin/shared/lexer_group.rb +593 -0
  153. data/spec/gherkin/shared/py_string_group.rb +153 -0
  154. data/spec/gherkin/shared/row_group.rb +125 -0
  155. data/spec/gherkin/shared/tags_group.rb +54 -0
  156. data/spec/gherkin/tag_expression_spec.rb +137 -0
  157. data/spec/spec_helper.rb +69 -0
  158. data/tasks/bench.rake +184 -0
  159. data/tasks/bench/feature_builder.rb +49 -0
  160. data/tasks/bench/generated/.gitignore +1 -0
  161. data/tasks/bench/null_listener.rb +4 -0
  162. data/tasks/compile.rake +102 -0
  163. data/tasks/cucumber.rake +20 -0
  164. data/tasks/gems.rake +35 -0
  165. data/tasks/ikvm.rake +79 -0
  166. data/tasks/ragel_task.rb +70 -0
  167. data/tasks/rdoc.rake +9 -0
  168. data/tasks/release.rake +30 -0
  169. data/tasks/rspec.rake +8 -0
  170. metadata +609 -0
@@ -0,0 +1,208 @@
1
+ package gherkin.lexer.i18n;
2
+
3
+ import java.io.UnsupportedEncodingException;
4
+ import java.util.List;
5
+ import java.util.ArrayList;
6
+ import java.util.regex.Pattern;
7
+ import gherkin.lexer.Lexer;
8
+ import gherkin.lexer.Listener;
9
+ import gherkin.lexer.LexingError;
10
+
11
+ public class <%= @i18n.underscored_iso_code.upcase %> implements Lexer {
12
+ %%{
13
+ machine lexer;
14
+ alphtype byte;
15
+
16
+ action begin_content {
17
+ contentStart = p;
18
+ currentLine = lineNumber;
19
+ if(keyword != null) {
20
+ startCol = p - lastNewline - (keyword.length() + 1);
21
+ }
22
+ }
23
+
24
+ action start_pystring {
25
+ currentLine = lineNumber;
26
+ startCol = p - lastNewline;
27
+ }
28
+
29
+ action begin_pystring_content {
30
+ contentStart = p;
31
+ }
32
+
33
+ action store_pystring_content {
34
+ String con = unindent(startCol, substring(data, contentStart, nextKeywordStart-1).replaceFirst("(\\r?\\n)?([\\t ])*\\Z", "").replaceAll("\\\\\"\\\\\"\\\\\"", "\"\"\""));
35
+ listener.pyString(con, currentLine);
36
+ }
37
+
38
+ action store_feature_content {
39
+ String[] nameDescription = nameAndUnindentedDescription(startCol, keywordContent(data, p, eof, nextKeywordStart, contentStart));
40
+ listener.feature(keyword, nameDescription[0], nameDescription[1], currentLine);
41
+ if(nextKeywordStart != -1) p = nextKeywordStart - 1;
42
+ nextKeywordStart = -1;
43
+ }
44
+
45
+ action store_background_content {
46
+ String[] nameDescription = nameAndUnindentedDescription(startCol, keywordContent(data, p, eof, nextKeywordStart, contentStart));
47
+ listener.background(keyword, nameDescription[0], nameDescription[1], currentLine);
48
+ if(nextKeywordStart != -1) p = nextKeywordStart - 1;
49
+ nextKeywordStart = -1;
50
+ }
51
+
52
+ action store_scenario_content {
53
+ String[] nameDescription = nameAndUnindentedDescription(startCol, keywordContent(data, p, eof, nextKeywordStart, contentStart));
54
+ listener.scenario(keyword, nameDescription[0], nameDescription[1], currentLine);
55
+ if(nextKeywordStart != -1) p = nextKeywordStart - 1;
56
+ nextKeywordStart = -1;
57
+ }
58
+
59
+ action store_scenario_outline_content {
60
+ String[] nameDescription = nameAndUnindentedDescription(startCol, keywordContent(data, p, eof, nextKeywordStart, contentStart));
61
+ listener.scenarioOutline(keyword, nameDescription[0], nameDescription[1], currentLine);
62
+ if(nextKeywordStart != -1) p = nextKeywordStart - 1;
63
+ nextKeywordStart = -1;
64
+ }
65
+
66
+ action store_examples_content {
67
+ String[] nameDescription = nameAndUnindentedDescription(startCol, keywordContent(data, p, eof, nextKeywordStart, contentStart));
68
+ listener.examples(keyword, nameDescription[0], nameDescription[1], currentLine);
69
+ if(nextKeywordStart != -1) p = nextKeywordStart - 1;
70
+ nextKeywordStart = -1;
71
+ }
72
+
73
+ action store_step_content {
74
+ listener.step(keyword, substring(data, contentStart, p).trim(), currentLine);
75
+ }
76
+
77
+ action store_comment_content {
78
+ listener.comment(substring(data, contentStart, p).trim(), lineNumber);
79
+ keywordStart = -1;
80
+ }
81
+
82
+ action store_tag_content {
83
+ listener.tag(substring(data, contentStart, p).trim(), currentLine);
84
+ keywordStart = -1;
85
+ }
86
+
87
+ action inc_line_number {
88
+ lineNumber++;
89
+ }
90
+
91
+ action last_newline {
92
+ lastNewline = p + 1;
93
+ }
94
+
95
+ action start_keyword {
96
+ if(keywordStart == -1) keywordStart = p;
97
+ }
98
+
99
+ action end_keyword {
100
+ keyword = substring(data, keywordStart, p).replaceFirst(":$","");
101
+ keywordStart = -1;
102
+ }
103
+
104
+ action next_keyword_start {
105
+ nextKeywordStart = p;
106
+ }
107
+
108
+ action start_row {
109
+ p = p - 1;
110
+ currentRow = new ArrayList<String>();
111
+ currentLine = lineNumber;
112
+ }
113
+
114
+ action begin_cell_content {
115
+ contentStart = p;
116
+ }
117
+
118
+ action store_cell_content {
119
+ String con = substring(data, contentStart, p).trim();
120
+ currentRow.add(con
121
+ .replaceAll("\\\\\\|", "|")
122
+ .replaceAll("\\\\n", "\n")
123
+ .replaceAll("\\\\\\\\", "\\\\")
124
+ );
125
+ }
126
+
127
+ action store_row {
128
+ listener.row(currentRow, currentLine);
129
+ }
130
+
131
+ action end_feature {
132
+ if(cs < lexer_first_final) {
133
+ String content = currentLineContent(data, lastNewline);
134
+ throw new LexingError("Lexing error on line " + lineNumber + ": '" + content + "'. See http://wiki.github.com/aslakhellesoy/gherkin/lexingerror for more information.");
135
+ } else {
136
+ listener.eof();
137
+ }
138
+ }
139
+
140
+ include lexer_common "lexer_common.<%= @i18n.underscored_iso_code %>.rl";
141
+ }%%
142
+
143
+ private final Listener listener;
144
+
145
+ public <%= @i18n.underscored_iso_code.upcase %>(Listener listener) {
146
+ this.listener = listener;
147
+ }
148
+
149
+ %% write data noerror;
150
+
151
+ public void scan(String source) {
152
+ String input = source + "\n%_FEATURE_END_%";
153
+ byte[] data = null;
154
+ try {
155
+ data = input.getBytes("UTF-8");
156
+ } catch(UnsupportedEncodingException e) {
157
+ throw new RuntimeException(e);
158
+ }
159
+ int cs, p = 0, pe = data.length;
160
+ int eof = pe;
161
+
162
+ int lineNumber = 1;
163
+ int lastNewline = 0;
164
+
165
+ int contentStart = -1;
166
+ int currentLine = -1;
167
+ int startCol = -1;
168
+ int nextKeywordStart = -1;
169
+ int keywordStart = -1;
170
+ String keyword = null;
171
+ List<String> currentRow = null;
172
+
173
+ %% write init;
174
+ %% write exec;
175
+ }
176
+
177
+ private String keywordContent(byte[] data, int p, int eof, int nextKeywordStart, int contentStart) {
178
+ int endPoint = (nextKeywordStart == -1 || (p == eof)) ? p : nextKeywordStart;
179
+ return substring(data, contentStart, endPoint);
180
+ }
181
+
182
+ private String[] nameAndUnindentedDescription(int startCol, String text) {
183
+ String[] lines = text.split("\n");
184
+ String name = lines.length > 0 ? lines[0].trim() : "";
185
+ StringBuffer description = new StringBuffer();
186
+ for(int i = 1; i < lines.length; i++) {
187
+ description.append(lines[i]);
188
+ description.append("\n");
189
+ }
190
+ return new String[]{name, unindent(startCol+2, description.toString()).replaceAll("\\s+$", "")};
191
+ }
192
+
193
+ private String unindent(int startCol, String text) {
194
+ return Pattern.compile("^[\t ]{0," + startCol + "}", Pattern.MULTILINE).matcher(text).replaceAll("");
195
+ }
196
+
197
+ private String currentLineContent(byte[] data, int lastNewline) {
198
+ return substring(data, lastNewline, data.length).trim();
199
+ }
200
+
201
+ private String substring(byte[] data, int start, int end) {
202
+ try {
203
+ return new String(data, start, end-start, "utf-8");
204
+ } catch(java.io.UnsupportedEncodingException e) {
205
+ throw new RuntimeException("Internal error", e);
206
+ }
207
+ }
208
+ }
@@ -0,0 +1,167 @@
1
+ require 'gherkin/lexer/i18n_lexer'
2
+
3
+ module Gherkin
4
+ module RbLexer
5
+ class <%= @i18n.underscored_iso_code.capitalize %> #:nodoc:
6
+ %%{
7
+ machine lexer;
8
+
9
+ action begin_content {
10
+ @content_start = p
11
+ @current_line = @line_number
12
+ @start_col = p - @last_newline - "#{@keyword}:".length
13
+ }
14
+
15
+ action start_pystring {
16
+ @current_line = @line_number
17
+ @start_col = p - @last_newline
18
+ }
19
+
20
+ action begin_pystring_content {
21
+ @content_start = p
22
+ }
23
+
24
+ action store_pystring_content {
25
+ con = unindent(@start_col, utf8_pack(data[@content_start...@next_keyword_start-1]).sub(/(\r?\n)?([\t ])*\Z/, '').gsub(/\\"\\"\\"/, '"""'))
26
+ @listener.py_string(con, @current_line)
27
+ }
28
+
29
+ action store_feature_content {
30
+ p = store_keyword_content(:feature, data, p, eof)
31
+ }
32
+
33
+ action store_background_content {
34
+ p = store_keyword_content(:background, data, p, eof)
35
+ }
36
+
37
+ action store_scenario_content {
38
+ p = store_keyword_content(:scenario, data, p, eof)
39
+ }
40
+
41
+ action store_scenario_outline_content {
42
+ p = store_keyword_content(:scenario_outline, data, p, eof)
43
+ }
44
+
45
+ action store_examples_content {
46
+ p = store_keyword_content(:examples, data, p, eof)
47
+ }
48
+
49
+ action store_step_content {
50
+ con = utf8_pack(data[@content_start...p]).strip
51
+ @listener.step(@keyword, con, @current_line)
52
+ }
53
+
54
+ action store_comment_content {
55
+ con = utf8_pack(data[@content_start...p]).strip
56
+ @listener.comment(con, @line_number)
57
+ @keyword_start = nil
58
+ }
59
+
60
+ action store_tag_content {
61
+ con = utf8_pack(data[@content_start...p]).strip
62
+ @listener.tag(con, @current_line)
63
+ @keyword_start = nil
64
+ }
65
+
66
+ action inc_line_number {
67
+ @line_number += 1
68
+ }
69
+
70
+ action last_newline {
71
+ @last_newline = p + 1
72
+ }
73
+
74
+ action start_keyword {
75
+ @keyword_start ||= p
76
+ }
77
+
78
+ action end_keyword {
79
+ @keyword = utf8_pack(data[@keyword_start...p]).sub(/:$/,'')
80
+ @keyword_start = nil
81
+ }
82
+
83
+ action next_keyword_start {
84
+ @next_keyword_start = p
85
+ }
86
+
87
+ action start_row {
88
+ p = p - 1
89
+ current_row = []
90
+ @current_line = @line_number
91
+ }
92
+
93
+ action begin_cell_content {
94
+ @content_start = p
95
+ }
96
+
97
+ action store_cell_content {
98
+ con = utf8_pack(data[@content_start...p]).strip
99
+ current_row << con.gsub(/\\\|/, "|").gsub(/\\n/, "\n").gsub(/\\\\/, "\\")
100
+ }
101
+
102
+ action store_row {
103
+ @listener.row(current_row, @current_line)
104
+ }
105
+
106
+ action end_feature {
107
+ if cs < lexer_first_final
108
+ content = current_line_content(data, p)
109
+ raise Gherkin::Lexer::LexingError.new("Lexing error on line %d: '%s'. See http://wiki.github.com/aslakhellesoy/gherkin/lexingerror for more information." % [@line_number, content])
110
+ else
111
+ @listener.eof
112
+ end
113
+ }
114
+
115
+ include lexer_common "lexer_common.<%= @i18n.underscored_iso_code %>.rl";
116
+ }%%
117
+
118
+ def initialize(listener)
119
+ @listener = listener
120
+ %% write data;
121
+ end
122
+
123
+ def scan(data)
124
+ data = (data + "\n%_FEATURE_END_%").unpack("c*") # Explicit EOF simplifies things considerably
125
+ eof = pe = data.length
126
+
127
+ @line_number = 1
128
+ @last_newline = 0
129
+
130
+ %% write init;
131
+ %% write exec;
132
+ end
133
+
134
+ def unindent(startcol, text)
135
+ text.gsub(/^[\t ]{0,#{startcol}}/, "")
136
+ end
137
+
138
+ def store_keyword_content(event, data, p, eof)
139
+ end_point = (!@next_keyword_start or (p == eof)) ? p : @next_keyword_start
140
+ content = unindent(@start_col + 2, utf8_pack(data[@content_start...end_point])).rstrip
141
+ content_lines = content.split("\n")
142
+ name = content_lines.shift || ""
143
+ name.strip!
144
+ description = content_lines.join("\n")
145
+ @listener.__send__(event, @keyword, name, description, @current_line)
146
+ @next_keyword_start ? @next_keyword_start - 1 : p
147
+ ensure
148
+ @next_keyword_start = nil
149
+ end
150
+
151
+ def current_line_content(data, p)
152
+ rest = data[@last_newline..-1]
153
+ utf8_pack(rest[0..rest.index(10)||-1]).strip
154
+ end
155
+
156
+ if (RUBY_VERSION =~ /^1\.9/)
157
+ def utf8_pack(array)
158
+ array.pack("c*").force_encoding("UTF-8")
159
+ end
160
+ else
161
+ def utf8_pack(array)
162
+ array.pack("c*")
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,50 @@
1
+ %%{
2
+ machine lexer_common;
3
+
4
+ # Language specific
5
+ I18N_Feature = (<%= ragel_list(@i18n.keywords('feature')) %> ':') >start_keyword %end_keyword;
6
+ I18N_Background = (<%= ragel_list(@i18n.keywords('background')) %> ':') >start_keyword %end_keyword;
7
+ I18N_ScenarioOutline = (<%= ragel_list(@i18n.keywords('scenario_outline')) %> ':') >start_keyword %end_keyword;
8
+ I18N_Scenario = (<%= ragel_list(@i18n.keywords('scenario')) %> ':') >start_keyword %end_keyword;
9
+ I18N_Step = <%= ragel_list(@i18n.step_keywords) %> >start_keyword %end_keyword;
10
+ I18N_Examples = (<%= ragel_list(@i18n.keywords('examples')) %> ':') >start_keyword %end_keyword;
11
+
12
+ EOF = '%_FEATURE_END_%'; # Explicit EOF added before scanning begins
13
+ EOL = ('\n' | '\r\n') @inc_line_number @last_newline;
14
+ BOM = 0xEF 0xBB 0xBF; # http://en.wikipedia.org/wiki/Byte_order_mark
15
+
16
+ PIPE = '|';
17
+ ESCAPED_PIPE = '\\|';
18
+
19
+ FeatureHeadingEnd = EOL+ space* (I18N_Feature | I18N_Background | I18N_Scenario | I18N_ScenarioOutline | I18N_Examples | '@' | '#' | EOF) >next_keyword_start;
20
+ ScenarioHeadingEnd = EOL+ space* ( I18N_Feature | I18N_Background | I18N_Scenario | I18N_ScenarioOutline | I18N_Step | '@' | '#' | EOF ) >next_keyword_start;
21
+ BackgroundHeadingEnd = EOL+ space* ( I18N_Feature | I18N_Scenario | I18N_ScenarioOutline | I18N_Step | '@' | '#'| EOF ) >next_keyword_start;
22
+ ScenarioOutlineHeadingEnd = EOL+ space* ( I18N_Feature | I18N_Scenario | I18N_Step | '@' | '#' | EOF ) >next_keyword_start;
23
+ ExamplesHeadingEnd = EOL+ space* ( I18N_Feature | '|' | '#') >next_keyword_start;
24
+
25
+ FeatureHeading = space* I18N_Feature %begin_content ^FeatureHeadingEnd* :>> FeatureHeadingEnd @store_feature_content;
26
+ BackgroundHeading = space* I18N_Background %begin_content ^BackgroundHeadingEnd* :>> BackgroundHeadingEnd @store_background_content;
27
+ ScenarioHeading = space* I18N_Scenario %begin_content ^ScenarioHeadingEnd* :>> ScenarioHeadingEnd @store_scenario_content;
28
+ ScenarioOutlineHeading = space* I18N_ScenarioOutline %begin_content ^ScenarioOutlineHeadingEnd* :>> ScenarioOutlineHeadingEnd @store_scenario_outline_content;
29
+ ExamplesHeading = space* I18N_Examples %begin_content ^ExamplesHeadingEnd* :>> ExamplesHeadingEnd @store_examples_content;
30
+
31
+ Step = space* I18N_Step %begin_content ^EOL+ %store_step_content :> EOL+;
32
+ Comment = space* '#' >begin_content ^EOL* %store_comment_content :> EOL+;
33
+
34
+ Tag = ( ('@' [^@\r\n\t ]+) >begin_content ) %store_tag_content;
35
+ Tags = space* (Tag space*)+ EOL+;
36
+
37
+ StartRow = space* PIPE >start_row;
38
+ EndRow = EOL space* ^PIPE >next_keyword_start;
39
+ Cell = PIPE (ESCAPED_PIPE | (any - (PIPE|EOL))+ )* >begin_cell_content %store_cell_content;
40
+ RowBody = space* Cell** PIPE :>> (space* EOL+ space*) %store_row;
41
+ Row = StartRow :>> RowBody <: EndRow?;
42
+
43
+ StartPyString = '"""' >start_pystring space* :>> EOL;
44
+ EndPyString = (space* '"""') >next_keyword_start;
45
+ PyString = space* StartPyString %begin_pystring_content (^EOL | EOL)* :>> EndPyString %store_pystring_content space* EOL+;
46
+
47
+ Tokens = BOM? (space | EOL)* (Tags | Comment | FeatureHeading | BackgroundHeading | ScenarioHeading | ScenarioOutlineHeading | ExamplesHeading | Step | Row | PyString)* (space | EOL)* EOF;
48
+
49
+ main := Tokens %end_feature @!end_feature;
50
+ }%%
@@ -0,0 +1,21 @@
1
+ #encoding: utf-8
2
+ unless defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby")
3
+ require 'spec_helper'
4
+ require 'gherkin_lexer_en'
5
+
6
+ module Gherkin
7
+ module Lexer
8
+ describe "C Lexer" do
9
+ before do
10
+ @listener = Gherkin::SexpRecorder.new
11
+ @lexer = Gherkin::CLexer::En.new(@listener)
12
+ end
13
+
14
+ it_should_behave_like "a Gherkin lexer"
15
+ it_should_behave_like "a Gherkin lexer lexing tags"
16
+ it_should_behave_like "a Gherkin lexer lexing py_strings"
17
+ it_should_behave_like "a Gherkin lexer lexing rows"
18
+ end
19
+ end
20
+ end
21
+ end