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.
- data/Rakefile +1 -1
- data/lib/mail.rb +2 -1
- data/lib/mail/version.rb +1 -1
- data/lib/vendor/treetop-1.4.3/History.txt +18 -0
- data/lib/vendor/treetop-1.4.3/LICENSE +19 -0
- data/lib/vendor/treetop-1.4.3/README.md +164 -0
- data/lib/vendor/treetop-1.4.3/Rakefile +23 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +251 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/info.plist +10 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar.gnuplot +15 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar.treetop +16 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar_benchmark.rb +107 -0
- data/lib/vendor/treetop-1.4.3/bin/tt +112 -0
- data/lib/vendor/treetop-1.4.3/doc/contributing_and_planned_features.markdown +103 -0
- data/lib/vendor/treetop-1.4.3/doc/grammar_composition.markdown +65 -0
- data/lib/vendor/treetop-1.4.3/doc/index.markdown +90 -0
- data/lib/vendor/treetop-1.4.3/doc/pitfalls_and_advanced_techniques.markdown +51 -0
- data/lib/vendor/treetop-1.4.3/doc/semantic_interpretation.markdown +189 -0
- data/lib/vendor/treetop-1.4.3/doc/site.rb +112 -0
- data/lib/vendor/treetop-1.4.3/doc/sitegen.rb +65 -0
- data/lib/vendor/treetop-1.4.3/doc/syntactic_recognition.markdown +100 -0
- data/lib/vendor/treetop-1.4.3/doc/using_in_ruby.markdown +21 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.rb +551 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.treetop +97 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_node_classes.rb +7 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb +54 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus +0 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.rb +718 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.treetop +132 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_node_classes.rb +5 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_test.rb +89 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/test_helper.rb +18 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler.rb +6 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/grammar_compiler.rb +44 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/lexical_address_space.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.rb +3366 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.treetop +436 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes.rb +20 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/character_class.rb +28 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/choice.rb +31 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/grammar.rb +28 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/optional.rb +19 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_rule.rb +58 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate.rb +45 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate_block.rb +16 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb +55 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/sequence.rb +71 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/terminal.rb +20 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/ruby_builder.rb +113 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions.rb +2 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb +42 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime.rb +5 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/compiled_parser.rb +110 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list.rb +4 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/syntax_node.rb +114 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/version.rb +9 -0
- data/lib/vendor/treetop-1.4.3/script/generate_metagrammar.rb +14 -0
- data/lib/vendor/treetop-1.4.3/script/svnadd +11 -0
- data/lib/vendor/treetop-1.4.3/script/svnrm +11 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/and_predicate_spec.rb +36 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/anything_symbol_spec.rb +44 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/character_class_spec.rb +276 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/choice_spec.rb +80 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/circular_compilation_spec.rb +28 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/failure_propagation_functional_spec.rb +21 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_compiler_spec.rb +84 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_spec.rb +41 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/multibyte_chars_spec.rb +46 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/nonterminal_symbol_spec.rb +40 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/not_predicate_spec.rb +38 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/one_or_more_spec.rb +35 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/optional_spec.rb +37 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/parenthesized_expression_spec.rb +19 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/parsing_rule_spec.rb +61 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/repeated_subrule_spec.rb +29 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/semantic_predicate_spec.rb +175 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/sequence_spec.rb +115 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_spec.rb +81 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_symbol_spec.rb +37 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.treetop +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.tt +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar_do.treetop +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/tt_compiler_spec.rb +216 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/zero_or_more_spec.rb +56 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/a.treetop +11 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/b.treetop +11 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/c.treetop +10 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/d.treetop +10 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/f.treetop +17 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/grammar_composition_spec.rb +40 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/subfolder/e_includes_c.treetop +15 -0
- data/lib/vendor/treetop-1.4.3/spec/ruby_extensions/string_spec.rb +32 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/compiled_parser_spec.rb +101 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/syntax_node_spec.rb +77 -0
- data/lib/vendor/treetop-1.4.3/spec/spec_helper.rb +110 -0
- data/lib/vendor/treetop-1.4.3/spec/spec_suite.rb +4 -0
- data/lib/vendor/treetop-1.4.3/treetop.gemspec +18 -0
- data/lib/vendor/treetop.rb +5 -0
- metadata +126 -11
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
BENCHMARK = false
|
3
|
+
|
4
|
+
module CircularCompilationSpec
|
5
|
+
describe "a parser for the metagrammar" do
|
6
|
+
attr_reader :parser
|
7
|
+
|
8
|
+
before do
|
9
|
+
@parser = Treetop::Compiler::MetagrammarParser.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can parse the metagrammar.treetop whence it was generated" do
|
13
|
+
File.open(METAGRAMMAR_PATH, 'r') do |f|
|
14
|
+
metagrammar_source = f.read
|
15
|
+
result = parser.parse(metagrammar_source)
|
16
|
+
result.should_not be_nil
|
17
|
+
|
18
|
+
# generated_parser = result.compile
|
19
|
+
# Object.class_eval(generated_parser)
|
20
|
+
# parser_2 = Treetop::Compiler::MetagrammarParser.new
|
21
|
+
# optionally_benchmark do
|
22
|
+
# result = parser_2.parse(metagrammar_source)
|
23
|
+
# result.should_not be_nil
|
24
|
+
# end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
describe "An expression for braces surrounding zero or more letters followed by semicolons" do
|
4
|
+
testing_expression "'{' ([a-z] ';')* '}'"
|
5
|
+
|
6
|
+
it "parses matching input successfully" do
|
7
|
+
parse('{a;b;c;}').should_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it "fails to parse input with an expression that is missing a semicolon, reporting the terminal failure occurring at the maximum index" do
|
11
|
+
parse('{a;b;c}') do |result|
|
12
|
+
result.should be_nil
|
13
|
+
|
14
|
+
terminal_failures = parser.terminal_failures
|
15
|
+
terminal_failures.size.should == 1
|
16
|
+
failure = terminal_failures[0]
|
17
|
+
failure.index.should == 6
|
18
|
+
failure.expected_string.should == ';'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
describe Compiler::GrammarCompiler do
|
4
|
+
attr_reader :compiler, :source_path_with_treetop_extension, :source_path_with_tt_extension, :target_path, :alternate_target_path
|
5
|
+
before do
|
6
|
+
@compiler = Compiler::GrammarCompiler.new
|
7
|
+
|
8
|
+
dir = File.dirname(__FILE__)
|
9
|
+
@source_path_with_treetop_extension = "#{dir}/test_grammar.treetop"
|
10
|
+
@source_path_with_do = "#{dir}/test_grammar_do.treetop"
|
11
|
+
@source_path_with_tt_extension = "#{dir}/test_grammar.tt"
|
12
|
+
@target_path = "#{dir}/test_grammar.rb"
|
13
|
+
@target_path_with_do = "#{dir}/test_grammar_do.rb"
|
14
|
+
@alternate_target_path = "#{dir}/test_grammar_alt.rb"
|
15
|
+
delete_target_files
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
delete_target_files
|
20
|
+
Object.class_eval do
|
21
|
+
remove_const(:Test) if const_defined?(:Test)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
specify "compilation of a single file to a default file name" do
|
26
|
+
File.exists?(target_path).should be_false
|
27
|
+
compiler.compile(source_path_with_treetop_extension)
|
28
|
+
File.exists?(target_path).should be_true
|
29
|
+
require target_path
|
30
|
+
Test::GrammarParser.new.parse('foo').should_not be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
specify "compilation of a single file to an explicit file name" do
|
34
|
+
File.exists?(alternate_target_path).should be_false
|
35
|
+
compiler.compile(source_path_with_treetop_extension, alternate_target_path)
|
36
|
+
File.exists?(alternate_target_path).should be_true
|
37
|
+
require alternate_target_path
|
38
|
+
Test::GrammarParser.new.parse('foo').should_not be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
specify "compilation of a single file without writing it to an output file" do
|
42
|
+
compiler.ruby_source(source_path_with_treetop_extension).should_not be_nil
|
43
|
+
end
|
44
|
+
|
45
|
+
specify "ruby_source_from_string compiles a grammar stored in string" do
|
46
|
+
compiler.ruby_source_from_string(File.read(source_path_with_treetop_extension)).should_not be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
specify "Treetop.load_from_string compiles and evaluates a source grammar stored in string" do
|
50
|
+
Treetop.load_from_string File.read(source_path_with_treetop_extension)
|
51
|
+
Test::GrammarParser.new.parse('foo').should_not be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
specify "Treetop.load compiles and evaluates a source grammar with a .treetop extension" do
|
55
|
+
Treetop.load source_path_with_treetop_extension
|
56
|
+
Test::GrammarParser.new.parse('foo').should_not be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
specify "Treetop.load compiles and evaluates a source grammar with a .tt extension" do
|
60
|
+
path_without_extension = source_path_with_tt_extension
|
61
|
+
Treetop.load path_without_extension
|
62
|
+
Test::GrammarParser.new.parse('foo').should_not be_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
specify "Treetop.load compiles and evaluates source grammar with no extension" do
|
67
|
+
path_without_extension = source_path_with_treetop_extension.gsub(/\.treetop\Z/, '')
|
68
|
+
Treetop.load path_without_extension
|
69
|
+
Test::GrammarParser.new.parse('foo').should_not be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
specify "grammars with 'do' compile" do
|
73
|
+
compiler.compile(@source_path_with_do)
|
74
|
+
require @target_path_with_do
|
75
|
+
Test::GrammarParser.new.parse('foo').should_not be_nil
|
76
|
+
end
|
77
|
+
|
78
|
+
def delete_target_files
|
79
|
+
File.delete(target_path) if File.exists?(target_path)
|
80
|
+
File.delete(@target_path_with_do) if File.exists?(@target_path_with_do)
|
81
|
+
File.delete(alternate_target_path) if File.exists?(alternate_target_path)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module GrammarSpec
|
4
|
+
module Bar
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "a grammar" do
|
8
|
+
testing_grammar %{
|
9
|
+
grammar Foo
|
10
|
+
# This comment should not cause a syntax error, nor should the following empty one
|
11
|
+
#
|
12
|
+
include GrammarSpec::Bar
|
13
|
+
|
14
|
+
rule foo
|
15
|
+
bar / baz
|
16
|
+
end
|
17
|
+
|
18
|
+
rule bar
|
19
|
+
'bar' 'bar'
|
20
|
+
end
|
21
|
+
|
22
|
+
rule baz
|
23
|
+
'baz' 'baz'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
it "parses matching input" do
|
29
|
+
parse('barbar').should_not be_nil
|
30
|
+
parse('bazbaz').should_not be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "fails if it does not parse all input" do
|
34
|
+
parse('barbarbazbaz').should be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "mixes in included modules" do
|
38
|
+
self.class.const_get(:Foo).ancestors.should include(GrammarSpec::Bar)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!ruby19
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
5
|
+
|
6
|
+
# Require ActiveSupport for multibyte strings
|
7
|
+
begin
|
8
|
+
require 'active_support'
|
9
|
+
rescue
|
10
|
+
gem 'activesupport'
|
11
|
+
require 'active_support'
|
12
|
+
end
|
13
|
+
|
14
|
+
module MultibyteCharsSpec
|
15
|
+
describe "an anything symbol" do
|
16
|
+
testing_expression '.'
|
17
|
+
it "matches an UTF-8 character" do
|
18
|
+
parse_multibyte("ø").should_not be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "A character class containing UTF-8 characters" do
|
23
|
+
testing_expression "[æøå]"
|
24
|
+
it "recognizes the UTF-8 characters" do
|
25
|
+
parse_multibyte("ø").should_not be_nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "a character class repetition containing UTF-8 characters mixed with other expressions" do
|
30
|
+
testing_expression '[æøå]+ "a"'
|
31
|
+
it "lazily instantiates a node for the character" do
|
32
|
+
result = parse_multibyte('æøåa')
|
33
|
+
pending "Multibyte support is not supported in Ruby 1.8.6" if RUBY_VERSION =~ /^1\.8.6/
|
34
|
+
result.elements[0].instance_variable_get("@elements").should include(true)
|
35
|
+
result.elements[0].elements.should_not include(true)
|
36
|
+
result.elements[0].elements.size.should == 3
|
37
|
+
result.elements.size.should == 2
|
38
|
+
result.elements[0].text_value.should == "æøå"
|
39
|
+
result.elements[0].elements[0].text_value.should == "æ"
|
40
|
+
result.elements[0].elements[1].text_value.should == "ø"
|
41
|
+
result.elements[0].elements[2].text_value.should == "å"
|
42
|
+
result.elements[1].text_value == "a"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module NonterminalSymbolSpec
|
4
|
+
describe "A nonterminal symbol followed by a block" do
|
5
|
+
testing_expression 'foo { def a_method; end }'
|
6
|
+
|
7
|
+
parser_class_under_test.class_eval do
|
8
|
+
def _nt_foo
|
9
|
+
'_nt_foo called'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "compiles to a method call, extending its results with the anonymous module for the block" do
|
14
|
+
result = parse('')
|
15
|
+
result.should == '_nt_foo called'
|
16
|
+
result.should respond_to(:a_method)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module TestModule
|
21
|
+
def a_method
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "a non-terminal followed by a module declaration" do
|
26
|
+
testing_expression 'foo <NonterminalSymbolSpec::TestModule>'
|
27
|
+
|
28
|
+
parser_class_under_test.class_eval do
|
29
|
+
def _nt_foo
|
30
|
+
'_nt_foo called'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "compiles to a method call, extending its results with the anonymous module for the block" do
|
35
|
+
result = parse('')
|
36
|
+
result.should == '_nt_foo called'
|
37
|
+
result.should respond_to(:a_method)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module NotPredicateSpec
|
4
|
+
describe "A !-predicated terminal symbol" do
|
5
|
+
testing_expression '!"foo"'
|
6
|
+
|
7
|
+
it "fails to parse input matching the terminal symbol" do
|
8
|
+
parse('foo').should be_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "A sequence of a terminal and an and another !-predicated terminal" do
|
13
|
+
testing_expression '"foo" !"bar"'
|
14
|
+
|
15
|
+
it "fails to match input matching both terminals" do
|
16
|
+
parse('foobar').should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "successfully parses input matching the first terminal and not the second, reporting the parse failure of the second terminal" do
|
20
|
+
parse('foo') do |result|
|
21
|
+
result.should_not be_nil
|
22
|
+
terminal_failures = parser.terminal_failures
|
23
|
+
terminal_failures.size.should == 1
|
24
|
+
failure = terminal_failures.first
|
25
|
+
failure.index.should == 3
|
26
|
+
failure.expected_string.should == 'bar'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "A !-predicated sequence" do
|
32
|
+
testing_expression '!("a" "b" "c")'
|
33
|
+
|
34
|
+
it "fails to parse matching input" do
|
35
|
+
parse('abc').should be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module OneOrMoreSpec
|
4
|
+
class Foo < Treetop::Runtime::SyntaxNode
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "one or more of a terminal symbol followed by a node class declaration and a block" do
|
8
|
+
testing_expression '"foo"+ <OneOrMoreSpec::Foo> { def a_method; end }'
|
9
|
+
|
10
|
+
it "fails to parse epsilon, reporting a failure" do
|
11
|
+
parse('') do |result|
|
12
|
+
result.should be_nil
|
13
|
+
terminal_failures = parser.terminal_failures
|
14
|
+
terminal_failures.size.should == 1
|
15
|
+
failure = terminal_failures.first
|
16
|
+
failure.index.should == 0
|
17
|
+
failure.expected_string.should == 'foo'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "successfully parses two of that terminal in a row, returning an instance of the declared node class and reporting the failure the third parsing attempt" do
|
22
|
+
parse("foofoo") do |result|
|
23
|
+
result.should_not be_nil
|
24
|
+
result.should be_an_instance_of(Foo)
|
25
|
+
result.should respond_to(:a_method)
|
26
|
+
|
27
|
+
terminal_failures = parser.terminal_failures
|
28
|
+
terminal_failures.size.should == 1
|
29
|
+
failure = terminal_failures.first
|
30
|
+
failure.index.should == 6
|
31
|
+
failure.expected_string.should == 'foo'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module OptionalSpec
|
4
|
+
describe "An optional terminal symbol" do
|
5
|
+
testing_expression '"foo"?'
|
6
|
+
|
7
|
+
it "parses input matching the terminal" do
|
8
|
+
parse('foo').should_not be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "parses epsilon, recording a failure" do
|
12
|
+
parse('') do |result|
|
13
|
+
result.should_not be_nil
|
14
|
+
result.interval.should == (0...0)
|
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 "parses input not matching the terminal, returning an epsilon result and recording a failure" do
|
25
|
+
parse('bar', :consume_all_input => false) do |result|
|
26
|
+
result.should_not be_nil
|
27
|
+
result.interval.should == (0...0)
|
28
|
+
|
29
|
+
terminal_failures = parser.terminal_failures
|
30
|
+
terminal_failures.size.should == 1
|
31
|
+
failure = terminal_failures.first
|
32
|
+
failure.index.should == 0
|
33
|
+
failure.expected_string.should == 'foo'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module ParenthesizedExpressionSpec
|
4
|
+
describe "An unadorned expression inside of parentheses" do
|
5
|
+
testing_expression '("foo")'
|
6
|
+
|
7
|
+
it "should behave as normal" do
|
8
|
+
parse('foo').should_not be_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "A prefixed-expression inside of parentheses" do
|
13
|
+
testing_expression '(!"foo")'
|
14
|
+
|
15
|
+
it "should behave as normal" do
|
16
|
+
parse('foo').should be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module ParsingRuleSpec
|
4
|
+
describe "a grammar with one parsing rule" do
|
5
|
+
|
6
|
+
testing_grammar %{
|
7
|
+
grammar Foo
|
8
|
+
rule bar
|
9
|
+
"baz"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
14
|
+
it "stores and retrieves nodes in its node cache" do
|
15
|
+
parser = self.class.const_get(:FooParser).new
|
16
|
+
parser.send(:prepare_to_parse, 'baz')
|
17
|
+
node_cache = parser.send(:node_cache)
|
18
|
+
|
19
|
+
node_cache[:bar][0].should be_nil
|
20
|
+
|
21
|
+
parser._nt_bar
|
22
|
+
|
23
|
+
cached_node = node_cache[:bar][0]
|
24
|
+
cached_node.should be_an_instance_of(Runtime::SyntaxNode)
|
25
|
+
cached_node.text_value.should == 'baz'
|
26
|
+
|
27
|
+
parser.instance_eval { @index = 0 }
|
28
|
+
parser._nt_bar.should equal(cached_node)
|
29
|
+
parser.index.should == cached_node.interval.end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
describe "a grammar with choice that uses the cache and has a subsequent expression" do
|
35
|
+
testing_grammar %{
|
36
|
+
grammar Logic
|
37
|
+
rule expression
|
38
|
+
value_plus
|
39
|
+
/
|
40
|
+
value
|
41
|
+
end
|
42
|
+
|
43
|
+
rule value_plus
|
44
|
+
value "something else"
|
45
|
+
end
|
46
|
+
|
47
|
+
rule value
|
48
|
+
[a-z]
|
49
|
+
/
|
50
|
+
"foobar" # the subsequent expression that needs cached.interval.end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
}
|
54
|
+
|
55
|
+
it "parses a single-character value and generates a node from the cache" do
|
56
|
+
result = parse('a')
|
57
|
+
result.should be_a(Treetop::Runtime::SyntaxNode)
|
58
|
+
result.elements.should be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|