less 1.1.13 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +13 -41
- data/VERSION +1 -1
- data/bin/lessc +8 -2
- data/less.gemspec +13 -92
- data/lib/ext.rb +15 -19
- data/lib/less.rb +2 -2
- data/lib/less/command.rb +14 -15
- data/lib/less/engine.rb +3 -2
- data/lib/less/engine/grammar/common.tt +1 -1
- data/lib/less/engine/grammar/entity.tt +5 -5
- data/lib/less/engine/grammar/less.tt +107 -77
- data/lib/less/engine/nodes/element.rb +103 -24
- data/lib/less/engine/nodes/entity.rb +3 -3
- data/lib/less/engine/nodes/function.rb +11 -6
- data/lib/less/engine/nodes/literal.rb +8 -4
- data/lib/less/engine/nodes/property.rb +98 -38
- data/lib/less/engine/nodes/selector.rb +1 -1
- data/spec/css/css-3.css +14 -0
- data/spec/css/mixins-args.css +31 -0
- data/spec/css/variables.css +1 -0
- data/spec/css/whitespace.css +1 -0
- data/spec/engine_spec.rb +4 -3
- data/spec/less/css-3.less +30 -0
- data/spec/less/hidden.less +25 -0
- data/spec/less/import.less +1 -0
- data/spec/less/literal-css.less +11 -0
- data/spec/less/mixins-args.less +50 -0
- data/spec/less/variables.less +7 -1
- data/spec/less/whitespace.less +1 -0
- data/spec/spec_helper.rb +2 -2
- metadata +25 -94
- data/lib/vendor/treetop/.gitignore +0 -7
- data/lib/vendor/treetop/LICENSE +0 -19
- data/lib/vendor/treetop/README +0 -164
- data/lib/vendor/treetop/Rakefile +0 -19
- data/lib/vendor/treetop/benchmark/seqpar.gnuplot +0 -15
- data/lib/vendor/treetop/benchmark/seqpar.treetop +0 -16
- data/lib/vendor/treetop/benchmark/seqpar_benchmark.rb +0 -107
- data/lib/vendor/treetop/bin/tt +0 -28
- data/lib/vendor/treetop/lib/treetop.rb +0 -8
- data/lib/vendor/treetop/lib/treetop/bootstrap_gen_1_metagrammar.rb +0 -45
- data/lib/vendor/treetop/lib/treetop/compiler.rb +0 -6
- data/lib/vendor/treetop/lib/treetop/compiler/grammar_compiler.rb +0 -42
- data/lib/vendor/treetop/lib/treetop/compiler/lexical_address_space.rb +0 -17
- data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.rb +0 -3097
- data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.treetop +0 -408
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes.rb +0 -19
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/anything_symbol.rb +0 -18
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/atomic_expression.rb +0 -14
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb +0 -24
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/choice.rb +0 -31
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/declaration_sequence.rb +0 -24
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/grammar.rb +0 -28
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/inline_module.rb +0 -27
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/nonterminal.rb +0 -13
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/optional.rb +0 -19
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parenthesized_expression.rb +0 -9
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_expression.rb +0 -138
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_rule.rb +0 -55
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/predicate.rb +0 -45
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb +0 -55
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/sequence.rb +0 -68
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/terminal.rb +0 -20
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/transient_prefix.rb +0 -9
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/treetop_file.rb +0 -9
- data/lib/vendor/treetop/lib/treetop/compiler/ruby_builder.rb +0 -113
- data/lib/vendor/treetop/lib/treetop/ruby_extensions.rb +0 -2
- data/lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb +0 -42
- data/lib/vendor/treetop/lib/treetop/runtime.rb +0 -5
- data/lib/vendor/treetop/lib/treetop/runtime/compiled_parser.rb +0 -105
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list.rb +0 -4
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/head_node.rb +0 -15
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +0 -200
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/node.rb +0 -164
- data/lib/vendor/treetop/lib/treetop/runtime/syntax_node.rb +0 -72
- data/lib/vendor/treetop/lib/treetop/runtime/terminal_parse_failure.rb +0 -16
- data/lib/vendor/treetop/lib/treetop/runtime/terminal_syntax_node.rb +0 -17
- data/lib/vendor/treetop/lib/treetop/version.rb +0 -9
- data/lib/vendor/treetop/spec/compiler/and_predicate_spec.rb +0 -36
- data/lib/vendor/treetop/spec/compiler/anything_symbol_spec.rb +0 -44
- data/lib/vendor/treetop/spec/compiler/character_class_spec.rb +0 -182
- data/lib/vendor/treetop/spec/compiler/choice_spec.rb +0 -80
- data/lib/vendor/treetop/spec/compiler/circular_compilation_spec.rb +0 -28
- data/lib/vendor/treetop/spec/compiler/failure_propagation_functional_spec.rb +0 -21
- data/lib/vendor/treetop/spec/compiler/grammar_compiler_spec.rb +0 -84
- data/lib/vendor/treetop/spec/compiler/grammar_spec.rb +0 -41
- data/lib/vendor/treetop/spec/compiler/nonterminal_symbol_spec.rb +0 -40
- data/lib/vendor/treetop/spec/compiler/not_predicate_spec.rb +0 -38
- data/lib/vendor/treetop/spec/compiler/one_or_more_spec.rb +0 -35
- data/lib/vendor/treetop/spec/compiler/optional_spec.rb +0 -37
- data/lib/vendor/treetop/spec/compiler/parenthesized_expression_spec.rb +0 -19
- data/lib/vendor/treetop/spec/compiler/parsing_rule_spec.rb +0 -32
- data/lib/vendor/treetop/spec/compiler/sequence_spec.rb +0 -115
- data/lib/vendor/treetop/spec/compiler/terminal_spec.rb +0 -81
- data/lib/vendor/treetop/spec/compiler/terminal_symbol_spec.rb +0 -37
- data/lib/vendor/treetop/spec/compiler/test_grammar.treetop +0 -7
- data/lib/vendor/treetop/spec/compiler/test_grammar.tt +0 -7
- data/lib/vendor/treetop/spec/compiler/test_grammar_do.treetop +0 -7
- data/lib/vendor/treetop/spec/compiler/zero_or_more_spec.rb +0 -56
- data/lib/vendor/treetop/spec/composition/a.treetop +0 -11
- data/lib/vendor/treetop/spec/composition/b.treetop +0 -11
- data/lib/vendor/treetop/spec/composition/c.treetop +0 -10
- data/lib/vendor/treetop/spec/composition/d.treetop +0 -10
- data/lib/vendor/treetop/spec/composition/f.treetop +0 -17
- data/lib/vendor/treetop/spec/composition/grammar_composition_spec.rb +0 -40
- data/lib/vendor/treetop/spec/composition/subfolder/e_includes_c.treetop +0 -15
- data/lib/vendor/treetop/spec/ruby_extensions/string_spec.rb +0 -32
- data/lib/vendor/treetop/spec/runtime/compiled_parser_spec.rb +0 -101
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_and_delete_node.rb +0 -385
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -23
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -164
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/spec_helper.rb +0 -84
- data/lib/vendor/treetop/spec/runtime/syntax_node_spec.rb +0 -53
- data/lib/vendor/treetop/spec/spec_helper.rb +0 -106
- data/lib/vendor/treetop/spec/spec_suite.rb +0 -4
- data/lib/vendor/treetop/treetop.gemspec +0 -17
@@ -1,58 +0,0 @@
|
|
1
|
-
#require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
|
2
|
-
#
|
3
|
-
#MAX_INTERVAL = 100000
|
4
|
-
#
|
5
|
-
#describe IntervalSkipList do
|
6
|
-
# describe "#next_node_height" do
|
7
|
-
# attr_reader :list
|
8
|
-
#
|
9
|
-
# before do
|
10
|
-
# @list = IntervalSkipList.new
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# it "returns a number between 1 and the max_height of the list" do
|
14
|
-
# height = list.next_node_height
|
15
|
-
# height.should be <= list.max_height
|
16
|
-
# height.should be > 0
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# describe "a list with 1000 random intervals" do
|
21
|
-
# attr_reader :list, :inserted_ranges
|
22
|
-
#
|
23
|
-
# before do
|
24
|
-
# @list = IntervalSkipList.new
|
25
|
-
# @inserted_ranges = []
|
26
|
-
#
|
27
|
-
# 0.upto(10) do |i|
|
28
|
-
# first, last = [rand(MAX_INTERVAL), rand(MAX_INTERVAL)].sort
|
29
|
-
# range = first..last
|
30
|
-
# list.insert(range, i)
|
31
|
-
# inserted_ranges.push(range)
|
32
|
-
# end
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# it "functions correctly for stabbing queries" do
|
36
|
-
# 10000.times do
|
37
|
-
# n = rand(MAX_INTERVAL)
|
38
|
-
# ranges = list.containing(n).sort
|
39
|
-
#
|
40
|
-
# expected_ranges = []
|
41
|
-
# inserted_ranges.each_with_index do |range,i|
|
42
|
-
# expected_ranges.push(i) if n > range.first && n < range.last
|
43
|
-
# end
|
44
|
-
# expected_ranges.sort!
|
45
|
-
# unless ranges == expected_ranges
|
46
|
-
# puts "N = #{n}"
|
47
|
-
# puts "Expected: " + expected_ranges.inspect
|
48
|
-
# puts "Actual: " + ranges.inspect
|
49
|
-
# expected_ranges.size.should be <= ranges.size
|
50
|
-
# puts "Missing containers: #{(expected_ranges.map {|o| o.object_id} - ranges.map {|o| o.object_id}).inspect}"
|
51
|
-
# puts "Unexpected containers: #{(ranges.map {|o| o.object_id} - expected_ranges.map {|o| o.object_id}).inspect}"
|
52
|
-
# puts "Inserted Ranges: #{inserted_ranges.inspect}"
|
53
|
-
# puts "Expected Ranges: #{expected_ranges.map {|i| inserted_ranges[i]}.inspect}"
|
54
|
-
# end
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
#end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
describe "the palindromic fixture", :shared => true do
|
2
|
-
attr_reader :list, :node
|
3
|
-
include IntervalSkipListSpecHelper
|
4
|
-
|
5
|
-
before do
|
6
|
-
@list = IntervalSkipList.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it_should_behave_like "#next_node_height is deterministic"
|
10
|
-
def expected_node_heights
|
11
|
-
[3, 2, 1, 3, 1, 2, 3]
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
list.insert(1..3, :a)
|
16
|
-
list.insert(1..5, :b)
|
17
|
-
list.insert(1..7, :c)
|
18
|
-
list.insert(1..9, :d)
|
19
|
-
list.insert(1..11, :e)
|
20
|
-
list.insert(1..13, :f)
|
21
|
-
list.insert(5..13, :g)
|
22
|
-
end
|
23
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
-
require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
|
3
|
-
|
4
|
-
describe "The palindromic fixture" do
|
5
|
-
it_should_behave_like "the palindromic fixture"
|
6
|
-
|
7
|
-
describe " #nodes" do
|
8
|
-
describe "[0]" do
|
9
|
-
before do
|
10
|
-
@node = list.nodes[0]
|
11
|
-
end
|
12
|
-
|
13
|
-
it "has a key of 1 and a height of 3" do
|
14
|
-
node.key.should == 1
|
15
|
-
node.height.should == 3
|
16
|
-
end
|
17
|
-
|
18
|
-
it "has :c, :d, :e, and :f as its only forward markers at level 2" do
|
19
|
-
node.forward_markers[2].should have_markers(:c, :d, :e, :f)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "has :a, :b as its only forward markers at level 1" do
|
23
|
-
node.forward_markers[1].should have_markers(:a, :b)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "has no forward markers at level 0" do
|
27
|
-
node.forward_markers[0].should be_empty
|
28
|
-
end
|
29
|
-
|
30
|
-
it "has no markers" do
|
31
|
-
node.markers.should be_empty
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "[1]" do
|
36
|
-
before do
|
37
|
-
@node = list.nodes[1]
|
38
|
-
end
|
39
|
-
|
40
|
-
it "has a key of 3 and a height of 2" do
|
41
|
-
node.key.should == 3
|
42
|
-
node.height.should == 2
|
43
|
-
end
|
44
|
-
|
45
|
-
it "has no forward markers at level 1" do
|
46
|
-
node.forward_markers[1].should be_empty
|
47
|
-
end
|
48
|
-
|
49
|
-
it "has :b as its only forward marker at level 0" do
|
50
|
-
node.forward_markers[0].should have_marker(:b)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "has :a and :b as its only markers" do
|
54
|
-
node.markers.should have_markers(:a, :b)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "[2]" do
|
59
|
-
before do
|
60
|
-
@node = list.nodes[2]
|
61
|
-
end
|
62
|
-
|
63
|
-
it "has a key of 5 and a height of 1" do
|
64
|
-
node.key.should == 5
|
65
|
-
node.height.should == 1
|
66
|
-
end
|
67
|
-
|
68
|
-
it "has :g as its only forward marker at level 0" do
|
69
|
-
node.forward_markers[0].should have_marker(:g)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "has :b as its only marker" do
|
73
|
-
node.markers.should have_marker(:b)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "[3]" do
|
78
|
-
before do
|
79
|
-
@node = list.nodes[3]
|
80
|
-
end
|
81
|
-
|
82
|
-
it "has a key of 7 and a height of 3" do
|
83
|
-
node.key.should == 7
|
84
|
-
node.height.should == 3
|
85
|
-
end
|
86
|
-
|
87
|
-
it "has :f and :g as its only forward markers at level 2" do
|
88
|
-
node.forward_markers[2].should have_markers(:f, :g)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "has :e as its only forward markers at level 1" do
|
92
|
-
node.forward_markers[1].should have_marker(:e)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "has :d as its only forward marker at level 0" do
|
96
|
-
node.forward_markers[0].should have_markers(:d)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "has :c, :d, :e, :f and :g as its only markers" do
|
100
|
-
node.markers.should have_markers(:c, :d, :e, :f, :g)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "[4]" do
|
105
|
-
before do
|
106
|
-
@node = list.nodes[4]
|
107
|
-
end
|
108
|
-
|
109
|
-
it "has a key of 9 and a height of 1" do
|
110
|
-
node.key.should == 9
|
111
|
-
node.height.should == 1
|
112
|
-
end
|
113
|
-
|
114
|
-
it "has no forward markers at any level" do
|
115
|
-
node.forward_markers[0].should be_empty
|
116
|
-
end
|
117
|
-
|
118
|
-
it "has :d as its only marker" do
|
119
|
-
node.markers.should have_markers(:d)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "[5]" do
|
124
|
-
before do
|
125
|
-
@node = list.nodes[5]
|
126
|
-
end
|
127
|
-
|
128
|
-
it "has a key of 11 and a height of 2" do
|
129
|
-
node.key.should == 11
|
130
|
-
node.height.should == 2
|
131
|
-
end
|
132
|
-
|
133
|
-
it "has no forward markers at any level" do
|
134
|
-
node.forward_markers[0].should be_empty
|
135
|
-
node.forward_markers[1].should be_empty
|
136
|
-
end
|
137
|
-
|
138
|
-
it "has :e as its only marker" do
|
139
|
-
node.markers.should have_markers(:e)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "[6]" do
|
144
|
-
before do
|
145
|
-
@node = list.nodes[6]
|
146
|
-
end
|
147
|
-
|
148
|
-
it "has a key of 13 and a height of 3" do
|
149
|
-
node.key.should == 13
|
150
|
-
node.height.should == 3
|
151
|
-
end
|
152
|
-
|
153
|
-
it "has no forward markers at any level" do
|
154
|
-
node.forward_markers[0].should be_empty
|
155
|
-
node.forward_markers[1].should be_empty
|
156
|
-
node.forward_markers[2].should be_empty
|
157
|
-
end
|
158
|
-
|
159
|
-
it "has :f and :g as its only markers" do
|
160
|
-
node.markers.should have_markers(:f, :g)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
-
|
3
|
-
class IntervalSkipList
|
4
|
-
public :insert_node, :delete_node, :nodes, :head, :next_node_height
|
5
|
-
end
|
6
|
-
|
7
|
-
describe "#next_node_height is deterministic", :shared => true do
|
8
|
-
before do
|
9
|
-
node_heights = expected_node_heights.dup
|
10
|
-
stub(list).next_node_height { node_heights.shift }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module IntervalSkipListSpecHelper
|
15
|
-
def contain_marker(marker)
|
16
|
-
ContainMarkers.new(list, [marker])
|
17
|
-
end
|
18
|
-
|
19
|
-
def contain_markers(*markers)
|
20
|
-
ContainMarkers.new(list, markers)
|
21
|
-
end
|
22
|
-
|
23
|
-
class ContainMarkers
|
24
|
-
attr_reader :failure_message
|
25
|
-
|
26
|
-
def initialize(list, expected_markers)
|
27
|
-
@list = list
|
28
|
-
@expected_markers = expected_markers
|
29
|
-
end
|
30
|
-
|
31
|
-
def matches?(target_range)
|
32
|
-
@target_range = target_range
|
33
|
-
|
34
|
-
@target_range.each do |i|
|
35
|
-
markers = @list.containing(i)
|
36
|
-
|
37
|
-
@expected_markers.each do |expected_marker|
|
38
|
-
unless markers.include?(expected_marker)
|
39
|
-
@failure_message = "Expected #{expected_marker.inspect} to contain #{i}, but it doesn't. #{i} is contained by: #{markers.inspect}."
|
40
|
-
return false
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
markers.each do |marker|
|
45
|
-
unless @expected_markers.include?(marker)
|
46
|
-
@failure_message = "Did not expect #{marker.inspect} to contain #{i}. Only expected #{@expected_markers.inspect}."
|
47
|
-
return false
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def have_markers(*markers)
|
57
|
-
HaveMarkers.new(markers)
|
58
|
-
end
|
59
|
-
|
60
|
-
def have_marker(marker)
|
61
|
-
HaveMarkers.new([marker])
|
62
|
-
end
|
63
|
-
|
64
|
-
class HaveMarkers
|
65
|
-
def initialize(expected_markers)
|
66
|
-
@expected_markers = expected_markers
|
67
|
-
end
|
68
|
-
|
69
|
-
def matches?(target)
|
70
|
-
@target = target
|
71
|
-
return false unless @target.size == @expected_markers.size
|
72
|
-
@expected_markers.each do |expected_marker|
|
73
|
-
return false unless @target.include?(expected_marker)
|
74
|
-
end
|
75
|
-
true
|
76
|
-
end
|
77
|
-
|
78
|
-
def failure_message
|
79
|
-
"Expected #{@target.inspect} to include only #{@expected_markers.inspect}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
require "#{File.dirname(__FILE__)}/palindromic_fixture"
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
-
|
3
|
-
module SyntaxNodeSpec
|
4
|
-
describe "A new terminal syntax node" do
|
5
|
-
attr_reader :node
|
6
|
-
|
7
|
-
before do
|
8
|
-
@node = Runtime::SyntaxNode.new("input", 0...3)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "reports itself as terminal" do
|
12
|
-
node.should be_terminal
|
13
|
-
node.should_not be_nonterminal
|
14
|
-
end
|
15
|
-
|
16
|
-
it "has a text value based on the input and the interval" do
|
17
|
-
node.text_value.should == "inp"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "has itself as its only element" do
|
21
|
-
node.elements.should be_nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "A new nonterminal syntax node" do
|
26
|
-
attr_reader :node
|
27
|
-
|
28
|
-
before do
|
29
|
-
@input = 'test input'
|
30
|
-
@elements = [Runtime::SyntaxNode.new('input', 0...3)]
|
31
|
-
@node = Runtime::SyntaxNode.new('input', 0...3, @elements)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "reports itself as nonterminal" do
|
35
|
-
node.should be_nonterminal
|
36
|
-
node.should_not be_terminal
|
37
|
-
end
|
38
|
-
|
39
|
-
it "has a text value based on the input and the interval" do
|
40
|
-
node.text_value.should == "inp"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "has the elements with which it was instantiated" do
|
44
|
-
node.elements.should == @elements
|
45
|
-
end
|
46
|
-
|
47
|
-
it "sets itself as the parent of its elements" do
|
48
|
-
node.elements.each do |element|
|
49
|
-
element.parent.should == node
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
dir = File.dirname(__FILE__)
|
2
|
-
require 'rubygems'
|
3
|
-
require 'benchmark'
|
4
|
-
require 'spec'
|
5
|
-
|
6
|
-
unless $bootstrapped_gen_1_metagrammar
|
7
|
-
load File.join(dir, '..', 'lib', 'treetop', 'bootstrap_gen_1_metagrammar.rb')
|
8
|
-
end
|
9
|
-
include Treetop
|
10
|
-
|
11
|
-
Spec::Runner.configure do |config|
|
12
|
-
config.mock_with :rr
|
13
|
-
end
|
14
|
-
|
15
|
-
module Treetop
|
16
|
-
class TreetopExampleGroup < Spec::Example::ExampleGroup
|
17
|
-
class << self
|
18
|
-
attr_accessor :parser_class_under_test
|
19
|
-
|
20
|
-
def testing_expression(expression_under_test)
|
21
|
-
testing_grammar(%{
|
22
|
-
grammar Test
|
23
|
-
rule expression_under_test
|
24
|
-
}+expression_under_test+%{
|
25
|
-
end
|
26
|
-
end
|
27
|
-
}.tabto(0))
|
28
|
-
end
|
29
|
-
|
30
|
-
def testing_grammar(grammar_under_test)
|
31
|
-
grammar_node = parse_with_metagrammar(grammar_under_test.strip, :grammar)
|
32
|
-
parser_code = grammar_node.compile
|
33
|
-
class_eval(parser_code)
|
34
|
-
self.parser_class_under_test = const_get(grammar_node.parser_name.to_sym)
|
35
|
-
end
|
36
|
-
|
37
|
-
def parse_with_metagrammar(input, root)
|
38
|
-
parser = Treetop::Compiler::MetagrammarParser.new
|
39
|
-
parser.root = root
|
40
|
-
node = parser.parse(input)
|
41
|
-
raise parser.failure_reason unless node
|
42
|
-
node
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
attr_reader :parser
|
48
|
-
|
49
|
-
def parse_with_metagrammar(input, root)
|
50
|
-
self.class.parse_with_metagrammar(input, root)
|
51
|
-
end
|
52
|
-
|
53
|
-
def parser_class_under_test
|
54
|
-
self.class.parser_class_under_test
|
55
|
-
end
|
56
|
-
|
57
|
-
def parse(input, options = {})
|
58
|
-
@parser = parser_class_under_test.new
|
59
|
-
unless options[:consume_all_input].nil?
|
60
|
-
parser.consume_all_input = options.delete(:consume_all_input)
|
61
|
-
end
|
62
|
-
result = parser.parse(input, options)
|
63
|
-
yield result if block_given?
|
64
|
-
result
|
65
|
-
end
|
66
|
-
|
67
|
-
def compiling_grammar(grammar_under_test)
|
68
|
-
lambda {
|
69
|
-
grammar_node = parse_with_metagrammar(grammar_under_test.strip, :grammar)
|
70
|
-
parser_code = grammar_node.compile
|
71
|
-
[grammar_node, parser_code]
|
72
|
-
}
|
73
|
-
end
|
74
|
-
|
75
|
-
def compiling_expression(expression_under_test)
|
76
|
-
compiling_grammar(%{
|
77
|
-
grammar Test
|
78
|
-
rule expression_under_test
|
79
|
-
#{expression_under_test}
|
80
|
-
end
|
81
|
-
end
|
82
|
-
}.tabto(0))
|
83
|
-
end
|
84
|
-
|
85
|
-
def optionally_benchmark(&block)
|
86
|
-
if BENCHMARK
|
87
|
-
Benchmark.bm do |x|
|
88
|
-
x.report(&block)
|
89
|
-
end
|
90
|
-
else
|
91
|
-
yield
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
Spec::Example::ExampleGroupFactory.register(:compiler, self)
|
96
|
-
Spec::Example::ExampleGroupFactory.register(:runtime, self)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
class Symbol
|
101
|
-
def to_proc
|
102
|
-
lambda do |x|
|
103
|
-
x.send(self)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|