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,29 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module RepeatedSubruleSpec
4
+ describe "a repeated subrule" do
5
+ testing_grammar %{
6
+ grammar Foo
7
+ rule foo
8
+ a:'a' space b:'b' space 'c'
9
+ end
10
+
11
+ rule space
12
+ ' '
13
+ end
14
+ end
15
+ }
16
+
17
+ it "should produce a parser having sequence-numbered node accessor methods" do
18
+ parse("a b c") do |result|
19
+ result.should_not be_nil
20
+ result.should respond_to(:space1)
21
+ result.should respond_to(:space2)
22
+ result.should_not respond_to(:space)
23
+ result.should respond_to(:a)
24
+ result.should respond_to(:b)
25
+ result.should_not respond_to(:c)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,175 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module SemanticPredicateSpec
4
+ describe "An &-predicate block" do
5
+ testing_expression '& {|| $ok_to_succeed}'
6
+
7
+ it "succeeds if it returns true, returning an epsilon syntax node" do
8
+ $ok_to_succeed = true
9
+ parse('foo', :consume_all_input => false) do |result|
10
+ result.should_not be_nil
11
+ result.interval.should == (0...0)
12
+ end
13
+ end
14
+
15
+ it "fails if it returns false" do
16
+ $ok_to_succeed = false
17
+ parse('foo', :consume_all_input => false) do |result|
18
+ result.should be_nil
19
+ terminal_failures = parser.terminal_failures
20
+ terminal_failures.size.should == 0
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ describe "A sequence of a terminal and an &-predicate block" do
27
+ testing_expression '"prior " &{|s| $value = s[0].text_value; $ok_to_succeed }'
28
+
29
+ it "matches the input terminal and consumes it if the block returns true, seeing the terminal in the sequence" do
30
+ $ok_to_succeed = true
31
+ $value = nil
32
+ parse('prior foo', :consume_all_input => false) do |result|
33
+ result.should_not be_nil
34
+ result.elements[0].text_value.should == "prior "
35
+ result.text_value.should == 'prior '
36
+ $value.should == 'prior '
37
+ end
38
+ end
39
+
40
+ it "fails if the block returns false, but sees the terminal in the sequence" do
41
+ $ok_to_succeed = false
42
+ $value = nil
43
+ parse('prior foo', :consume_all_input => false) do |result|
44
+ result.should be_nil
45
+ $value.should == 'prior '
46
+ terminal_failures = parser.terminal_failures
47
+ terminal_failures.size.should == 0
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ describe "A sequence of an optional terminal and an &-predicate block" do
54
+ testing_expression '"prior "? &{|s| $value = s[0].text_value; $ok_to_succeed}'
55
+
56
+ it "matches the input terminal and consumes it if the block returns true" do
57
+ $ok_to_succeed = true
58
+ parse('prior foo', :consume_all_input => false) do |result|
59
+ result.should_not be_nil
60
+ result.elements[0].text_value.should == "prior "
61
+ result.text_value.should == 'prior '
62
+ $value.should == 'prior '
63
+ end
64
+ end
65
+
66
+ it "fails with no terminal_failures if the block returns false" do
67
+ $ok_to_succeed = false
68
+ parse('prior foo', :consume_all_input => false) do |result|
69
+ result.should be_nil
70
+ $value.should == 'prior '
71
+ terminal_failures = parser.terminal_failures
72
+ terminal_failures.size.should == 0
73
+ end
74
+ end
75
+
76
+ it "fail and return the expected optional preceeding terminal as expected input if the block returns false" do
77
+ $ok_to_succeed = false
78
+ parse('foo', :consume_all_input => false) do |result|
79
+ result.should be_nil
80
+ terminal_failures = parser.terminal_failures
81
+ terminal_failures.size.should == 1
82
+ failure = terminal_failures[0]
83
+ failure.index.should == 0
84
+ failure.expected_string.should == 'prior '
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ describe "A !-predicate block" do
91
+ testing_expression '! {|| $ok_to_succeed}'
92
+
93
+ it "succeeds if it returns false, returning an epsilon syntax node" do
94
+ $ok_to_succeed = false
95
+ parse('foo', :consume_all_input => false) do |result|
96
+ result.should_not be_nil
97
+ result.interval.should == (0...0)
98
+ end
99
+ end
100
+
101
+ it "fails if it returns true" do
102
+ $ok_to_succeed = true
103
+ parse('foo', :consume_all_input => false) do |result|
104
+ result.should be_nil
105
+ terminal_failures = parser.terminal_failures
106
+ terminal_failures.size.should == 0
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ describe "A sequence of a terminal and an !-predicate block" do
113
+ testing_expression '"prior " !{|s| $value = s[0].text_value; $ok_to_succeed }'
114
+
115
+ it "matches the input terminal and consumes it if the block returns false, seeing the terminal in the sequence" do
116
+ $ok_to_succeed = false
117
+ $value = nil
118
+ parse('prior foo', :consume_all_input => false) do |result|
119
+ result.should_not be_nil
120
+ result.elements[0].text_value.should == "prior "
121
+ result.text_value.should == 'prior '
122
+ $value.should == 'prior '
123
+ end
124
+ end
125
+
126
+ it "fails if the block returns true, but sees the terminal in the sequence" do
127
+ $ok_to_succeed = true
128
+ $value = nil
129
+ parse('prior foo', :consume_all_input => false) do |result|
130
+ result.should be_nil
131
+ $value.should == 'prior '
132
+ terminal_failures = parser.terminal_failures
133
+ terminal_failures.size.should == 0
134
+ end
135
+ end
136
+
137
+ end
138
+
139
+ describe "A sequence of an optional terminal and an !-predicate block" do
140
+ testing_expression '"prior "? !{|s| $value = s[0].text_value; $ok_to_succeed}'
141
+
142
+ it "matches the input terminal and consumes it if the block returns false" do
143
+ $ok_to_succeed = false
144
+ parse('prior foo', :consume_all_input => false) do |result|
145
+ result.should_not be_nil
146
+ result.elements[0].text_value.should == "prior "
147
+ result.text_value.should == 'prior '
148
+ $value.should == 'prior '
149
+ end
150
+ end
151
+
152
+ it "fails with no terminal_failures if the block returns true" do
153
+ $ok_to_succeed = true
154
+ parse('prior foo', :consume_all_input => false) do |result|
155
+ result.should be_nil
156
+ $value.should == 'prior '
157
+ terminal_failures = parser.terminal_failures
158
+ terminal_failures.size.should == 0
159
+ end
160
+ end
161
+
162
+ it "fail and return the expected optional preceeding terminal as expected input if the block returns true" do
163
+ $ok_to_succeed = true
164
+ parse('foo', :consume_all_input => false) do |result|
165
+ result.should be_nil
166
+ terminal_failures = parser.terminal_failures
167
+ terminal_failures.size.should == 1
168
+ failure = terminal_failures[0]
169
+ failure.index.should == 0
170
+ failure.expected_string.should == 'prior '
171
+ end
172
+ end
173
+
174
+ end
175
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module SequenceSpec
4
+ class Foo < Treetop::Runtime::SyntaxNode
5
+ end
6
+
7
+ describe "a sequence of labeled terminal symbols followed by a node class declaration and a block" do
8
+ testing_expression 'foo:"foo" bar:"bar" baz:"baz" <SequenceSpec::Foo> { def a_method; end }'
9
+
10
+ it "upon successfully matching input, instantiates an instance of the declared node class with element accessor methods and the method from the inline module" do
11
+ parse('foobarbaz') do |result|
12
+ result.should_not be_nil
13
+ result.should be_an_instance_of(Foo)
14
+ result.should respond_to(:a_method)
15
+ result.foo.text_value.should == 'foo'
16
+ result.bar.text_value.should == 'bar'
17
+ result.baz.text_value.should == 'baz'
18
+ end
19
+ end
20
+
21
+ it "successfully matches at a non-zero index" do
22
+ parse('---foobarbaz', :index => 3) do |result|
23
+ result.should_not be_nil
24
+ result.should be_nonterminal
25
+ (result.elements.map {|elt| elt.text_value}).join.should == 'foobarbaz'
26
+ end
27
+ end
28
+
29
+ it "fails to match non-matching input, recording the parse failure of first non-matching terminal" do
30
+ parse('---foobazbaz', :index => 3) do |result|
31
+ result.should be_nil
32
+ parser.index.should == 3
33
+ terminal_failures = parser.terminal_failures
34
+ terminal_failures.size.should == 1
35
+ failure = terminal_failures.first
36
+ failure.index.should == 6
37
+ failure.expected_string.should == 'bar'
38
+ end
39
+ end
40
+ end
41
+
42
+ module ModFoo
43
+ def mod_method; end
44
+ end
45
+
46
+ describe "a sequence of labeled terminal symbols followed by a node module declaration and a block" do
47
+ testing_expression 'foo:"foo" bar:"bar" baz:"baz" <SequenceSpec::ModFoo> { def a_method; end }'
48
+
49
+ it "upon successfully matching input, instantiates a syntax node and extends it with the declared module, element accessor methods, and the method from the inline module" do
50
+ parse('foobarbaz') do |result|
51
+ result.should_not be_nil
52
+ result.should respond_to(:mod_method)
53
+ result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
54
+ result.should be_a_kind_of(ModFoo)
55
+ result.should respond_to(:a_method)
56
+ result.foo.text_value.should == 'foo'
57
+ result.bar.text_value.should == 'bar'
58
+ result.baz.text_value.should == 'baz'
59
+ end
60
+ end
61
+ end
62
+
63
+ describe "a sequence of non-terminals" do
64
+ testing_grammar %{
65
+ grammar TestGrammar
66
+ rule sequence
67
+ foo bar baz {
68
+ def baz
69
+ 'override' + super.text_value
70
+ end
71
+ }
72
+ end
73
+
74
+ rule foo 'foo' end
75
+ rule bar 'bar' end
76
+ rule baz 'baz' end
77
+ end
78
+ }
79
+
80
+ it "defines accessors for non-terminals automatically that can be overridden in the inline block" do
81
+ parse('foobarbaz') do |result|
82
+ result.foo.text_value.should == 'foo'
83
+ result.bar.text_value.should == 'bar'
84
+ result.baz.should == 'overridebaz'
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "Compiling a sequence containing various white-space errors" do
90
+ it "should succeed on a valid sequence" do
91
+ compiling_expression('foo:"foo" "bar" <SequenceSpec::Foo> { def a_method; end }').should_not raise_error
92
+ end
93
+
94
+ it "rejects space after a label" do
95
+ compiling_expression('foo :"foo" "bar"').should raise_error(RuntimeError)
96
+ end
97
+
98
+ it "rejects space after label's colon" do
99
+ compiling_expression('foo: "foo" "bar"').should raise_error(RuntimeError)
100
+ end
101
+
102
+ it "rejects missing space after a primary" do
103
+ compiling_expression('foo:"foo""bar"').should raise_error(RuntimeError)
104
+ end
105
+
106
+ it "rejects missing space before node class declaration" do
107
+ compiling_expression('foo:"foo" "bar"<SequenceSpec::Foo>').should raise_error(RuntimeError)
108
+ end
109
+
110
+ it "rejects missing space before inline module" do
111
+ compiling_expression('foo:"foo" "bar" <SequenceSpec::Foo>{def a_method; end}').should raise_error(RuntimeError)
112
+ end
113
+ end
114
+
115
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module TerminalSymbolSpec
4
+ class Foo < Treetop::Runtime::SyntaxNode
5
+ end
6
+
7
+ describe "a terminal symbol followed by a node class declaration and a block" do
8
+ testing_expression "'foo' <TerminalSymbolSpec::Foo> { def a_method; end }"
9
+
10
+ it "correctly parses matching input prefixes at various indices, returning an instance of the declared class that can respond to methods defined in the inline module" do
11
+ parse "foo", :index => 0 do |result|
12
+ result.should be_an_instance_of(Foo)
13
+ result.should respond_to(:a_method)
14
+ result.interval.should == (0...3)
15
+ result.text_value.should == 'foo'
16
+ end
17
+
18
+ parse "xfoo", :index => 1 do |result|
19
+ result.should be_an_instance_of(Foo)
20
+ result.should respond_to(:a_method)
21
+ result.interval.should == (1...4)
22
+ result.text_value.should == 'foo'
23
+ end
24
+
25
+ parse "---foo", :index => 3 do |result|
26
+ result.should be_an_instance_of(Foo)
27
+ result.should respond_to(:a_method)
28
+ result.interval.should == (3...6)
29
+ result.text_value.should == 'foo'
30
+ end
31
+ end
32
+
33
+ it "fails to parse nonmatching input at the index even if a match occurs later" do
34
+ parse(" foo", :index => 0).should be_nil
35
+ end
36
+ end
37
+
38
+ module ModFoo
39
+ end
40
+
41
+ describe "a terminal symbol followed by a node class declaration and a block" do
42
+ testing_expression "'foo' <TerminalSymbolSpec::ModFoo> { def a_method; end }"
43
+
44
+ it "correctly parses matching input prefixes at various indices, returning an instance of SyntaxNode extended with the declared module that can respond to methods defined in the inline module" do
45
+ parse "foo", :index => 0 do |result|
46
+ result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
47
+ result.should be_a_kind_of(ModFoo)
48
+ result.should respond_to(:a_method)
49
+ result.interval.should == (0...3)
50
+ result.text_value.should == 'foo'
51
+ end
52
+
53
+ parse "xfoo", :index => 1 do |result|
54
+ result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
55
+ result.should be_a_kind_of(ModFoo)
56
+ result.should respond_to(:a_method)
57
+ result.interval.should == (1...4)
58
+ result.text_value.should == 'foo'
59
+ end
60
+
61
+ parse "---foo", :index => 3 do |result|
62
+ result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
63
+ result.should be_a_kind_of(ModFoo)
64
+ result.should respond_to(:a_method)
65
+ result.interval.should == (3...6)
66
+ result.text_value.should == 'foo'
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "a transient terminal symbol" do
72
+ testing_expression "~'foo'"
73
+
74
+ it "returns true upon parsing matching input prefixes at various indices" do
75
+ pending "transient terminal expressions"
76
+ parse("foo", :index => 0).should be_true
77
+ parse("-foo", :index => 1).should be_true
78
+ parse("---foo", :index => 3).should be_true
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module TerminalSymbolSpec
4
+ class Foo < Treetop::Runtime::SyntaxNode
5
+ end
6
+
7
+ describe "a terminal symbol followed by a node class declaration and a block" do
8
+ testing_expression "'foo' <TerminalSymbolSpec::Foo> { def a_method; end }"
9
+
10
+ it "correctly parses matching input prefixes at various indices, returning an instance of the declared class that can respond to methods defined in the inline module" do
11
+ parse "foo", :index => 0 do |result|
12
+ result.should be_an_instance_of(Foo)
13
+ result.should respond_to(:a_method)
14
+ result.interval.should == (0...3)
15
+ result.text_value.should == 'foo'
16
+ end
17
+
18
+ parse "xfoo", :index => 1 do |result|
19
+ result.should be_an_instance_of(Foo)
20
+ result.should respond_to(:a_method)
21
+ result.interval.should == (1...4)
22
+ result.text_value.should == 'foo'
23
+ end
24
+
25
+ parse "---foo", :index => 3 do |result|
26
+ result.should be_an_instance_of(Foo)
27
+ result.should respond_to(:a_method)
28
+ result.interval.should == (3...6)
29
+ result.text_value.should == 'foo'
30
+ end
31
+ end
32
+
33
+ it "fails to parse nonmatching input at the index even if a match occurs later" do
34
+ parse(" foo", :index => 0).should be_nil
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Test
2
+ grammar Grammar
3
+ rule foo
4
+ 'foo'
5
+ end
6
+ end
7
+ end