treetop 1.6.6 → 1.6.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +18 -0
- data/History.txt +18 -0
- data/README.md +2 -0
- data/Rakefile +10 -43
- data/Treetop.tmbundle/Preferences/Comments.tmPreferences +28 -0
- data/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
- data/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
- data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
- data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
- data/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
- data/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +358 -0
- data/Treetop.tmbundle/info.plist +10 -0
- data/doc/pitfalls_and_advanced_techniques.markdown +6 -0
- data/doc/syntactic_recognition.markdown +2 -2
- data/lib/treetop/compiler/grammar_compiler.rb +6 -3
- data/lib/treetop/compiler/metagrammar.rb +97 -77
- data/lib/treetop/compiler/metagrammar.treetop +1 -1
- data/lib/treetop/compiler/ruby_builder.rb +2 -2
- data/lib/treetop/ruby_extensions/string.rb +0 -6
- data/lib/treetop/runtime/compiled_parser.rb +15 -2
- data/lib/treetop/version.rb +1 -1
- data/treetop.gemspec +25 -157
- metadata +15 -61
- data/doc/site.rb +0 -112
- data/doc/sitegen.rb +0 -65
- data/spec/compiler/and_predicate_spec.rb +0 -36
- data/spec/compiler/anything_symbol_spec.rb +0 -47
- data/spec/compiler/character_class_spec.rb +0 -304
- data/spec/compiler/choice_spec.rb +0 -89
- data/spec/compiler/circular_compilation_spec.rb +0 -30
- data/spec/compiler/failure_propagation_functional_spec.rb +0 -21
- data/spec/compiler/grammar_compiler_spec.rb +0 -113
- data/spec/compiler/grammar_spec.rb +0 -44
- data/spec/compiler/multibyte_chars_spec.rb +0 -38
- data/spec/compiler/namespace_spec.rb +0 -42
- data/spec/compiler/nonterminal_symbol_spec.rb +0 -40
- data/spec/compiler/not_predicate_spec.rb +0 -52
- data/spec/compiler/occurrence_range_spec.rb +0 -186
- data/spec/compiler/one_or_more_spec.rb +0 -35
- data/spec/compiler/optional_spec.rb +0 -37
- data/spec/compiler/parenthesized_expression_spec.rb +0 -34
- data/spec/compiler/parsing_rule_spec.rb +0 -61
- data/spec/compiler/repeated_subrule_spec.rb +0 -29
- data/spec/compiler/semantic_predicate_spec.rb +0 -176
- data/spec/compiler/sequence_spec.rb +0 -129
- data/spec/compiler/terminal_spec.rb +0 -177
- data/spec/compiler/terminal_symbol_spec.rb +0 -40
- data/spec/compiler/test_grammar.treetop +0 -7
- data/spec/compiler/test_grammar.tt +0 -7
- data/spec/compiler/test_grammar_do.treetop +0 -7
- data/spec/compiler/test_grammar_magic_coding.treetop +0 -8
- data/spec/compiler/test_grammar_magic_encoding.treetop +0 -8
- data/spec/compiler/tt_compiler_spec.rb +0 -224
- data/spec/compiler/zero_or_more_spec.rb +0 -58
- data/spec/composition/a.treetop +0 -11
- data/spec/composition/b.treetop +0 -11
- data/spec/composition/c.treetop +0 -10
- data/spec/composition/d.treetop +0 -10
- data/spec/composition/f.treetop +0 -17
- data/spec/composition/grammar_composition_spec.rb +0 -40
- data/spec/composition/subfolder/e_includes_c.treetop +0 -15
- data/spec/ruby_extensions/string_spec.rb +0 -32
- data/spec/runtime/compiled_parser_spec.rb +0 -153
- data/spec/runtime/syntax_node_spec.rb +0 -77
- data/spec/spec_helper.rb +0 -123
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.
|
4
|
+
version: 1.6.11
|
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:
|
12
|
+
date: 2020-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: polyglot
|
@@ -25,34 +25,20 @@ 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
|
45
31
|
requirements:
|
46
32
|
- - "~>"
|
47
33
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
34
|
+
version: '4'
|
49
35
|
type: :development
|
50
36
|
prerelease: false
|
51
37
|
version_requirements: !ruby/object:Gem::Requirement
|
52
38
|
requirements:
|
53
39
|
- - "~>"
|
54
40
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
41
|
+
version: '4'
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
43
|
name: i18n
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,17 +104,25 @@ 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
|
127
123
|
- doc/index.markdown
|
128
124
|
- doc/pitfalls_and_advanced_techniques.markdown
|
129
125
|
- doc/semantic_interpretation.markdown
|
130
|
-
- doc/site.rb
|
131
|
-
- doc/sitegen.rb
|
132
126
|
- doc/syntactic_recognition.markdown
|
133
127
|
- doc/tt.1
|
134
128
|
- doc/using_in_ruby.markdown
|
@@ -184,46 +178,6 @@ files:
|
|
184
178
|
- lib/treetop/runtime/terminal_parse_failure.rb
|
185
179
|
- lib/treetop/runtime/terminal_syntax_node.rb
|
186
180
|
- 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
181
|
- treetop.gemspec
|
228
182
|
homepage: https://github.com/cjheath/treetop
|
229
183
|
licenses:
|
@@ -245,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
199
|
version: '0'
|
246
200
|
requirements: []
|
247
201
|
rubyforge_project:
|
248
|
-
rubygems_version: 2.
|
202
|
+
rubygems_version: 2.7.6.2
|
249
203
|
signing_key:
|
250
204
|
specification_version: 4
|
251
205
|
summary: A Ruby-based text parsing and interpretation DSL
|
data/doc/site.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'erector'
|
3
|
-
require "#{File.dirname(__FILE__)}/sitegen"
|
4
|
-
require 'fileutils'
|
5
|
-
require 'bluecloth'
|
6
|
-
|
7
|
-
class Layout < Erector::Widget
|
8
|
-
def content
|
9
|
-
html do
|
10
|
-
head do
|
11
|
-
link :rel => "stylesheet",
|
12
|
-
:type => "text/css",
|
13
|
-
:href => "./screen.css"
|
14
|
-
|
15
|
-
rawtext %(
|
16
|
-
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
17
|
-
</script>
|
18
|
-
<script type="text/javascript">
|
19
|
-
_uacct = "UA-3418876-1";
|
20
|
-
urchinTracker();
|
21
|
-
</script>
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
body do
|
26
|
-
div :id => 'top' do
|
27
|
-
div :id => 'main_navigation' do
|
28
|
-
main_navigation
|
29
|
-
end
|
30
|
-
end
|
31
|
-
div :id => 'middle' do
|
32
|
-
div :id => 'main_content' do
|
33
|
-
main_content
|
34
|
-
end
|
35
|
-
end
|
36
|
-
div :id => 'bottom' do
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def main_navigation
|
44
|
-
ul do
|
45
|
-
li { link_to "Documentation", SyntacticRecognition, Documentation }
|
46
|
-
li { link_to "Contribute", Contribute }
|
47
|
-
li { link_to "Home", Index }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def main_content
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Index < Layout
|
56
|
-
def main_content
|
57
|
-
bluecloth "index.markdown"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class Documentation < Layout
|
62
|
-
abstract
|
63
|
-
|
64
|
-
def main_content
|
65
|
-
div :id => 'secondary_navigation' do
|
66
|
-
ul do
|
67
|
-
li { link_to 'Syntax', SyntacticRecognition }
|
68
|
-
li { link_to 'Semantics', SemanticInterpretation }
|
69
|
-
li { link_to 'Using In Ruby', UsingInRuby }
|
70
|
-
li { link_to 'Advanced Techniques', PitfallsAndAdvancedTechniques }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
div :id => 'documentation_content' do
|
75
|
-
documentation_content
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class SyntacticRecognition < Documentation
|
81
|
-
def documentation_content
|
82
|
-
bluecloth "syntactic_recognition.markdown"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
class SemanticInterpretation < Documentation
|
87
|
-
def documentation_content
|
88
|
-
bluecloth "semantic_interpretation.markdown"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class UsingInRuby < Documentation
|
93
|
-
def documentation_content
|
94
|
-
bluecloth "using_in_ruby.markdown"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class PitfallsAndAdvancedTechniques < Documentation
|
99
|
-
def documentation_content
|
100
|
-
bluecloth "pitfalls_and_advanced_techniques.markdown"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
class Contribute < Layout
|
106
|
-
def main_content
|
107
|
-
bluecloth "contributing_and_planned_features.markdown"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
Layout.generate_site
|
data/doc/sitegen.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
class Layout < Erector::Widget
|
2
|
-
|
3
|
-
class << self
|
4
|
-
def inherited(page_class)
|
5
|
-
puts page_class
|
6
|
-
(@@page_classes ||= []) << page_class
|
7
|
-
end
|
8
|
-
|
9
|
-
def generate_site
|
10
|
-
FileUtils.mkdir_p(site_dir)
|
11
|
-
@@page_classes.each do |page_class|
|
12
|
-
page_class.generate_html unless page_class.abstract?
|
13
|
-
puts page_class
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def generate_html
|
18
|
-
File.open(absolute_path, 'w') do |file|
|
19
|
-
file.write(new.to_html)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def absolute_path
|
24
|
-
absolutize(relative_path)
|
25
|
-
end
|
26
|
-
|
27
|
-
def relative_path
|
28
|
-
"#{name.gsub('::', '_').underscore}.html"
|
29
|
-
end
|
30
|
-
|
31
|
-
def absolutize(relative_path)
|
32
|
-
File.join(site_dir, relative_path)
|
33
|
-
end
|
34
|
-
|
35
|
-
def abstract
|
36
|
-
@abstract = true
|
37
|
-
end
|
38
|
-
|
39
|
-
def abstract?
|
40
|
-
@abstract
|
41
|
-
end
|
42
|
-
|
43
|
-
def site_dir
|
44
|
-
File.join(File.dirname(__FILE__), "../website")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def bluecloth(relative_path)
|
49
|
-
File.open(File.join(File.dirname(__FILE__), relative_path)) do |file|
|
50
|
-
rawtext BlueCloth.new(file.read).to_html
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def absolutize(relative_path)
|
55
|
-
self.class.absolutize(relative_path)
|
56
|
-
end
|
57
|
-
|
58
|
-
def link_to(link_text, page_class, section_class=nil)
|
59
|
-
if instance_of?(page_class) || section_class && is_a?(section_class)
|
60
|
-
text link_text
|
61
|
-
else
|
62
|
-
a link_text, :href => page_class.relative_path
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -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
|