treetop 1.6.8 → 1.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +18 -0
  3. data/History.txt +18 -0
  4. data/Rakefile +3 -28
  5. data/Treetop.tmbundle/Preferences/Comments.tmPreferences +28 -0
  6. data/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
  7. data/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
  8. data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
  9. data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
  10. data/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
  11. data/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +358 -0
  12. data/Treetop.tmbundle/info.plist +10 -0
  13. data/lib/treetop/runtime/compiled_parser.rb +15 -2
  14. data/lib/treetop/version.rb +1 -1
  15. data/treetop.gemspec +25 -157
  16. metadata +12 -56
  17. data/spec/compiler/and_predicate_spec.rb +0 -36
  18. data/spec/compiler/anything_symbol_spec.rb +0 -47
  19. data/spec/compiler/character_class_spec.rb +0 -304
  20. data/spec/compiler/choice_spec.rb +0 -89
  21. data/spec/compiler/circular_compilation_spec.rb +0 -30
  22. data/spec/compiler/failure_propagation_functional_spec.rb +0 -21
  23. data/spec/compiler/grammar_compiler_spec.rb +0 -113
  24. data/spec/compiler/grammar_spec.rb +0 -44
  25. data/spec/compiler/multibyte_chars_spec.rb +0 -38
  26. data/spec/compiler/namespace_spec.rb +0 -42
  27. data/spec/compiler/nonterminal_symbol_spec.rb +0 -40
  28. data/spec/compiler/not_predicate_spec.rb +0 -52
  29. data/spec/compiler/occurrence_range_spec.rb +0 -186
  30. data/spec/compiler/one_or_more_spec.rb +0 -35
  31. data/spec/compiler/optional_spec.rb +0 -37
  32. data/spec/compiler/parenthesized_expression_spec.rb +0 -34
  33. data/spec/compiler/parsing_rule_spec.rb +0 -61
  34. data/spec/compiler/repeated_subrule_spec.rb +0 -29
  35. data/spec/compiler/semantic_predicate_spec.rb +0 -176
  36. data/spec/compiler/sequence_spec.rb +0 -129
  37. data/spec/compiler/terminal_spec.rb +0 -177
  38. data/spec/compiler/terminal_symbol_spec.rb +0 -40
  39. data/spec/compiler/test_grammar.treetop +0 -7
  40. data/spec/compiler/test_grammar.tt +0 -7
  41. data/spec/compiler/test_grammar_do.treetop +0 -7
  42. data/spec/compiler/test_grammar_magic_coding.treetop +0 -8
  43. data/spec/compiler/test_grammar_magic_encoding.treetop +0 -8
  44. data/spec/compiler/tt_compiler_spec.rb +0 -224
  45. data/spec/compiler/zero_or_more_spec.rb +0 -58
  46. data/spec/composition/a.treetop +0 -11
  47. data/spec/composition/b.treetop +0 -11
  48. data/spec/composition/c.treetop +0 -10
  49. data/spec/composition/d.treetop +0 -10
  50. data/spec/composition/f.treetop +0 -17
  51. data/spec/composition/grammar_composition_spec.rb +0 -40
  52. data/spec/composition/subfolder/e_includes_c.treetop +0 -15
  53. data/spec/ruby_extensions/string_spec.rb +0 -32
  54. data/spec/runtime/compiled_parser_spec.rb +0 -153
  55. data/spec/runtime/syntax_node_spec.rb +0 -77
  56. data/spec/spec_helper.rb +0 -123
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>name</key>
6
+ <string>Treetop</string>
7
+ <key>uuid</key>
8
+ <string>83A8B700-143D-4BD6-B4EA-D73796E8F883</string>
9
+ </dict>
10
+ </plist>
@@ -52,10 +52,10 @@ module Treetop
52
52
  end
53
53
 
54
54
  def terminal_failures
55
- if @terminal_failures.empty? || @terminal_failures[0].is_a?(TerminalParseFailure)
55
+ if @terminal_failures.empty? || @terminal_failures[-1].is_a?(TerminalParseFailure)
56
56
  @terminal_failures
57
57
  else
58
- @terminal_failures.map! {|tf_ary| TerminalParseFailure.new(*tf_ary) }
58
+ @terminal_failures.map! {|tf_ary| tf_ary.is_a?(TerminalParseFailure) ? tf_ary : TerminalParseFailure.new(*tf_ary) }
59
59
  end
60
60
  end
61
61
 
@@ -75,6 +75,11 @@ module Treetop
75
75
  @max_terminal_failure_index = 0
76
76
  end
77
77
 
78
+ def forget_failures_to_here
79
+ @terminal_failures = []
80
+ @max_terminal_failure_index = -1
81
+ end
82
+
78
83
  def reset_index
79
84
  @index = 0
80
85
  end
@@ -113,12 +118,20 @@ module Treetop
113
118
  end
114
119
 
115
120
  def terminal_parse_failure(expected_string, unexpected = false)
121
+ if @max_terminal_failure_index == -1
122
+ @max_terminal_failure_index = 0
123
+ return nil
124
+ end
116
125
  return nil if index < max_terminal_failure_index
117
126
  if index > max_terminal_failure_index
118
127
  @max_terminal_failure_index = index
119
128
  @terminal_failures = []
120
129
  end
121
130
  @terminal_failures << [index, expected_string, unexpected]
131
+ # It's very slow, but this shows the last 5 nested rules:
132
+ # caller.reject{|l| l =~ /`loop'|`block in /}[0..5].reverse.map{|l| l.sub(/[^`]*`_nt_/,'').sub(/'/,'')}
133
+
134
+ terminal_failures
122
135
  return nil
123
136
  end
124
137
  end
@@ -2,7 +2,7 @@ module Treetop #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 6
5
- TINY = 8
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,166 +1,34 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
- # stub: treetop 1.6.7 ruby lib
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'date'
5
+ require 'treetop/version'
6
6
 
7
- Gem::Specification.new do |s|
8
- s.name = "treetop"
9
- s.version = "1.6.7"
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "treetop"
9
+ spec.version = Treetop::VERSION::STRING
10
+ spec.authors = ["Nathan Sobo", "Clifford Heath"]
10
11
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Nathan Sobo", "Clifford Heath"]
14
- s.date = "2016-07-20"
15
- s.description = "A Parsing Expression Grammar (PEG) Parser generator DSL for Ruby"
16
- s.email = "cliffordheath@gmail.com"
17
- s.executables = ["tt"]
18
- s.extra_rdoc_files = [
12
+ spec.email = "cliffordheath@gmail.com"
13
+ spec.date = Date.today.strftime("%F")
14
+ spec.summary = "A Ruby-based text parsing and interpretation DSL"
15
+ spec.description = "A Parsing Expression Grammar (PEG) Parser generator DSL for Ruby"
16
+ spec.homepage = "https://github.com/cjheath/treetop"
17
+ spec.licenses = ["MIT"]
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|website|script|\.|benchmark)}) }
20
+ spec.executables = ["tt"]
21
+ spec.require_paths = ["lib"]
22
+ spec.extra_rdoc_files = [
19
23
  "LICENSE",
20
24
  "README.md"
21
25
  ]
22
- s.files = [
23
- "LICENSE",
24
- "README.md",
25
- "Rakefile",
26
- "bin/tt",
27
- "doc/contributing_and_planned_features.markdown",
28
- "doc/grammar_composition.markdown",
29
- "doc/index.markdown",
30
- "doc/pitfalls_and_advanced_techniques.markdown",
31
- "doc/semantic_interpretation.markdown",
32
- "doc/site.rb",
33
- "doc/sitegen.rb",
34
- "doc/syntactic_recognition.markdown",
35
- "doc/tt.1",
36
- "doc/using_in_ruby.markdown",
37
- "examples/indented_blocks/indented_blocks.tt",
38
- "examples/indented_blocks/indented_blocks_test.rb",
39
- "examples/lambda_calculus/arithmetic.rb",
40
- "examples/lambda_calculus/arithmetic.treetop",
41
- "examples/lambda_calculus/arithmetic_node_classes.rb",
42
- "examples/lambda_calculus/arithmetic_test.rb",
43
- "examples/lambda_calculus/lambda_calculus.rb",
44
- "examples/lambda_calculus/lambda_calculus.treetop",
45
- "examples/lambda_calculus/lambda_calculus_node_classes.rb",
46
- "examples/lambda_calculus/lambda_calculus_test.rb",
47
- "examples/lambda_calculus/test_helper.rb",
48
- "lib/treetop.rb",
49
- "lib/treetop/bootstrap_gen_1_metagrammar.rb",
50
- "lib/treetop/compiler.rb",
51
- "lib/treetop/compiler/grammar_compiler.rb",
52
- "lib/treetop/compiler/lexical_address_space.rb",
53
- "lib/treetop/compiler/metagrammar.rb",
54
- "lib/treetop/compiler/metagrammar.treetop",
55
- "lib/treetop/compiler/node_classes.rb",
56
- "lib/treetop/compiler/node_classes/anything_symbol.rb",
57
- "lib/treetop/compiler/node_classes/atomic_expression.rb",
58
- "lib/treetop/compiler/node_classes/character_class.rb",
59
- "lib/treetop/compiler/node_classes/choice.rb",
60
- "lib/treetop/compiler/node_classes/declaration_sequence.rb",
61
- "lib/treetop/compiler/node_classes/grammar.rb",
62
- "lib/treetop/compiler/node_classes/inline_module.rb",
63
- "lib/treetop/compiler/node_classes/nonterminal.rb",
64
- "lib/treetop/compiler/node_classes/optional.rb",
65
- "lib/treetop/compiler/node_classes/parenthesized_expression.rb",
66
- "lib/treetop/compiler/node_classes/parsing_expression.rb",
67
- "lib/treetop/compiler/node_classes/parsing_rule.rb",
68
- "lib/treetop/compiler/node_classes/predicate.rb",
69
- "lib/treetop/compiler/node_classes/predicate_block.rb",
70
- "lib/treetop/compiler/node_classes/repetition.rb",
71
- "lib/treetop/compiler/node_classes/sequence.rb",
72
- "lib/treetop/compiler/node_classes/terminal.rb",
73
- "lib/treetop/compiler/node_classes/transient_prefix.rb",
74
- "lib/treetop/compiler/node_classes/treetop_file.rb",
75
- "lib/treetop/compiler/ruby_builder.rb",
76
- "lib/treetop/polyglot.rb",
77
- "lib/treetop/ruby_extensions.rb",
78
- "lib/treetop/ruby_extensions/string.rb",
79
- "lib/treetop/runtime.rb",
80
- "lib/treetop/runtime/compiled_parser.rb",
81
- "lib/treetop/runtime/interval_skip_list.rb",
82
- "lib/treetop/runtime/interval_skip_list/head_node.rb",
83
- "lib/treetop/runtime/interval_skip_list/interval_skip_list.rb",
84
- "lib/treetop/runtime/interval_skip_list/node.rb",
85
- "lib/treetop/runtime/syntax_node.rb",
86
- "lib/treetop/runtime/terminal_parse_failure.rb",
87
- "lib/treetop/runtime/terminal_syntax_node.rb",
88
- "lib/treetop/version.rb",
89
- "spec/compiler/and_predicate_spec.rb",
90
- "spec/compiler/anything_symbol_spec.rb",
91
- "spec/compiler/character_class_spec.rb",
92
- "spec/compiler/choice_spec.rb",
93
- "spec/compiler/circular_compilation_spec.rb",
94
- "spec/compiler/failure_propagation_functional_spec.rb",
95
- "spec/compiler/grammar_compiler_spec.rb",
96
- "spec/compiler/grammar_spec.rb",
97
- "spec/compiler/multibyte_chars_spec.rb",
98
- "spec/compiler/namespace_spec.rb",
99
- "spec/compiler/nonterminal_symbol_spec.rb",
100
- "spec/compiler/not_predicate_spec.rb",
101
- "spec/compiler/occurrence_range_spec.rb",
102
- "spec/compiler/one_or_more_spec.rb",
103
- "spec/compiler/optional_spec.rb",
104
- "spec/compiler/parenthesized_expression_spec.rb",
105
- "spec/compiler/parsing_rule_spec.rb",
106
- "spec/compiler/repeated_subrule_spec.rb",
107
- "spec/compiler/semantic_predicate_spec.rb",
108
- "spec/compiler/sequence_spec.rb",
109
- "spec/compiler/terminal_spec.rb",
110
- "spec/compiler/terminal_symbol_spec.rb",
111
- "spec/compiler/test_grammar.treetop",
112
- "spec/compiler/test_grammar.tt",
113
- "spec/compiler/test_grammar_do.treetop",
114
- "spec/compiler/test_grammar_magic_coding.treetop",
115
- "spec/compiler/test_grammar_magic_encoding.treetop",
116
- "spec/compiler/tt_compiler_spec.rb",
117
- "spec/compiler/zero_or_more_spec.rb",
118
- "spec/composition/a.treetop",
119
- "spec/composition/b.treetop",
120
- "spec/composition/c.treetop",
121
- "spec/composition/d.treetop",
122
- "spec/composition/f.treetop",
123
- "spec/composition/grammar_composition_spec.rb",
124
- "spec/composition/subfolder/e_includes_c.treetop",
125
- "spec/ruby_extensions/string_spec.rb",
126
- "spec/runtime/compiled_parser_spec.rb",
127
- "spec/runtime/syntax_node_spec.rb",
128
- "spec/spec_helper.rb",
129
- "treetop.gemspec"
130
- ]
131
- s.homepage = "https://github.com/cjheath/treetop"
132
- s.licenses = ["MIT"]
133
- s.rubygems_version = "2.4.5"
134
- s.summary = "A Ruby-based text parsing and interpretation DSL"
135
-
136
- if s.respond_to? :specification_version then
137
- s.specification_version = 4
138
26
 
139
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
140
- s.add_runtime_dependency(%q<polyglot>, ["~> 0.3"])
141
- s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
142
- s.add_development_dependency(%q<activesupport>, ["~> 4"])
143
- s.add_development_dependency(%q<i18n>, ["~> 0.6"])
144
- s.add_development_dependency(%q<rr>, ["~> 1.0"])
145
- s.add_development_dependency(%q<rspec>, ["~> 3"])
146
- s.add_development_dependency(%q<rake>, ["~> 11"])
147
- else
148
- s.add_dependency(%q<polyglot>, ["~> 0.3"])
149
- s.add_dependency(%q<jeweler>, ["~> 2.0"])
150
- s.add_dependency(%q<activesupport>, ["~> 4"])
151
- s.add_dependency(%q<i18n>, ["~> 0.6"])
152
- s.add_dependency(%q<rr>, ["~> 1.0"])
153
- s.add_dependency(%q<rspec>, ["~> 3"])
154
- s.add_dependency(%q<rake>, ["~> 11"])
155
- end
156
- else
157
- s.add_dependency(%q<polyglot>, ["~> 0.3"])
158
- s.add_dependency(%q<jeweler>, ["~> 2.0"])
159
- s.add_dependency(%q<activesupport>, ["~> 4"])
160
- s.add_dependency(%q<i18n>, ["~> 0.6"])
161
- s.add_dependency(%q<rr>, ["~> 1.0"])
162
- s.add_dependency(%q<rspec>, ["~> 3"])
163
- s.add_dependency(%q<rake>, ["~> 11"])
164
- end
27
+ spec.add_runtime_dependency(%q<polyglot>, ["~> 0.3"])
28
+ spec.add_development_dependency(%q<activesupport>, ["~> 4"])
29
+ spec.add_development_dependency(%q<i18n>, ["~> 0.6"])
30
+ spec.add_development_dependency(%q<rr>, ["~> 1.0"])
31
+ spec.add_development_dependency(%q<rspec>, ["~> 3"])
32
+ spec.add_development_dependency(%q<rake>, ["~> 11"])
165
33
  end
166
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: treetop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.8
4
+ version: 1.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Sobo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-21 00:00:00.000000000 Z
12
+ date: 2017-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polyglot
@@ -25,20 +25,6 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0.3'
28
- - !ruby/object:Gem::Dependency
29
- name: jeweler
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '2.0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '2.0'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: activesupport
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -118,9 +104,19 @@ extra_rdoc_files:
118
104
  - LICENSE
119
105
  - README.md
120
106
  files:
107
+ - Gemfile
108
+ - History.txt
121
109
  - LICENSE
122
110
  - README.md
123
111
  - Rakefile
112
+ - Treetop.tmbundle/Preferences/Comments.tmPreferences
113
+ - Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet
114
+ - Treetop.tmbundle/Snippets/rule ___ end.tmSnippet
115
+ - Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib
116
+ - Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib
117
+ - Treetop.tmbundle/Support/syntax_tree_viewer.rb
118
+ - Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage
119
+ - Treetop.tmbundle/info.plist
124
120
  - bin/tt
125
121
  - doc/contributing_and_planned_features.markdown
126
122
  - doc/grammar_composition.markdown
@@ -184,46 +180,6 @@ files:
184
180
  - lib/treetop/runtime/terminal_parse_failure.rb
185
181
  - lib/treetop/runtime/terminal_syntax_node.rb
186
182
  - lib/treetop/version.rb
187
- - spec/compiler/and_predicate_spec.rb
188
- - spec/compiler/anything_symbol_spec.rb
189
- - spec/compiler/character_class_spec.rb
190
- - spec/compiler/choice_spec.rb
191
- - spec/compiler/circular_compilation_spec.rb
192
- - spec/compiler/failure_propagation_functional_spec.rb
193
- - spec/compiler/grammar_compiler_spec.rb
194
- - spec/compiler/grammar_spec.rb
195
- - spec/compiler/multibyte_chars_spec.rb
196
- - spec/compiler/namespace_spec.rb
197
- - spec/compiler/nonterminal_symbol_spec.rb
198
- - spec/compiler/not_predicate_spec.rb
199
- - spec/compiler/occurrence_range_spec.rb
200
- - spec/compiler/one_or_more_spec.rb
201
- - spec/compiler/optional_spec.rb
202
- - spec/compiler/parenthesized_expression_spec.rb
203
- - spec/compiler/parsing_rule_spec.rb
204
- - spec/compiler/repeated_subrule_spec.rb
205
- - spec/compiler/semantic_predicate_spec.rb
206
- - spec/compiler/sequence_spec.rb
207
- - spec/compiler/terminal_spec.rb
208
- - spec/compiler/terminal_symbol_spec.rb
209
- - spec/compiler/test_grammar.treetop
210
- - spec/compiler/test_grammar.tt
211
- - spec/compiler/test_grammar_do.treetop
212
- - spec/compiler/test_grammar_magic_coding.treetop
213
- - spec/compiler/test_grammar_magic_encoding.treetop
214
- - spec/compiler/tt_compiler_spec.rb
215
- - spec/compiler/zero_or_more_spec.rb
216
- - spec/composition/a.treetop
217
- - spec/composition/b.treetop
218
- - spec/composition/c.treetop
219
- - spec/composition/d.treetop
220
- - spec/composition/f.treetop
221
- - spec/composition/grammar_composition_spec.rb
222
- - spec/composition/subfolder/e_includes_c.treetop
223
- - spec/ruby_extensions/string_spec.rb
224
- - spec/runtime/compiled_parser_spec.rb
225
- - spec/runtime/syntax_node_spec.rb
226
- - spec/spec_helper.rb
227
183
  - treetop.gemspec
228
184
  homepage: https://github.com/cjheath/treetop
229
185
  licenses:
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module AndPredicateSpec
4
- describe "An &-predicated terminal symbol" do
5
- testing_expression '&"foo"'
6
-
7
- it "successfully parses input matching the terminal symbol, returning an epsilon syntax node" do
8
- parse('foo', :consume_all_input => false) do |result|
9
- result.should_not be_nil
10
- result.interval.should == (0...0)
11
- end
12
- end
13
- end
14
-
15
- describe "A sequence of a terminal and an and another &-predicated terminal" do
16
- testing_expression '"foo" &"bar"'
17
-
18
- it "matches input matching both terminals, but only consumes the first" do
19
- parse('foobar', :consume_all_input => false) do |result|
20
- result.should_not be_nil
21
- result.text_value.should == 'foo'
22
- end
23
- end
24
-
25
- it "fails to parse input matching only the first terminal, with a terminal failure recorded at index 3" do
26
- parse('foo') do |result|
27
- result.should be_nil
28
- terminal_failures = parser.terminal_failures
29
- terminal_failures.size.should == 1
30
- failure = terminal_failures[0]
31
- failure.index.should == 3
32
- failure.expected_string.should == '"bar"'
33
- end
34
- end
35
- end
36
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module AnythingSymbolSpec
4
- class Foo < Treetop::Runtime::SyntaxNode
5
- end
6
-
7
- describe "an anything symbol followed by a node class declaration and a block" do
8
- testing_expression '. <AnythingSymbolSpec::Foo> { def a_method; end }'
9
-
10
- it "matches any single character in a big range, returning an instance of the declared node class that responds to methods defined in the inline module" do
11
- (33..127).each do |digit|
12
- parse(digit.chr) do |result|
13
- result.should_not be_nil
14
- result.should be_an_instance_of(Foo)
15
- result.should respond_to(:a_method)
16
- result.interval.should == (0...1)
17
- end
18
- end
19
- end
20
-
21
- it "fails to parse epsilon" do
22
- parse('') do |result|
23
- result.should be_nil
24
- parser.terminal_failures.size.should == 1
25
- end
26
- end
27
- end
28
-
29
- module ModFoo
30
- end
31
-
32
- describe "an anything symbol followed by a module declaration and a block" do
33
- testing_expression '. <AnythingSymbolSpec::ModFoo> { def a_method; end }'
34
-
35
- it "matches any single character in a big range, returning an instance of SyntaxNode extended by the declared module that responds to methods defined in the inline module" do
36
- (33..127).each do |digit|
37
- parse(digit.chr) do |result|
38
- result.should_not be_nil
39
- result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
40
- result.should be_a_kind_of(ModFoo)
41
- result.should respond_to(:a_method)
42
- result.interval.should == (0...1)
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,304 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CharacterClassSpec
4
- class Foo < Treetop::Runtime::SyntaxNode
5
- end
6
-
7
- describe "a character class followed by a node class declaration and a block" do
8
-
9
- testing_expression "[A-Z] <CharacterClassSpec::Foo> { def a_method; end }"
10
-
11
- it "matches single characters within that range, returning instances of the declared node class that respond to the method defined in the inline module" do
12
- result = parse('A')
13
- result.should be_an_instance_of(Foo)
14
- result.should respond_to(:a_method)
15
- result = parse('N')
16
- result.should be_an_instance_of(Foo)
17
- result.should respond_to(:a_method)
18
- result = parse('Z')
19
- result.should be_an_instance_of(Foo)
20
- result.should respond_to(:a_method)
21
- end
22
-
23
- it "does not match single characters outside of that range" do
24
- parse('8') do |result|
25
- result.should be_nil
26
- parser.terminal_failures.size.should == 1
27
- end
28
- parse('a').should be_nil
29
- end
30
-
31
- it "matches a single character within that range at index 1" do
32
- parse(' A', :index => 1).should_not be_nil
33
- end
34
-
35
- it "fails to match a single character out of that range at index 1" do
36
- parse(' 1', :index => 1).should be_nil
37
- end
38
- end
39
-
40
- module ModFoo
41
- end
42
-
43
- describe "a character class followed by a node module declaration and a block" do
44
-
45
- testing_expression "[A-Z] <CharacterClassSpec::ModFoo> { def a_method; end }"
46
-
47
- it "matches single characters within that range, returning instances of SyntaxNode extended by the specified module" do
48
- result = parse('A')
49
- result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
50
- result.should be_a_kind_of(ModFoo)
51
- result.should respond_to(:a_method)
52
- result = parse('N')
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 = parse('Z')
57
- result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
58
- result.should be_a_kind_of(ModFoo)
59
- result.should respond_to(:a_method)
60
- end
61
-
62
- it "does not match single characters outside of that range" do
63
- parse('8').should be_nil
64
- parse('a').should be_nil
65
- end
66
-
67
- it "matches a single character within that range at index 1" do
68
- parse(' A', :index => 1).should_not be_nil
69
- end
70
-
71
- it "fails to match a single character out of that range at index 1" do
72
- parse(' 1', :index => 1).should be_nil
73
- end
74
- end
75
-
76
- describe "a character class with a POSIX bracket expression" do
77
- testing_expression "[[:digit:]]"
78
- it "matches a single character within the class" do
79
- parse('1').should_not be_nil
80
- end
81
- it "does not match a single character outside the class" do
82
- parse('a').should be_nil
83
- parse('-').should be_nil
84
- end
85
- testing_expression "[[:digit:][:space:]]+"
86
- it "matches a string with a mix of two character classes" do
87
- parse('1 4 9').should_not be_nil
88
- end
89
- end
90
-
91
- describe "a character class with a negated POSIX bracket expression" do
92
- testing_expression "[^[:space:]]"
93
- it "matches a character outside the negated class" do
94
- parse('a').should_not be_nil
95
- end
96
- it "doesn't match a character within the negated class" do
97
- parse(' ').should be_nil
98
- end
99
- end
100
-
101
- describe "a character class followed by a node class declaration and a block" do
102
-
103
- testing_expression "[A-Z] <CharacterClassSpec::Foo>"
104
-
105
- it "actively generates nodes for the character when it is the primary node" do
106
- result = parse('A')
107
- result.should be_a(Treetop::Runtime::SyntaxNode)
108
- result.elements.should be_nil
109
- end
110
-
111
- end
112
-
113
- describe "A character class containing quotes" do
114
- testing_expression "[\"']"
115
-
116
- it "matches a quote" do
117
- parse("'").should_not be_nil
118
- end
119
-
120
- it "matches a double-quote" do
121
- parse('"').should_not be_nil
122
- end
123
- end
124
-
125
- describe "A character class containing a special character" do
126
- testing_expression "[\t]"
127
- it "matches that character only" do
128
- parse("\t").should_not be_nil
129
- parse('t').should be_nil
130
- end
131
- end
132
-
133
- describe "A character class containing an escaped backslash" do
134
- slash = "\\" # Make it explicit that there are *two* backslashes here
135
- testing_expression "[#{slash}#{slash}]"
136
- it "matches a backslash only" do
137
- parse("\\").should_not be_nil
138
- parse('t').should be_nil
139
- end
140
- end
141
-
142
- describe "A character class containing a hex escape" do
143
- slash = "\\"
144
- testing_expression "[#{slash}x41]"
145
- it "matches that character only" do
146
- parse('A').should_not be_nil
147
- parse('\\').should be_nil
148
- parse('x').should be_nil
149
- parse('4').should be_nil
150
- parse('1').should be_nil
151
- end
152
- end
153
-
154
- describe "A character class containing an octal escape" do
155
- slash = "\\"
156
- testing_expression "[#{slash}101]"
157
- it "matches that character only" do
158
- parse('A').should_not be_nil
159
- parse('\\').should be_nil
160
- parse('1').should be_nil
161
- parse('0').should be_nil
162
- end
163
- end
164
-
165
- describe "A character class containing a \\c control-char escape" do
166
- slash = "\\"
167
- testing_expression "[#{slash}cC]"
168
- it "matches that character only" do
169
- parse("\003").should_not be_nil
170
- parse('\\').should be_nil
171
- parse('c').should be_nil
172
- parse('C').should be_nil
173
- end
174
- end
175
-
176
- describe "A character class containing a \\C- control-char escape" do
177
- slash = "\\"
178
- testing_expression "[#{slash}C-C]"
179
- it "matches that character only" do
180
- parse("\003").should_not be_nil
181
- parse('\\').should be_nil
182
- parse('C').should be_nil
183
- parse('-').should be_nil
184
- end
185
- end
186
-
187
- if RUBY_VERSION =~ /\A1\.8\./
188
- describe "A character class containing a \\M- meta-char escape" do
189
- slash = "\\"
190
- testing_expression "[#{slash}M- ]"
191
- it "matches that character only" do
192
- parse("\240").should_not be_nil
193
- parse('\\').should be_nil
194
- parse('M').should be_nil
195
- parse('-').should be_nil
196
- parse(' ').should be_nil
197
- end
198
- end
199
- end
200
-
201
- describe "A character class containing an escaped non-special character" do
202
- slash = "\\"
203
- testing_expression "[#{slash}y]"
204
- it "matches that character only" do
205
- parse("y").should_not be_nil
206
- parse('\\').should be_nil
207
- end
208
- end
209
-
210
- describe "A character class containing an \#{...} insertion" do
211
- testing_expression "[\#{raise 'error'}]"
212
- it "doesn't evaluate the insertion" do
213
- x = true
214
- lambda{
215
- x = parse("y")
216
- }.should_not raise_error
217
- x.should be_nil
218
- parse('#').should_not be_nil
219
- parse("'").should_not be_nil
220
- parse("0").should be_nil
221
- end
222
- end
223
-
224
- describe "a character class" do
225
- testing_expression "[A-Z]"
226
- it "actively generates a node for the character because it is the primary node" do
227
- result = parse('A')
228
- result.should be_a(Treetop::Runtime::SyntaxNode)
229
- result.elements.should be_nil
230
- end
231
- end
232
-
233
- describe "a character class mixed with other expressions" do
234
- testing_expression '[A-Z] "a" "bc"'
235
- it "lazily instantiates a node for the character" do
236
- result = parse('Aabc')
237
- result.instance_variable_get("@elements").should include(true)
238
- result.elements.should_not include(true)
239
- result.elements.size.should == 3
240
- end
241
- end
242
-
243
- describe "a character class with a node class declaration mixed with other expressions" do
244
- testing_expression '([A-Z] <CharacterClassSpec::Foo>) "ab"'
245
- it "actively generates a node for the character because it has a node class declared" do
246
- result = parse('Aab')
247
- result.instance_variable_get("@elements").should_not include(true)
248
- result.elements.should_not include(true)
249
- result.elements.size.should == 2
250
- end
251
- end
252
-
253
- describe "a character class with a node module declaration mixed with other expressions" do
254
- testing_expression '([A-Z] <CharacterClassSpec::ModFoo>) "ab"'
255
- it "actively generates a node for the character because it has a node module declared" do
256
- result = parse('Aab')
257
- result.instance_variable_get("@elements").should_not include(true)
258
- result.elements.should_not include(true)
259
- result.elements.size.should == 2
260
- end
261
- end
262
-
263
- describe "a character class with an inline block mixed with other expressions" do
264
- testing_expression '([A-Z] { def a_method; end }) "ab"'
265
- it "actively generates a node for the character because it has an inline block" do
266
- result = parse('Aab')
267
- result.instance_variable_get("@elements").should_not include(true)
268
- result.elements.should_not include(true)
269
- result.elements.size.should == 2
270
- end
271
- end
272
-
273
- describe "a character class with a label mixed with other expressions" do
274
- testing_expression 'upper:([A-Z]) "b" "cd"'
275
- it "returns the correct element for the labeled expression" do
276
- result = parse('Abcd')
277
- result.upper.text_value.should == "A"
278
- result.elements.size.should == 3
279
- end
280
- end
281
-
282
- describe "a character class repetition mixed with other expressions" do
283
- testing_expression '[A-Z]+ "a" "bc"'
284
- it "lazily instantiates a node for the character" do
285
- result = parse('ABCabc')
286
- result.elements[0].instance_variable_get("@elements").should include(true)
287
- result.elements[0].elements.should_not include(true)
288
- result.elements[0].elements.size.should == 3
289
- result.elements.size.should == 3
290
- result.elements.inspect.should == %Q{[SyntaxNode offset=0, "ABC":\n SyntaxNode offset=0, "A"\n SyntaxNode offset=1, "B"\n SyntaxNode offset=2, "C", SyntaxNode offset=3, "a", SyntaxNode offset=4, "bc"]}
291
- end
292
- end
293
-
294
- describe "a character class that gets cached because of a choice" do
295
- testing_expression "[A-Z] 'a' 'bc' / [A-Z]"
296
-
297
- it "generates a node for the lazily-instantiated character when it is the primary node" do
298
- result = parse('A')
299
- result.should be_a(Treetop::Runtime::SyntaxNode)
300
- result.elements.should be_nil
301
- end
302
- end
303
-
304
- end