cucumber 0.6.4 → 0.7.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/History.txt +11 -0
  2. data/Rakefile +3 -5
  3. data/VERSION.yml +3 -3
  4. data/cucumber.gemspec +35 -55
  5. data/cucumber.yml +3 -2
  6. data/examples/i18n/Rakefile +1 -0
  7. data/examples/i18n/en-lol/features/step_definitions/cucumbrz_steps.rb +1 -1
  8. data/examples/i18n/eo/.gitignore +1 -0
  9. data/examples/i18n/eo/Rakefile +6 -0
  10. data/examples/i18n/eo/features/adicio.feature +17 -0
  11. data/examples/i18n/eo/features/divido.feature +10 -0
  12. data/examples/i18n/eo/features/step_definitons/calculator_steps.rb +24 -0
  13. data/examples/i18n/eo/lib/calculator.rb +14 -0
  14. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +1 -1
  15. data/examples/i18n/ru/features/division.feature +1 -1
  16. data/examples/i18n/uk/Rakefile +6 -0
  17. data/examples/i18n/uk/features/addition.feature +11 -0
  18. data/examples/i18n/uk/features/consecutive_calculations.feature +17 -0
  19. data/examples/i18n/uk/features/division.feature +16 -0
  20. data/examples/i18n/uk/features/step_definitons/calculator_steps.rb +19 -0
  21. data/examples/i18n/uk/features/support/env.rb +5 -0
  22. data/examples/i18n/uk/features/support/world.rb +8 -0
  23. data/examples/i18n/uk/lib/calculator.rb +24 -0
  24. data/examples/i18n/uz/features/step_definitons/calculator_steps.rb +1 -1
  25. data/examples/sinatra/features/add.feature +1 -1
  26. data/examples/sinatra/features/step_definitions/add_steps.rb +1 -1
  27. data/examples/sinatra/features/support/env.rb +2 -19
  28. data/examples/sinatra/views/add.erb +7 -5
  29. data/features/announce.feature +46 -39
  30. data/features/background.feature +3 -0
  31. data/features/call_many_steps.feature +1 -1
  32. data/features/cucumber_cli_outlines.feature +12 -0
  33. data/features/drb_server_integration.feature +1 -1
  34. data/features/exception_in_after_block.feature +3 -0
  35. data/features/exception_in_after_step_block.feature +3 -0
  36. data/features/html_formatter/a.html +29 -29
  37. data/features/language_help.feature +57 -52
  38. data/features/multiline_names.feature +1 -0
  39. data/features/step_definitions/cucumber_steps.rb +2 -1
  40. data/features/usage_and_stepdefs_formatter.feature +30 -30
  41. data/features/wire_protocol.feature +12 -9
  42. data/features/wire_protocol_table_diffing.feature +8 -6
  43. data/features/wire_protocol_timeouts.feature +5 -4
  44. data/gem_tasks/treetop.rake +13 -0
  45. data/lib/autotest/cucumber_mixin.rb +1 -1
  46. data/lib/cucumber/ast.rb +1 -0
  47. data/lib/cucumber/ast/background.rb +14 -4
  48. data/lib/cucumber/ast/examples.rb +2 -0
  49. data/lib/cucumber/ast/feature.rb +26 -5
  50. data/lib/cucumber/ast/feature_element.rb +18 -9
  51. data/lib/cucumber/ast/outline_table.rb +13 -1
  52. data/lib/cucumber/ast/py_string.rb +26 -9
  53. data/lib/cucumber/ast/scenario.rb +13 -7
  54. data/lib/cucumber/ast/scenario_outline.rb +18 -6
  55. data/lib/cucumber/ast/step.rb +4 -4
  56. data/lib/cucumber/ast/step_invocation.rb +5 -2
  57. data/lib/cucumber/ast/table.rb +26 -1
  58. data/lib/cucumber/ast/tags.rb +3 -1
  59. data/lib/cucumber/ast/tree_walker.rb +2 -18
  60. data/lib/cucumber/cli/configuration.rb +2 -2
  61. data/lib/cucumber/cli/options.rb +16 -21
  62. data/lib/cucumber/feature_file.rb +25 -7
  63. data/lib/cucumber/formatter/ansicolor.rb +6 -1
  64. data/lib/cucumber/formatter/console.rb +4 -3
  65. data/lib/cucumber/formatter/html.rb +8 -5
  66. data/lib/cucumber/formatter/junit.rb +5 -4
  67. data/lib/cucumber/formatter/pdf.rb +2 -3
  68. data/lib/cucumber/formatter/pretty.rb +5 -5
  69. data/lib/cucumber/formatter/usage.rb +2 -2
  70. data/lib/cucumber/parser.rb +0 -6
  71. data/lib/cucumber/parser/gherkin_builder.rb +142 -0
  72. data/lib/cucumber/platform.rb +0 -2
  73. data/lib/cucumber/rb_support/rb_language.rb +7 -12
  74. data/lib/cucumber/step_mother.rb +4 -26
  75. data/spec/cucumber/ast/background_spec.rb +0 -1
  76. data/spec/cucumber/ast/feature_factory.rb +2 -4
  77. data/spec/cucumber/ast/feature_spec.rb +0 -2
  78. data/spec/cucumber/ast/py_string_spec.rb +2 -13
  79. data/spec/cucumber/ast/scenario_outline_spec.rb +0 -1
  80. data/spec/cucumber/ast/scenario_spec.rb +0 -1
  81. data/spec/cucumber/ast/step_spec.rb +1 -1
  82. data/spec/cucumber/ast/table_spec.rb +2 -2
  83. data/spec/cucumber/cli/main_spec.rb +1 -1
  84. data/spec/cucumber/cli/options_spec.rb +2 -2
  85. data/spec/cucumber/formatter/html_spec.rb +20 -1
  86. data/spec/cucumber/formatter/junit_spec.rb +1 -0
  87. data/spec/cucumber/formatter/spec_helper.rb +7 -5
  88. data/spec/cucumber/rb_support/rb_step_definition_spec.rb +0 -1
  89. data/spec/cucumber/step_mother_spec.rb +2 -2
  90. data/spec/spec_helper.rb +0 -1
  91. metadata +67 -93
  92. data/lib/cucumber/cli/language_help_formatter.rb +0 -72
  93. data/lib/cucumber/filter.rb +0 -43
  94. data/lib/cucumber/languages.yml +0 -536
  95. data/lib/cucumber/parser/common.rb +0 -182
  96. data/lib/cucumber/parser/common.tt +0 -21
  97. data/lib/cucumber/parser/feature.rb +0 -1591
  98. data/lib/cucumber/parser/feature.tt +0 -287
  99. data/lib/cucumber/parser/i18n.tt +0 -35
  100. data/lib/cucumber/parser/natural_language.rb +0 -118
  101. data/lib/cucumber/parser/py_string.rb +0 -285
  102. data/lib/cucumber/parser/py_string.tt +0 -45
  103. data/lib/cucumber/parser/table.rb +0 -314
  104. data/lib/cucumber/parser/table.tt +0 -60
  105. data/lib/cucumber/parser/treetop_ext.rb +0 -54
  106. data/lib/cucumber/tag_expression.rb +0 -41
  107. data/spec/cucumber/ast/feature_element_spec.rb +0 -41
  108. data/spec/cucumber/ast/step_collection_spec.rb +0 -17
  109. data/spec/cucumber/parser/feature_parser_spec.rb +0 -400
  110. data/spec/cucumber/parser/table_parser_spec.rb +0 -52
  111. data/spec/cucumber/tag_expression_spec.rb +0 -125
  112. data/spec/cucumber/treetop_parser/empty_feature.feature +0 -4
  113. data/spec/cucumber/treetop_parser/empty_scenario.feature +0 -9
  114. data/spec/cucumber/treetop_parser/empty_scenario_outline.feature +0 -3
  115. data/spec/cucumber/treetop_parser/fit_scenario.feature +0 -8
  116. data/spec/cucumber/treetop_parser/given_scenario.feature +0 -9
  117. data/spec/cucumber/treetop_parser/invalid_scenario_outlines.feature +0 -7
  118. data/spec/cucumber/treetop_parser/multiline_steps.feature +0 -17
  119. data/spec/cucumber/treetop_parser/multiple_tables.feature +0 -27
  120. data/spec/cucumber/treetop_parser/scenario_outline.feature +0 -16
  121. data/spec/cucumber/treetop_parser/spaces.feature +0 -12
  122. data/spec/cucumber/treetop_parser/test_dos.feature +0 -25
  123. data/spec/cucumber/treetop_parser/with_comments.feature +0 -23
  124. data/spec/cucumber/treetop_parser/with_tags.feature +0 -18
@@ -1,287 +0,0 @@
1
- require 'cucumber/ast/tags'
2
-
3
- module Cucumber
4
- module Parser
5
- # TIP: When you hack on the grammar, just delete feature.rb in this directory.
6
- # Also make sure you have uninstalled all cucumber gems (don't forget xxx-cucumber
7
- # github gems).
8
- #
9
- # Treetop will then generate the parser in-memory. When you're happy, just generate
10
- # the rb file with tt feature.tt
11
- grammar Feature
12
-
13
- rule feature_sub
14
- white
15
- comment
16
- white
17
- tags
18
- white
19
- header:(!(scenario_outline / scenario / background) .)*
20
- bg:background?
21
- feature_elements
22
- comment? {
23
- def build(filter)
24
- if(filter.nil? || feature_elements.accept?(filter) || (!bg.empty? && filter.accept?(bg)))
25
- background = bg.respond_to?(:build) ? bg.build : nil
26
- Ast::Feature.new(
27
- background,
28
- comment.build,
29
- tags.build,
30
- header.text_value,
31
- feature_elements.build(background, filter)
32
- )
33
- end
34
- end
35
- }
36
- end
37
-
38
- rule tags
39
- white ts:(tag (space/eol)+)* {
40
- def at_line?(line)
41
- ts.elements.detect{|e| e.tag.line == line}
42
- end
43
-
44
- def build
45
- Ast::Tags.new(ts.line, tag_names)
46
- end
47
-
48
- def tag_names
49
- @tag_names ||= ts.elements.map{|e| e.tag.text_value}
50
- end
51
- }
52
- end
53
-
54
- rule tag
55
- '@' [^@\r\n\t ]+
56
- end
57
-
58
- rule comment
59
- (comment_line white)* {
60
- def build
61
- Ast::Comment.new(text_value)
62
- end
63
- }
64
- end
65
-
66
- rule comment_line
67
- space* '#' line_to_eol
68
- end
69
-
70
- rule background
71
- comment white background_keyword space* name:lines_to_keyword? (eol+ / eof) steps {
72
- def matches_name?(regexp_to_match)
73
- name.build =~ regexp_to_match
74
- end
75
-
76
- def at_line?(line)
77
- background_keyword.line == line ||
78
- steps.at_line?(line)
79
- end
80
-
81
- def matches_tags?(tag_expression)
82
- tag_expression.eval(self.parent.tags.tag_names)
83
- end
84
-
85
- def build
86
- Ast::Background.new(
87
- comment.build,
88
- background_keyword.line,
89
- background_keyword.text_value,
90
- name.build,
91
- steps.build
92
- )
93
- end
94
- }
95
- end
96
-
97
- rule feature_elements
98
- (scenario / scenario_outline)* {
99
- def accept?(filter)
100
- filter.nil? || elements.empty? || elements.detect{|feature_element| filter.accept?(feature_element)}
101
- end
102
-
103
- def build(background, filter)
104
- elements.map do |feature_element|
105
- if filter.nil? || filter.accept?(feature_element)
106
- feature_element.build(background, filter)
107
- end
108
- end.compact
109
- end
110
- }
111
- end
112
-
113
- rule scenario
114
- comment tags white scenario_keyword space* name:lines_to_keyword white steps white {
115
- def at_line?(line)
116
- scenario_keyword.line == line ||
117
- steps.at_line?(line) ||
118
- tags.at_line?(line)
119
- end
120
-
121
- def matches_tags?(tag_expression)
122
- feature_tag_names = self.parent.parent.tags.tag_names
123
- source_tag_names = (feature_tag_names + tags.tag_names).uniq
124
- tag_expression.eval(source_tag_names)
125
- end
126
-
127
- def matches_name?(regexp_to_match)
128
- name.build =~ regexp_to_match
129
- end
130
-
131
- def build(background, filter)
132
- Ast::Scenario.new(
133
- background,
134
- comment.build,
135
- tags.build,
136
- scenario_keyword.line,
137
- scenario_keyword.text_value,
138
- name.build,
139
- steps.build
140
- )
141
- end
142
- }
143
- end
144
-
145
- rule scenario_outline
146
- comment tags white scenario_outline_keyword space* name:lines_to_keyword white steps examples_sections white {
147
- def at_line?(line)
148
- outline_at_line?(line) ||
149
- examples_sections.at_line?(line) ||
150
- tags.at_line?(line)
151
- end
152
-
153
- def outline_at_line?(line)
154
- scenario_outline_keyword.line == line ||
155
- steps.at_line?(line)
156
- end
157
-
158
- def matches_tags?(tag_expression)
159
- feature_tag_names = self.parent.parent.tags.tag_names
160
- source_tag_names = (feature_tag_names + tags.tag_names).uniq
161
- tag_expression.eval(source_tag_names)
162
- end
163
-
164
- def matches_name?(regexp_to_match)
165
- outline_matches_name?(regexp_to_match) || examples_sections.matches_name?(regexp_to_match)
166
- end
167
-
168
- def outline_matches_name?(regexp_to_match)
169
- name.build =~ regexp_to_match
170
- end
171
-
172
- def build(background, filter)
173
- Ast::ScenarioOutline.new(
174
- background,
175
- comment.build,
176
- tags.build,
177
- scenario_outline_keyword.line,
178
- scenario_outline_keyword.text_value,
179
- name.build,
180
- steps.build,
181
- examples_sections.build(filter, self)
182
- )
183
- end
184
- }
185
- end
186
-
187
- rule steps
188
- step* {
189
- def at_line?(line)
190
- elements.detect{|e| e.at_line?(line)}
191
- end
192
-
193
- def build
194
- elements.map{|e| e.build}
195
- end
196
- }
197
- end
198
-
199
- rule step
200
- comment space* step_keyword space* name:line_to_eol (eol+ / eof) multi:multiline_arg? white {
201
- def at_line?(line)
202
- step_keyword.line == line ||
203
- (multi.respond_to?(:at_line?) && multi.at_line?(line))
204
- end
205
-
206
- def build
207
- if multi.respond_to?(:build)
208
- Ast::Step.new(step_keyword.line, step_keyword.text_value.strip, name.text_value.strip, multi.build)
209
- else
210
- Ast::Step.new(step_keyword.line, step_keyword.text_value.strip, name.text_value.strip)
211
- end
212
- end
213
- }
214
- end
215
-
216
- rule examples_sections
217
- examples* {
218
- def at_line?(line)
219
- elements.detect { |e| e.at_line?(line) }
220
- end
221
-
222
- def matches_name?(regexp_to_match)
223
- elements.detect { |e| e.matches_name?(regexp_to_match) }
224
- end
225
-
226
- def build(filter, scenario_outline)
227
- elements.map do |e|
228
- if(filter.nil? || filter.accept_example?(e, scenario_outline))
229
- e.build(filter, scenario_outline)
230
- end
231
- end.compact
232
- end
233
- }
234
- end
235
-
236
- rule examples
237
- comment space* examples_keyword space* name:lines_to_keyword? eol table white {
238
- def at_line?(line)
239
- examples_keyword.line == line ||
240
- table.at_line?(line)
241
- end
242
-
243
- def matches_tags?(tag_names)
244
- true
245
- end
246
-
247
- def outline_at_line?(line)
248
- true
249
- end
250
-
251
- def matches_name?(regexp_to_match)
252
- name.build =~ regexp_to_match
253
- end
254
-
255
- def build(filter, scenario_outline)
256
- [comment.build, examples_keyword.line, examples_keyword.text_value, name.build, table.raw(filter, scenario_outline)]
257
- end
258
- }
259
- end
260
-
261
- rule multiline_arg
262
- table / py_string
263
- end
264
-
265
- rule line_to_eol
266
- (!eol .)*
267
- end
268
-
269
- rule lines_to_keyword
270
- (!(eol space* reserved_words_and_symbols) .)* {
271
- def build
272
- self.text_value.split("\n").map{|s| s.strip}.join("\n")
273
- end
274
- }
275
- end
276
-
277
- rule reserved_words_and_symbols
278
- (step_keyword) / scenario_keyword / scenario_outline_keyword / table / tag / comment_line
279
- end
280
-
281
- rule white
282
- (space / eol)*
283
- end
284
-
285
- end
286
- end
287
- end
@@ -1,35 +0,0 @@
1
- module Cucumber
2
- module Parser
3
- module I18n
4
- grammar <%= @grammar_name %>
5
- include Feature
6
- include Table
7
- include PyString
8
-
9
- rule feature
10
- feature_sub
11
- end
12
-
13
- rule background_keyword
14
- <%= treetop_keywords(background_keywords) %> ':'
15
- end
16
-
17
- rule scenario_keyword
18
- <%= treetop_keywords(scenario_keywords) %> ':'
19
- end
20
-
21
- rule scenario_outline_keyword
22
- <%= treetop_keywords(scenario_outline_keywords) %> ':'
23
- end
24
-
25
- rule step_keyword
26
- <%= treetop_keywords(step_keywords) %>
27
- end
28
-
29
- rule examples_keyword
30
- <%= treetop_keywords(examples_keywords) %> ':'?
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,118 +0,0 @@
1
- # TODO: REMOVE ME
2
- # Most of this class now lives in Gherkin's i18n.rb
3
- module Cucumber
4
- module Parser
5
- class NaturalLanguage
6
- KEYWORD_KEYS = %w{name native feature background scenario scenario_outline examples given when then and but}
7
-
8
- class << self
9
- def get(step_mother, lang)
10
- languages[lang] ||= new(step_mother, lang)
11
- end
12
-
13
- def languages
14
- @languages ||= {}
15
- end
16
-
17
- # Used by code generators for other lexer tools like pygments lexer and textmate bundle
18
- def all(step_mother=nil)
19
- Cucumber::LANGUAGES.keys.sort.map{|lang| get(step_mother, lang)}
20
- end
21
- end
22
-
23
- def initialize(step_mother, lang)
24
- @keywords = Cucumber::LANGUAGES[lang]
25
- raise "Language not supported: #{lang.inspect}" if @keywords.nil?
26
- @grammar_name = lang.gsub(/[\s-]/, '').upcase
27
- register_adverbs(step_mother) if step_mother
28
- @parser = nil
29
- end
30
-
31
- def register_adverbs(step_mother)
32
- adverbs = %w{given when then and but}.map{|keyword| @keywords[keyword].split('|').map{|w| w.gsub(/[\s<']/, '')}}.flatten
33
- step_mother.register_adverbs(adverbs) if step_mother
34
- end
35
-
36
- def parser
37
- return @parser if @parser
38
- i18n_tt = File.expand_path(File.dirname(__FILE__) + '/i18n.tt')
39
- template = File.open(i18n_tt, Cucumber.file_mode('r')).read
40
- erb = ERB.new(template)
41
- grammar = erb.result(binding)
42
-
43
- # The Rails 2-3-stable branch has decided to monkey-patch ERB so that ERB#result
44
- # returns a subclass of String (SafeBuffer). This class will escape '&', '>', '<' and '"',
45
- # effectively breaking any other library that relies on ERB behavig the way it _should_.
46
- # This is a workaround hack until this has been fixed in Rails.
47
- grammar = "" + grammar # Make SafeBuffer a String again.
48
- Treetop.load_from_string(grammar)
49
- @parser = Parser::I18n.const_get("#{@grammar_name}Parser").new
50
- def @parser.inspect
51
- "#<#{self.class.name}>"
52
- end
53
- @parser
54
- end
55
-
56
- def parse(source, path, filter)
57
- feature = parser.parse_or_fail(source, path, filter)
58
- feature.language = self if feature
59
- feature
60
- end
61
-
62
- def incomplete?
63
- KEYWORD_KEYS.detect{|key| @keywords[key].nil?}
64
- end
65
-
66
- def feature_keywords
67
- keywords('feature')
68
- end
69
-
70
- def scenario_keywords
71
- keywords('scenario')
72
- end
73
-
74
- def scenario_outline_keywords
75
- keywords('scenario_outline')
76
- end
77
-
78
- def background_keywords
79
- keywords('background')
80
- end
81
-
82
- def examples_keywords
83
- keywords('examples')
84
- end
85
-
86
- def but_keywords(space=true)
87
- keywords('but', space)
88
- end
89
-
90
- def and_keywords(space=true)
91
- keywords('and', space)
92
- end
93
-
94
- def given_keyword
95
- keywords('given', false)[1] # The 0th one is a '*', which we don't want
96
- end
97
-
98
- def step_keywords
99
- %w{given when then and but}.map{|key| keywords(key, true)}.flatten.uniq
100
- end
101
-
102
- def keywords(key, space=false)
103
- raise "No #{key} in #{@keywords.inspect}" if @keywords[key].nil?
104
- @keywords[key].split('|').map{|kw| space ? keyword_space(kw) : kw}.uniq
105
- end
106
-
107
- private
108
-
109
- def treetop_keywords(keywords)
110
- "(" + keywords.map{|k| %{"#{k}"}}.join(" / ") + ")"
111
- end
112
-
113
- def keyword_space(val)
114
- (val + ' ').sub(/< $/,'')
115
- end
116
- end
117
- end
118
- end
@@ -1,285 +0,0 @@
1
- # Autogenerated from a Treetop grammar. Edits may be lost.
2
-
3
-
4
- module Cucumber
5
- module Parser
6
- # TIP: When you hack on the grammar, just delete py_string.rb in this directory.
7
- # Also make sure you have uninstalled all cucumber gems (don't forget xxx-cucumber
8
- # github gems).
9
- #
10
- # Treetop will then generate the parser in-memory. When you're happy, just generate
11
- # the rb file with tt feature.tt
12
- module PyString
13
- include Treetop::Runtime
14
-
15
- def root
16
- @root || :py_string
17
- end
18
-
19
- include Common
20
-
21
- module PyString0
22
- end
23
-
24
- module PyString1
25
- def open_py_string
26
- elements[0]
27
- end
28
-
29
- def s
30
- elements[1]
31
- end
32
-
33
- def close_py_string
34
- elements[2]
35
- end
36
- end
37
-
38
- module PyString2
39
- def at_line?(line)
40
- line >= open_py_string.line && line <= close_py_string.line
41
- end
42
-
43
- def build(ignored_filter=nil)
44
- Ast::PyString.new(open_py_string.line, close_py_string.line, s.text_value, open_py_string.indentation)
45
- end
46
- end
47
-
48
- def _nt_py_string
49
- start_index = index
50
- if node_cache[:py_string].has_key?(index)
51
- cached = node_cache[:py_string][index]
52
- if cached
53
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
54
- @index = cached.interval.end
55
- end
56
- return cached
57
- end
58
-
59
- i0, s0 = index, []
60
- r1 = _nt_open_py_string
61
- s0 << r1
62
- if r1
63
- s2, i2 = [], index
64
- loop do
65
- i3, s3 = index, []
66
- i4 = index
67
- r5 = _nt_close_py_string
68
- if r5
69
- r4 = nil
70
- else
71
- @index = i4
72
- r4 = instantiate_node(SyntaxNode,input, index...index)
73
- end
74
- s3 << r4
75
- if r4
76
- if index < input_length
77
- r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
78
- @index += 1
79
- else
80
- terminal_parse_failure("any character")
81
- r6 = nil
82
- end
83
- s3 << r6
84
- end
85
- if s3.last
86
- r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
87
- r3.extend(PyString0)
88
- else
89
- @index = i3
90
- r3 = nil
91
- end
92
- if r3
93
- s2 << r3
94
- else
95
- break
96
- end
97
- end
98
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
99
- s0 << r2
100
- if r2
101
- r7 = _nt_close_py_string
102
- s0 << r7
103
- end
104
- end
105
- if s0.last
106
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
107
- r0.extend(PyString1)
108
- r0.extend(PyString2)
109
- else
110
- @index = i0
111
- r0 = nil
112
- end
113
-
114
- node_cache[:py_string][start_index] = r0
115
-
116
- r0
117
- end
118
-
119
- module OpenPyString0
120
- def indent
121
- elements[0]
122
- end
123
-
124
- def eol
125
- elements[3]
126
- end
127
- end
128
-
129
- module OpenPyString1
130
- def indentation
131
- indent.text_value
132
- end
133
-
134
- def line
135
- indent.line
136
- end
137
- end
138
-
139
- def _nt_open_py_string
140
- start_index = index
141
- if node_cache[:open_py_string].has_key?(index)
142
- cached = node_cache[:open_py_string][index]
143
- if cached
144
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
145
- @index = cached.interval.end
146
- end
147
- return cached
148
- end
149
-
150
- i0, s0 = index, []
151
- s1, i1 = [], index
152
- loop do
153
- r2 = _nt_space
154
- if r2
155
- s1 << r2
156
- else
157
- break
158
- end
159
- end
160
- r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
161
- s0 << r1
162
- if r1
163
- if has_terminal?('"""', false, index)
164
- r3 = instantiate_node(SyntaxNode,input, index...(index + 3))
165
- @index += 3
166
- else
167
- terminal_parse_failure('"""')
168
- r3 = nil
169
- end
170
- s0 << r3
171
- if r3
172
- s4, i4 = [], index
173
- loop do
174
- r5 = _nt_space
175
- if r5
176
- s4 << r5
177
- else
178
- break
179
- end
180
- end
181
- r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
182
- s0 << r4
183
- if r4
184
- r6 = _nt_eol
185
- s0 << r6
186
- end
187
- end
188
- end
189
- if s0.last
190
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
191
- r0.extend(OpenPyString0)
192
- r0.extend(OpenPyString1)
193
- else
194
- @index = i0
195
- r0 = nil
196
- end
197
-
198
- node_cache[:open_py_string][start_index] = r0
199
-
200
- r0
201
- end
202
-
203
- module ClosePyString0
204
- def eol
205
- elements[0]
206
- end
207
-
208
- def quotes
209
- elements[2]
210
- end
211
-
212
- def white
213
- elements[3]
214
- end
215
- end
216
-
217
- module ClosePyString1
218
- def line
219
- quotes.line
220
- end
221
- end
222
-
223
- def _nt_close_py_string
224
- start_index = index
225
- if node_cache[:close_py_string].has_key?(index)
226
- cached = node_cache[:close_py_string][index]
227
- if cached
228
- cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
229
- @index = cached.interval.end
230
- end
231
- return cached
232
- end
233
-
234
- i0, s0 = index, []
235
- r1 = _nt_eol
236
- s0 << r1
237
- if r1
238
- s2, i2 = [], index
239
- loop do
240
- r3 = _nt_space
241
- if r3
242
- s2 << r3
243
- else
244
- break
245
- end
246
- end
247
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
248
- s0 << r2
249
- if r2
250
- if has_terminal?('"""', false, index)
251
- r4 = instantiate_node(SyntaxNode,input, index...(index + 3))
252
- @index += 3
253
- else
254
- terminal_parse_failure('"""')
255
- r4 = nil
256
- end
257
- s0 << r4
258
- if r4
259
- r5 = _nt_white
260
- s0 << r5
261
- end
262
- end
263
- end
264
- if s0.last
265
- r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
266
- r0.extend(ClosePyString0)
267
- r0.extend(ClosePyString1)
268
- else
269
- @index = i0
270
- r0 = nil
271
- end
272
-
273
- node_cache[:close_py_string][start_index] = r0
274
-
275
- r0
276
- end
277
-
278
- end
279
-
280
- class PyStringParser < Treetop::Runtime::CompiledParser
281
- include PyString
282
- end
283
-
284
- end
285
- end