mail 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mail might be problematic. Click here for more details.

Files changed (129) hide show
  1. data/Rakefile +1 -1
  2. data/lib/mail.rb +2 -1
  3. data/lib/mail/version.rb +1 -1
  4. data/lib/vendor/treetop-1.4.3/History.txt +18 -0
  5. data/lib/vendor/treetop-1.4.3/LICENSE +19 -0
  6. data/lib/vendor/treetop-1.4.3/README.md +164 -0
  7. data/lib/vendor/treetop-1.4.3/Rakefile +23 -0
  8. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
  9. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
  10. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
  11. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
  12. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
  13. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +251 -0
  14. data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/info.plist +10 -0
  15. data/lib/vendor/treetop-1.4.3/benchmark/seqpar.gnuplot +15 -0
  16. data/lib/vendor/treetop-1.4.3/benchmark/seqpar.treetop +16 -0
  17. data/lib/vendor/treetop-1.4.3/benchmark/seqpar_benchmark.rb +107 -0
  18. data/lib/vendor/treetop-1.4.3/bin/tt +112 -0
  19. data/lib/vendor/treetop-1.4.3/doc/contributing_and_planned_features.markdown +103 -0
  20. data/lib/vendor/treetop-1.4.3/doc/grammar_composition.markdown +65 -0
  21. data/lib/vendor/treetop-1.4.3/doc/index.markdown +90 -0
  22. data/lib/vendor/treetop-1.4.3/doc/pitfalls_and_advanced_techniques.markdown +51 -0
  23. data/lib/vendor/treetop-1.4.3/doc/semantic_interpretation.markdown +189 -0
  24. data/lib/vendor/treetop-1.4.3/doc/site.rb +112 -0
  25. data/lib/vendor/treetop-1.4.3/doc/sitegen.rb +65 -0
  26. data/lib/vendor/treetop-1.4.3/doc/syntactic_recognition.markdown +100 -0
  27. data/lib/vendor/treetop-1.4.3/doc/using_in_ruby.markdown +21 -0
  28. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.rb +551 -0
  29. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.treetop +97 -0
  30. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_node_classes.rb +7 -0
  31. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb +54 -0
  32. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus +0 -0
  33. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.rb +718 -0
  34. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.treetop +132 -0
  35. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_node_classes.rb +5 -0
  36. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_test.rb +89 -0
  37. data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/test_helper.rb +18 -0
  38. data/lib/vendor/treetop-1.4.3/lib/treetop.rb +17 -0
  39. data/lib/vendor/treetop-1.4.3/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
  40. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler.rb +6 -0
  41. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/grammar_compiler.rb +44 -0
  42. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/lexical_address_space.rb +17 -0
  43. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.rb +3366 -0
  44. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.treetop +436 -0
  45. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes.rb +20 -0
  46. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
  47. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
  48. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/character_class.rb +28 -0
  49. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/choice.rb +31 -0
  50. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
  51. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/grammar.rb +28 -0
  52. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
  53. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
  54. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/optional.rb +19 -0
  55. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
  56. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
  57. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_rule.rb +58 -0
  58. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate.rb +45 -0
  59. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate_block.rb +16 -0
  60. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb +55 -0
  61. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/sequence.rb +71 -0
  62. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/terminal.rb +20 -0
  63. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
  64. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
  65. data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/ruby_builder.rb +113 -0
  66. data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions.rb +2 -0
  67. data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb +42 -0
  68. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime.rb +5 -0
  69. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/compiled_parser.rb +110 -0
  70. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list.rb +4 -0
  71. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
  72. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
  73. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
  74. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/syntax_node.rb +114 -0
  75. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
  76. data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
  77. data/lib/vendor/treetop-1.4.3/lib/treetop/version.rb +9 -0
  78. data/lib/vendor/treetop-1.4.3/script/generate_metagrammar.rb +14 -0
  79. data/lib/vendor/treetop-1.4.3/script/svnadd +11 -0
  80. data/lib/vendor/treetop-1.4.3/script/svnrm +11 -0
  81. data/lib/vendor/treetop-1.4.3/spec/compiler/and_predicate_spec.rb +36 -0
  82. data/lib/vendor/treetop-1.4.3/spec/compiler/anything_symbol_spec.rb +44 -0
  83. data/lib/vendor/treetop-1.4.3/spec/compiler/character_class_spec.rb +276 -0
  84. data/lib/vendor/treetop-1.4.3/spec/compiler/choice_spec.rb +80 -0
  85. data/lib/vendor/treetop-1.4.3/spec/compiler/circular_compilation_spec.rb +28 -0
  86. data/lib/vendor/treetop-1.4.3/spec/compiler/failure_propagation_functional_spec.rb +21 -0
  87. data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_compiler_spec.rb +84 -0
  88. data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_spec.rb +41 -0
  89. data/lib/vendor/treetop-1.4.3/spec/compiler/multibyte_chars_spec.rb +46 -0
  90. data/lib/vendor/treetop-1.4.3/spec/compiler/nonterminal_symbol_spec.rb +40 -0
  91. data/lib/vendor/treetop-1.4.3/spec/compiler/not_predicate_spec.rb +38 -0
  92. data/lib/vendor/treetop-1.4.3/spec/compiler/one_or_more_spec.rb +35 -0
  93. data/lib/vendor/treetop-1.4.3/spec/compiler/optional_spec.rb +37 -0
  94. data/lib/vendor/treetop-1.4.3/spec/compiler/parenthesized_expression_spec.rb +19 -0
  95. data/lib/vendor/treetop-1.4.3/spec/compiler/parsing_rule_spec.rb +61 -0
  96. data/lib/vendor/treetop-1.4.3/spec/compiler/repeated_subrule_spec.rb +29 -0
  97. data/lib/vendor/treetop-1.4.3/spec/compiler/semantic_predicate_spec.rb +175 -0
  98. data/lib/vendor/treetop-1.4.3/spec/compiler/sequence_spec.rb +115 -0
  99. data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_spec.rb +81 -0
  100. data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_symbol_spec.rb +37 -0
  101. data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.treetop +7 -0
  102. data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.tt +7 -0
  103. data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar_do.treetop +7 -0
  104. data/lib/vendor/treetop-1.4.3/spec/compiler/tt_compiler_spec.rb +216 -0
  105. data/lib/vendor/treetop-1.4.3/spec/compiler/zero_or_more_spec.rb +56 -0
  106. data/lib/vendor/treetop-1.4.3/spec/composition/a.treetop +11 -0
  107. data/lib/vendor/treetop-1.4.3/spec/composition/b.treetop +11 -0
  108. data/lib/vendor/treetop-1.4.3/spec/composition/c.treetop +10 -0
  109. data/lib/vendor/treetop-1.4.3/spec/composition/d.treetop +10 -0
  110. data/lib/vendor/treetop-1.4.3/spec/composition/f.treetop +17 -0
  111. data/lib/vendor/treetop-1.4.3/spec/composition/grammar_composition_spec.rb +40 -0
  112. data/lib/vendor/treetop-1.4.3/spec/composition/subfolder/e_includes_c.treetop +15 -0
  113. data/lib/vendor/treetop-1.4.3/spec/ruby_extensions/string_spec.rb +32 -0
  114. data/lib/vendor/treetop-1.4.3/spec/runtime/compiled_parser_spec.rb +101 -0
  115. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
  116. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
  117. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
  118. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
  119. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
  120. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
  121. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
  122. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
  123. data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
  124. data/lib/vendor/treetop-1.4.3/spec/runtime/syntax_node_spec.rb +77 -0
  125. data/lib/vendor/treetop-1.4.3/spec/spec_helper.rb +110 -0
  126. data/lib/vendor/treetop-1.4.3/spec/spec_suite.rb +4 -0
  127. data/lib/vendor/treetop-1.4.3/treetop.gemspec +18 -0
  128. data/lib/vendor/treetop.rb +5 -0
  129. metadata +126 -11
@@ -0,0 +1,7 @@
1
+ module Test
2
+ grammar Grammar
3
+ rule foo
4
+ 'foo'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Test
2
+ grammar Grammar do
3
+ rule foo do
4
+ 'foo'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,216 @@
1
+ require 'digest/sha1'
2
+
3
+ # ensure the Kernel.system and Kernel.open's always use the correct tt and
4
+ # Treetop library versions, not a previously installed gem
5
+ ENV['PATH'] = File.expand_path(File.dirname(__FILE__) + '../../../bin' +
6
+ File::PATH_SEPARATOR + ENV['PATH'])
7
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '../../../lib'))
8
+
9
+ describe "The 'tt' comand line compiler" do
10
+
11
+ context 'when processing a single grammar file' do
12
+ before(:each) do
13
+ # create a fresh but dumb grammar file for each example
14
+ @test_base = "dumb-#{rand(1000)}"
15
+ @test_grammar = "#{@test_base}.tt"
16
+ File.open(@test_grammar, 'w+') do |f|
17
+ f.print("grammar Dumb\n")
18
+ f.print("end\n")
19
+ end unless File.exists?(@test_grammar)
20
+ end
21
+
22
+ after(:each) do
23
+ # cleanup test grammar and parser output files
24
+ f = "#{@test_base}.rb"
25
+ File.delete(@test_grammar) if File.exists?(@test_grammar)
26
+ File.delete(f) if File.exists?(f)
27
+ end
28
+
29
+ it 'can compile a grammar file' do
30
+ # puts %q{emulate 'tt dumb.tt'}
31
+ system("ruby -S tt #{@test_grammar}").should be_true
32
+
33
+ pf = "#{@test_base}.rb"
34
+ File.exists?(pf).should be_true
35
+ File.zero?(pf).should_not be_true
36
+ end
37
+
38
+ it 'can compile a relative pathed grammar file' do
39
+ dir = File.basename(File.expand_path(File.dirname(@test_grammar)))
40
+
41
+ # puts %q{emulate 'tt "../<current_dir>/dumb.tt"'}
42
+ system("ruby -S tt \"../#{dir}/#{@test_grammar}\"").should be_true
43
+
44
+ pf = "#{@test_base}.rb"
45
+ File.exists?(pf).should be_true
46
+ File.zero?(pf).should_not be_true
47
+ end
48
+
49
+ it 'can compile an absolute pathed grammar file' do
50
+ # puts %q{emulate 'tt "/path/to/dumb.tt"'}
51
+ system("ruby -S tt \"#{File.expand_path(@test_grammar)}\"").should be_true
52
+
53
+ pf = "#{@test_base}.rb"
54
+ File.exists?(pf).should be_true
55
+ File.zero?(pf).should_not be_true
56
+ end
57
+
58
+ it 'can compile without explicit file extensions' do
59
+ # puts %q{emulate 'tt dumb'}
60
+ system("ruby -S tt #{@test_base}").should be_true
61
+
62
+ pf = "#{@test_base}.rb"
63
+ File.exists?(pf).should be_true
64
+ File.zero?(pf).should_not be_true
65
+ end
66
+
67
+ it 'skips nonexistent grammar file without failing or creating bogus output' do
68
+ # puts %q{emulate 'tt dumb.bad'}
69
+ Kernel.open("|ruby -S tt #{@test_base}.bad") do |io|
70
+ (io.read =~ /ERROR.*?not exist.*?continuing/).should_not be_nil
71
+ end
72
+
73
+ File.exists?("#{@test_base}.rb").should be_false
74
+ end
75
+
76
+ it 'can compile to a specified parser source file' do
77
+ # puts %q{emulate 'tt -o my_dumb_test_parser.rb dumb'}
78
+ pf = 'my_dumb_test_parser.rb'
79
+ begin
80
+ system("ruby -S tt -o #{pf} #{@test_base}").should be_true
81
+
82
+ File.exists?(pf).should be_true
83
+ File.zero?(pf).should_not be_true
84
+ ensure
85
+ File.delete(pf) if File.exists?(pf)
86
+ end
87
+ end
88
+
89
+ it 'by default, does not overwrite an existing file without an autogenerated header' do
90
+ # puts %q{emulate 'tt -o must_save_parser.rb dumb'}
91
+ pf = 'must_save_parser.rb'
92
+ begin
93
+ system("ruby -S tt -o #{pf} #{@test_base}").should be_true
94
+
95
+ File.exists?(pf).should be_true
96
+ File.zero?(pf).should_not be_true
97
+
98
+ # Modify the file and make sure it remains unchanged:
99
+ File.open(pf, "r+") { |f| f.write("# Changed...") }
100
+ orig_file_hash = Digest::SHA1.hexdigest(File.read(pf))
101
+
102
+ Kernel.open("|ruby -S tt -o #{pf} #{@test_base}") do |io|
103
+ (io.read =~ /ERROR.*?already exists.*?skipping/).should_not be_nil
104
+ end
105
+
106
+ Digest::SHA1.hexdigest(File.read(pf)).should == orig_file_hash
107
+ ensure
108
+ File.delete(pf) if File.exists?(pf)
109
+ end
110
+ end
111
+
112
+ it 'by default, overwrites a changed file with an intact autogenerated header' do
113
+ # puts %q{emulate 'tt -o must_save_parser.rb dumb'}
114
+ pf = 'must_save_parser.rb'
115
+ begin
116
+ system("ruby -S tt -o #{pf} #{@test_base}").should be_true
117
+
118
+ File.exists?(pf).should be_true
119
+ File.zero?(pf).should_not be_true
120
+ orig_file_hash = Digest::SHA1.hexdigest(File.read(pf))
121
+
122
+ # Modify the file and make sure it gets reverted:
123
+ File.open(pf, "r+") { |f| f.gets; f.write("#") }
124
+
125
+ system("ruby -S tt -o #{pf} #{@test_base}").should be_true
126
+ Digest::SHA1.hexdigest(File.read(pf)).should == orig_file_hash
127
+ ensure
128
+ File.delete(pf) if File.exists?(pf)
129
+ end
130
+ end
131
+
132
+ it 'can be forced to overwrite existing file #{@test_base}' do
133
+ pf = "#{@test_base}.rb"
134
+ system("echo some junk >#{pf}").should be_true
135
+
136
+ File.exists?(pf).should be_true
137
+ File.zero?(pf).should_not be_true
138
+ orig_file_hash = Digest::SHA1.hexdigest(File.read(pf))
139
+
140
+ system("ruby -S tt -f #{@test_base}").should be_true
141
+ Digest::SHA1.hexdigest(File.read(pf)).should_not == orig_file_hash
142
+ end
143
+
144
+ end
145
+
146
+ context 'when processing multiple grammar files' do
147
+
148
+ before(:each) do
149
+ # provide fresh but dumb grammar files for each test
150
+ @test_bases = []
151
+ @test_grammars = []
152
+
153
+ %w[dumb1 dumb2].each do |e|
154
+ base = "#{e}-#{rand(1000)}"
155
+ grammar_file = "#{base}.tt"
156
+ @test_bases << base
157
+ @test_grammars << grammar_file
158
+
159
+ File.open(grammar_file, 'w+') do |f|
160
+ f.print("grammar #{e.capitalize}\n")
161
+ f.print("end\n")
162
+ end unless File.exists?(grammar_file)
163
+ end
164
+ end
165
+
166
+ after(:each) do
167
+ # cleanup test grammar and output parser files
168
+ @test_grammars.each { |f| File.delete(f) if File.exists?(f) }
169
+ @test_bases.each { |f| File.delete("#{f}.rb") if File.exists?("#{f}.rb") }
170
+ end
171
+
172
+ it 'can compile them in one invocation' do
173
+ # puts %q{emulate 'tt dumb1.tt dumb2.tt'}
174
+ system("ruby -S tt #{@test_grammars.join(' ')}").should be_true
175
+
176
+ @test_bases.each do |f|
177
+ pf = "#{f}.rb"
178
+ File.exists?(pf).should be_true
179
+ File.zero?(pf).should_not be_true
180
+ end
181
+ end
182
+
183
+ it 'can compile them without explicit file extenstions' do
184
+ # puts %q{emulate 'tt dumb1 dumb2'}
185
+ system("ruby -S tt #{@test_bases.join(' ')}").should be_true
186
+
187
+ @test_bases.each do |f|
188
+ pf = "#{f}.rb"
189
+ File.exists?(pf).should be_true
190
+ File.zero?(pf).should_not be_true
191
+ end
192
+ end
193
+
194
+ it 'can skip nonexistent and invalid extension named grammar files' do
195
+ # puts %q{emulate 'tt not_here bad_ext.ttg dumb1 dumb2'}
196
+ system("ruby -S tt not_here bad_ext.ttg #{@test_bases.join(' ')} >/dev/null 2>&1").should be_true
197
+
198
+ File.exists?('not_here.rb').should_not be_true
199
+ File.exists?('bad_ext.rb').should_not be_true
200
+
201
+ @test_bases.each do |f|
202
+ pf = "#{f}.rb"
203
+ File.exists?(pf).should be_true
204
+ File.zero?(pf).should_not be_true
205
+ end
206
+ end
207
+
208
+ it 'can not specify an output file' do
209
+ # puts %q{emulate 'tt -o my_bogus_test_parser.rb dumb1 dumb2'}
210
+ pf = 'my_bogus_test_parser.rb'
211
+ system("ruby -S tt -o #{pf} #{@test_bases.join(' ')} >/dev/null 2>&1").should be_false
212
+ File.exists?(pf).should be_false
213
+ end
214
+ end
215
+
216
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module ZeroOrMoreSpec
4
+ class Foo < Treetop::Runtime::SyntaxNode
5
+ end
6
+
7
+ describe "zero or more of a terminal symbol followed by a node class declaration and a block" do
8
+ testing_expression '"foo"* <ZeroOrMoreSpec::Foo> { def a_method; end }'
9
+
10
+ it "successfully parses epsilon, returning an instance declared node class and recording a terminal failure" do
11
+ parse('') do |result|
12
+ result.should_not be_nil
13
+ result.should be_an_instance_of(Foo)
14
+ result.should respond_to(:a_method)
15
+
16
+ terminal_failures = parser.terminal_failures
17
+ terminal_failures.size.should == 1
18
+ failure = terminal_failures.first
19
+ failure.index.should == 0
20
+ failure.expected_string.should == 'foo'
21
+ end
22
+ end
23
+
24
+ it "successfully parses two of that terminal in a row, returning an instance of the declared node class and recording a failure representing the third attempt " do
25
+ parse("foofoo") do |result|
26
+ result.should_not be_nil
27
+ result.should be_an_instance_of(Foo)
28
+
29
+ terminal_failures = parser.terminal_failures
30
+ terminal_failures.size.should == 1
31
+ failure = terminal_failures.first
32
+ failure.index.should == 6
33
+ failure.expected_string.should == 'foo'
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "Zero or more of a sequence" do
39
+ testing_expression '("foo" "bar")*'
40
+
41
+ it "resets the index appropriately following partially matcing input" do
42
+ parse('foobarfoo', :consume_all_input => false) do |result|
43
+ result.should_not be_nil
44
+ result.interval.should == (0...6)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "Zero or more of a choice" do
50
+ testing_expression '("a" / "b")*'
51
+
52
+ it "successfully parses matching input" do
53
+ parse('abba').should_not be_nil
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ module Test
2
+ grammar A
3
+ rule a
4
+ 'a'
5
+ end
6
+
7
+ rule inherit
8
+ 'super'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Test
2
+ grammar B
3
+ rule b
4
+ 'b'
5
+ end
6
+
7
+ rule inherit
8
+ super 'keyword'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Test
2
+ grammar C
3
+ include A
4
+ include B
5
+
6
+ rule c
7
+ a b 'c'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Test
2
+ grammar D
3
+ include A
4
+ include B
5
+
6
+ rule inherit
7
+ super 'works'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+
2
+ require "a"
3
+
4
+ require File.dirname(__FILE__) + "/b"
5
+ require File.dirname(__FILE__) + "/subfolder/e_includes_c"
6
+
7
+ module Test
8
+ grammar F
9
+ include A
10
+ include B
11
+ include E
12
+
13
+ rule f
14
+ c e 'f'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module GrammarCompositionSpec
4
+ describe "several composed grammars" do
5
+ before do
6
+ dir = File.dirname(__FILE__)
7
+ Treetop.load File.join(dir, 'a')
8
+ Treetop.load File.join(dir, 'b')
9
+ Treetop.load File.join(dir, 'c')
10
+ # Check that polyglot finds d.treetop and loads it:
11
+ $: << dir
12
+ require 'd'
13
+
14
+ @c = ::Test::CParser.new
15
+ @d = ::Test::DParser.new
16
+ end
17
+
18
+ specify "rules in C have access to rules defined in A and B" do
19
+ @c.parse('abc').should_not be_nil
20
+ end
21
+
22
+ specify "rules in C can override rules in A and B with super semantics" do
23
+ @d.parse('superkeywordworks').should_not be_nil
24
+ end
25
+ end
26
+
27
+ describe "composed grammar chaining with require" do
28
+ before do
29
+ # Load f with polyglot without using the load path:
30
+ require File.dirname(__FILE__) + '/f'
31
+
32
+ @f = ::Test::FParser.new
33
+ end
34
+
35
+ specify "rules in F have access to rule defined in E" do
36
+ @f.parse('abcef').should_not be_nil
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + "/../c"
2
+
3
+ module Test
4
+ grammar E
5
+ include C
6
+
7
+ rule e
8
+ 'e'
9
+ end
10
+
11
+ rule inherit
12
+ 'super'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ describe String do
4
+ before do
5
+ @string = %{
6
+ 0123456789
7
+ 012345
8
+ 01234567
9
+ 0123
10
+ }.tabto(0).strip
11
+ end
12
+
13
+ it "can translate indices to column numbers" do
14
+ @string.column_of(0).should == 1
15
+ @string.column_of(5).should == 6
16
+ @string.column_of(10).should == 11
17
+ @string.column_of(11).should == 1
18
+ @string.column_of(17).should == 7
19
+ @string.column_of(18).should == 1
20
+ @string.column_of(24).should == 7
21
+ end
22
+
23
+ it "can translate indices to line numbers" do
24
+ @string.line_of(0).should == 1
25
+ @string.line_of(5).should == 1
26
+ @string.line_of(10).should == 1
27
+ @string.line_of(11).should == 2
28
+ @string.line_of(17).should == 2
29
+ @string.line_of(18).should == 3
30
+ @string.line_of(24).should == 3
31
+ end
32
+ end