less 0.8.13 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/Rakefile +21 -3
- data/VERSION +1 -1
- data/bin/lessc +0 -8
- data/less.gemspec +138 -15
- data/lib/less.rb +67 -11
- data/lib/less/command.rb +24 -25
- data/lib/less/engine.rb +36 -140
- data/lib/less/engine/builder.rb +8 -0
- data/lib/less/engine/less.tt +374 -0
- data/lib/less/engine/nodes.rb +8 -0
- data/lib/less/engine/nodes/element.rb +150 -0
- data/lib/less/engine/nodes/entity.rb +73 -0
- data/lib/less/engine/nodes/function.rb +82 -0
- data/lib/less/engine/nodes/literal.rb +135 -0
- data/lib/less/engine/nodes/property.rb +112 -0
- data/lib/less/engine/nodes/selector.rb +39 -0
- data/lib/less/engine/parser.rb +3860 -0
- data/lib/vendor/treetop/.gitignore +7 -0
- data/lib/vendor/treetop/LICENSE +19 -0
- data/lib/vendor/treetop/README +164 -0
- data/lib/vendor/treetop/Rakefile +19 -0
- data/lib/vendor/treetop/benchmark/seqpar.gnuplot +15 -0
- data/lib/vendor/treetop/benchmark/seqpar.treetop +16 -0
- data/lib/vendor/treetop/benchmark/seqpar_benchmark.rb +107 -0
- data/lib/vendor/treetop/bin/tt +28 -0
- data/lib/vendor/treetop/lib/treetop.rb +8 -0
- data/lib/vendor/treetop/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
- data/lib/vendor/treetop/lib/treetop/compiler.rb +6 -0
- data/lib/vendor/treetop/lib/treetop/compiler/grammar_compiler.rb +42 -0
- data/lib/vendor/treetop/lib/treetop/compiler/lexical_address_space.rb +17 -0
- data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.rb +3097 -0
- data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.treetop +408 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes.rb +19 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb +23 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/choice.rb +31 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/grammar.rb +28 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/optional.rb +19 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_rule.rb +55 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/predicate.rb +45 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb +55 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/sequence.rb +68 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/terminal.rb +20 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
- data/lib/vendor/treetop/lib/treetop/compiler/ruby_builder.rb +113 -0
- data/lib/vendor/treetop/lib/treetop/ruby_extensions.rb +2 -0
- data/lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb +42 -0
- data/lib/vendor/treetop/lib/treetop/runtime.rb +5 -0
- data/lib/vendor/treetop/lib/treetop/runtime/compiled_parser.rb +109 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list.rb +4 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
- data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
- data/lib/vendor/treetop/lib/treetop/runtime/syntax_node.rb +90 -0
- data/lib/vendor/treetop/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
- data/lib/vendor/treetop/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
- data/lib/vendor/treetop/lib/treetop/version.rb +9 -0
- data/lib/vendor/treetop/spec/compiler/and_predicate_spec.rb +36 -0
- data/lib/vendor/treetop/spec/compiler/anything_symbol_spec.rb +44 -0
- data/lib/vendor/treetop/spec/compiler/character_class_spec.rb +247 -0
- data/lib/vendor/treetop/spec/compiler/choice_spec.rb +80 -0
- data/lib/vendor/treetop/spec/compiler/circular_compilation_spec.rb +28 -0
- data/lib/vendor/treetop/spec/compiler/failure_propagation_functional_spec.rb +21 -0
- data/lib/vendor/treetop/spec/compiler/grammar_compiler_spec.rb +84 -0
- data/lib/vendor/treetop/spec/compiler/grammar_spec.rb +41 -0
- data/lib/vendor/treetop/spec/compiler/nonterminal_symbol_spec.rb +40 -0
- data/lib/vendor/treetop/spec/compiler/not_predicate_spec.rb +38 -0
- data/lib/vendor/treetop/spec/compiler/one_or_more_spec.rb +35 -0
- data/lib/vendor/treetop/spec/compiler/optional_spec.rb +37 -0
- data/lib/vendor/treetop/spec/compiler/parenthesized_expression_spec.rb +19 -0
- data/lib/vendor/treetop/spec/compiler/parsing_rule_spec.rb +32 -0
- data/lib/vendor/treetop/spec/compiler/sequence_spec.rb +115 -0
- data/lib/vendor/treetop/spec/compiler/terminal_spec.rb +81 -0
- data/lib/vendor/treetop/spec/compiler/terminal_symbol_spec.rb +37 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar.treetop +7 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar.tt +7 -0
- data/lib/vendor/treetop/spec/compiler/test_grammar_do.treetop +7 -0
- data/lib/vendor/treetop/spec/compiler/zero_or_more_spec.rb +56 -0
- data/lib/vendor/treetop/spec/composition/a.treetop +11 -0
- data/lib/vendor/treetop/spec/composition/b.treetop +11 -0
- data/lib/vendor/treetop/spec/composition/c.treetop +10 -0
- data/lib/vendor/treetop/spec/composition/d.treetop +10 -0
- data/lib/vendor/treetop/spec/composition/f.treetop +17 -0
- data/lib/vendor/treetop/spec/composition/grammar_composition_spec.rb +40 -0
- data/lib/vendor/treetop/spec/composition/subfolder/e_includes_c.treetop +15 -0
- data/lib/vendor/treetop/spec/ruby_extensions/string_spec.rb +32 -0
- data/lib/vendor/treetop/spec/runtime/compiled_parser_spec.rb +101 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
- data/lib/vendor/treetop/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
- data/lib/vendor/treetop/spec/runtime/syntax_node_spec.rb +68 -0
- data/lib/vendor/treetop/spec/spec_helper.rb +106 -0
- data/lib/vendor/treetop/spec/spec_suite.rb +4 -0
- data/lib/vendor/treetop/treetop.gemspec +17 -0
- data/spec/command_spec.rb +2 -6
- data/spec/css/accessors-1.0.css +18 -0
- data/spec/css/big-1.0.css +3768 -0
- data/spec/css/comments-1.0.css +9 -0
- data/spec/css/css-1.0.css +40 -0
- data/spec/css/functions-1.0.css +6 -0
- data/spec/css/import-1.0.css +11 -0
- data/spec/css/mixins-1.0.css +28 -0
- data/spec/css/operations-1.0.css +28 -0
- data/spec/css/rulesets-1.0.css +17 -0
- data/spec/css/scope-1.0.css +14 -0
- data/spec/css/strings-1.0.css +12 -0
- data/spec/css/variables-1.0.css +6 -0
- data/spec/css/whitespace-1.0.css +9 -0
- data/spec/engine_spec.rb +66 -18
- data/spec/less/accessors-1.0.less +20 -0
- data/spec/less/big-1.0.less +4810 -0
- data/spec/less/colors-1.0.less +0 -0
- data/spec/less/comments-1.0.less +46 -0
- data/spec/less/css-1.0.less +84 -0
- data/spec/less/exceptions/mixed-units-error.less +3 -0
- data/spec/less/exceptions/name-error-1.0.less +3 -0
- data/spec/less/exceptions/syntax-error-1.0.less +3 -0
- data/spec/less/functions-1.0.less +6 -0
- data/spec/less/import-1.0.less +7 -0
- data/spec/less/import/import-test-a.less +2 -0
- data/spec/less/import/import-test-b.less +8 -0
- data/spec/less/import/import-test-c.less +5 -0
- data/spec/less/mixins-1.0.less +43 -0
- data/spec/less/operations-1.0.less +39 -0
- data/spec/less/rulesets-1.0.less +30 -0
- data/spec/less/scope-1.0.less +33 -0
- data/spec/less/strings-1.0.less +14 -0
- data/spec/less/variables-1.0.less +18 -0
- data/spec/less/whitespace-1.0.less +21 -0
- data/spec/spec.css +79 -24
- data/spec/spec.less +2 -3
- data/spec/spec_helper.rb +4 -1
- metadata +136 -13
- data/lib/less/tree.rb +0 -82
- data/spec/css/less-0.8.10.css +0 -30
- data/spec/css/less-0.8.11.css +0 -31
- data/spec/css/less-0.8.12.css +0 -28
- data/spec/css/less-0.8.5.css +0 -24
- data/spec/css/less-0.8.6.css +0 -24
- data/spec/css/less-0.8.7.css +0 -24
- data/spec/css/less-0.8.8.css +0 -25
- data/spec/tree_spec.rb +0 -5
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module SequenceSpec
|
4
|
+
class Foo < Treetop::Runtime::SyntaxNode
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "a sequence of labeled terminal symbols followed by a node class declaration and a block" do
|
8
|
+
testing_expression 'foo:"foo" bar:"bar" baz:"baz" <SequenceSpec::Foo> { def a_method; end }'
|
9
|
+
|
10
|
+
it "upon successfully matching input, instantiates an instance of the declared node class with element accessor methods and the method from the inline module" do
|
11
|
+
parse('foobarbaz') do |result|
|
12
|
+
result.should_not be_nil
|
13
|
+
result.should be_an_instance_of(Foo)
|
14
|
+
result.should respond_to(:a_method)
|
15
|
+
result.foo.text_value.should == 'foo'
|
16
|
+
result.bar.text_value.should == 'bar'
|
17
|
+
result.baz.text_value.should == 'baz'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "successfully matches at a non-zero index" do
|
22
|
+
parse('---foobarbaz', :index => 3) do |result|
|
23
|
+
result.should_not be_nil
|
24
|
+
result.should be_nonterminal
|
25
|
+
(result.elements.map {|elt| elt.text_value}).join.should == 'foobarbaz'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "fails to match non-matching input, recording the parse failure of first non-matching terminal" do
|
30
|
+
parse('---foobazbaz', :index => 3) do |result|
|
31
|
+
result.should be_nil
|
32
|
+
parser.index.should == 3
|
33
|
+
terminal_failures = parser.terminal_failures
|
34
|
+
terminal_failures.size.should == 1
|
35
|
+
failure = terminal_failures.first
|
36
|
+
failure.index.should == 6
|
37
|
+
failure.expected_string.should == 'bar'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module ModFoo
|
43
|
+
def mod_method; end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "a sequence of labeled terminal symbols followed by a node module declaration and a block" do
|
47
|
+
testing_expression 'foo:"foo" bar:"bar" baz:"baz" <SequenceSpec::ModFoo> { def a_method; end }'
|
48
|
+
|
49
|
+
it "upon successfully matching input, instantiates a syntax node and extends it with the declared module, element accessor methods, and the method from the inline module" do
|
50
|
+
parse('foobarbaz') do |result|
|
51
|
+
result.should_not be_nil
|
52
|
+
result.should respond_to(:mod_method)
|
53
|
+
result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
|
54
|
+
result.should be_a_kind_of(ModFoo)
|
55
|
+
result.should respond_to(:a_method)
|
56
|
+
result.foo.text_value.should == 'foo'
|
57
|
+
result.bar.text_value.should == 'bar'
|
58
|
+
result.baz.text_value.should == 'baz'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "a sequence of non-terminals" do
|
64
|
+
testing_grammar %{
|
65
|
+
grammar TestGrammar
|
66
|
+
rule sequence
|
67
|
+
foo bar baz {
|
68
|
+
def baz
|
69
|
+
'override' + super.text_value
|
70
|
+
end
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
rule foo 'foo' end
|
75
|
+
rule bar 'bar' end
|
76
|
+
rule baz 'baz' end
|
77
|
+
end
|
78
|
+
}
|
79
|
+
|
80
|
+
it "defines accessors for non-terminals automatically that can be overridden in the inline block" do
|
81
|
+
parse('foobarbaz') do |result|
|
82
|
+
result.foo.text_value.should == 'foo'
|
83
|
+
result.bar.text_value.should == 'bar'
|
84
|
+
result.baz.should == 'overridebaz'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "Compiling a sequence containing various white-space errors" do
|
90
|
+
it "should succeed on a valid sequence" do
|
91
|
+
compiling_expression('foo:"foo" "bar" <SequenceSpec::Foo> { def a_method; end }').should_not raise_error
|
92
|
+
end
|
93
|
+
|
94
|
+
it "rejects space after a label" do
|
95
|
+
compiling_expression('foo :"foo" "bar"').should raise_error(RuntimeError)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "rejects space after label's colon" do
|
99
|
+
compiling_expression('foo: "foo" "bar"').should raise_error(RuntimeError)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "rejects missing space after a primary" do
|
103
|
+
compiling_expression('foo:"foo""bar"').should raise_error(RuntimeError)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "rejects missing space before node class declaration" do
|
107
|
+
compiling_expression('foo:"foo" "bar"<SequenceSpec::Foo>').should raise_error(RuntimeError)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "rejects missing space before inline module" do
|
111
|
+
compiling_expression('foo:"foo" "bar" <SequenceSpec::Foo>{def a_method; end}').should raise_error(RuntimeError)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module TerminalSymbolSpec
|
4
|
+
class Foo < Treetop::Runtime::SyntaxNode
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "a terminal symbol followed by a node class declaration and a block" do
|
8
|
+
testing_expression "'foo' <TerminalSymbolSpec::Foo> { def a_method; end }"
|
9
|
+
|
10
|
+
it "correctly parses matching input prefixes at various indices, returning an instance of the declared class that can respond to methods defined in the inline module" do
|
11
|
+
parse "foo", :index => 0 do |result|
|
12
|
+
result.should be_an_instance_of(Foo)
|
13
|
+
result.should respond_to(:a_method)
|
14
|
+
result.interval.should == (0...3)
|
15
|
+
result.text_value.should == 'foo'
|
16
|
+
end
|
17
|
+
|
18
|
+
parse "xfoo", :index => 1 do |result|
|
19
|
+
result.should be_an_instance_of(Foo)
|
20
|
+
result.should respond_to(:a_method)
|
21
|
+
result.interval.should == (1...4)
|
22
|
+
result.text_value.should == 'foo'
|
23
|
+
end
|
24
|
+
|
25
|
+
parse "---foo", :index => 3 do |result|
|
26
|
+
result.should be_an_instance_of(Foo)
|
27
|
+
result.should respond_to(:a_method)
|
28
|
+
result.interval.should == (3...6)
|
29
|
+
result.text_value.should == 'foo'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "fails to parse nonmatching input at the index even if a match occurs later" do
|
34
|
+
parse(" foo", :index => 0).should be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module ModFoo
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "a terminal symbol followed by a node class declaration and a block" do
|
42
|
+
testing_expression "'foo' <TerminalSymbolSpec::ModFoo> { def a_method; end }"
|
43
|
+
|
44
|
+
it "correctly parses matching input prefixes at various indices, returning an instance of SyntaxNode extended with the declared module that can respond to methods defined in the inline module" do
|
45
|
+
parse "foo", :index => 0 do |result|
|
46
|
+
result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
|
47
|
+
result.should be_a_kind_of(ModFoo)
|
48
|
+
result.should respond_to(:a_method)
|
49
|
+
result.interval.should == (0...3)
|
50
|
+
result.text_value.should == 'foo'
|
51
|
+
end
|
52
|
+
|
53
|
+
parse "xfoo", :index => 1 do |result|
|
54
|
+
result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
|
55
|
+
result.should be_a_kind_of(ModFoo)
|
56
|
+
result.should respond_to(:a_method)
|
57
|
+
result.interval.should == (1...4)
|
58
|
+
result.text_value.should == 'foo'
|
59
|
+
end
|
60
|
+
|
61
|
+
parse "---foo", :index => 3 do |result|
|
62
|
+
result.should be_an_instance_of(Treetop::Runtime::SyntaxNode)
|
63
|
+
result.should be_a_kind_of(ModFoo)
|
64
|
+
result.should respond_to(:a_method)
|
65
|
+
result.interval.should == (3...6)
|
66
|
+
result.text_value.should == 'foo'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "a transient terminal symbol" do
|
72
|
+
testing_expression "~'foo'"
|
73
|
+
|
74
|
+
it "returns true upon parsing matching input prefixes at various indices" do
|
75
|
+
pending "transient terminal expressions"
|
76
|
+
parse("foo", :index => 0).should be_true
|
77
|
+
parse("-foo", :index => 1).should be_true
|
78
|
+
parse("---foo", :index => 3).should be_true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module TerminalSymbolSpec
|
4
|
+
class Foo < Treetop::Runtime::SyntaxNode
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "a terminal symbol followed by a node class declaration and a block" do
|
8
|
+
testing_expression "'foo' <TerminalSymbolSpec::Foo> { def a_method; end }"
|
9
|
+
|
10
|
+
it "correctly parses matching input prefixes at various indices, returning an instance of the declared class that can respond to methods defined in the inline module" do
|
11
|
+
parse "foo", :index => 0 do |result|
|
12
|
+
result.should be_an_instance_of(Foo)
|
13
|
+
result.should respond_to(:a_method)
|
14
|
+
result.interval.should == (0...3)
|
15
|
+
result.text_value.should == 'foo'
|
16
|
+
end
|
17
|
+
|
18
|
+
parse "xfoo", :index => 1 do |result|
|
19
|
+
result.should be_an_instance_of(Foo)
|
20
|
+
result.should respond_to(:a_method)
|
21
|
+
result.interval.should == (1...4)
|
22
|
+
result.text_value.should == 'foo'
|
23
|
+
end
|
24
|
+
|
25
|
+
parse "---foo", :index => 3 do |result|
|
26
|
+
result.should be_an_instance_of(Foo)
|
27
|
+
result.should respond_to(:a_method)
|
28
|
+
result.interval.should == (3...6)
|
29
|
+
result.text_value.should == 'foo'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "fails to parse nonmatching input at the index even if a match occurs later" do
|
34
|
+
parse(" foo", :index => 0).should be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module ZeroOrMoreSpec
|
4
|
+
class Foo < Treetop::Runtime::SyntaxNode
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "zero or more of a terminal symbol followed by a node class declaration and a block" do
|
8
|
+
testing_expression '"foo"* <ZeroOrMoreSpec::Foo> { def a_method; end }'
|
9
|
+
|
10
|
+
it "successfully parses epsilon, returning an instance declared node class and recording a terminal failure" do
|
11
|
+
parse('') do |result|
|
12
|
+
result.should_not be_nil
|
13
|
+
result.should be_an_instance_of(Foo)
|
14
|
+
result.should respond_to(:a_method)
|
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 "successfully parses two of that terminal in a row, returning an instance of the declared node class and recording a failure representing the third attempt " do
|
25
|
+
parse("foofoo") do |result|
|
26
|
+
result.should_not be_nil
|
27
|
+
result.should be_an_instance_of(Foo)
|
28
|
+
|
29
|
+
terminal_failures = parser.terminal_failures
|
30
|
+
terminal_failures.size.should == 1
|
31
|
+
failure = terminal_failures.first
|
32
|
+
failure.index.should == 6
|
33
|
+
failure.expected_string.should == 'foo'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Zero or more of a sequence" do
|
39
|
+
testing_expression '("foo" "bar")*'
|
40
|
+
|
41
|
+
it "resets the index appropriately following partially matcing input" do
|
42
|
+
parse('foobarfoo', :consume_all_input => false) do |result|
|
43
|
+
result.should_not be_nil
|
44
|
+
result.interval.should == (0...6)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "Zero or more of a choice" do
|
50
|
+
testing_expression '("a" / "b")*'
|
51
|
+
|
52
|
+
it "successfully parses matching input" do
|
53
|
+
parse('abba').should_not be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module GrammarCompositionSpec
|
4
|
+
describe "several composed grammars" do
|
5
|
+
before do
|
6
|
+
dir = File.dirname(__FILE__)
|
7
|
+
Treetop.load File.join(dir, 'a')
|
8
|
+
Treetop.load File.join(dir, 'b')
|
9
|
+
Treetop.load File.join(dir, 'c')
|
10
|
+
# Check that polyglot finds d.treetop and loads it:
|
11
|
+
$: << dir
|
12
|
+
require 'd'
|
13
|
+
|
14
|
+
@c = ::Test::CParser.new
|
15
|
+
@d = ::Test::DParser.new
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "rules in C have access to rules defined in A and B" do
|
19
|
+
@c.parse('abc').should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "rules in C can override rules in A and B with super semantics" do
|
23
|
+
@d.parse('superkeywordworks').should_not be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "composed grammar chaining with require" do
|
28
|
+
before do
|
29
|
+
# Load f with polyglot without using the load path:
|
30
|
+
require File.dirname(__FILE__) + '/f'
|
31
|
+
|
32
|
+
@f = ::Test::FParser.new
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "rules in F have access to rule defined in E" do
|
36
|
+
@f.parse('abcef').should_not be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
before do
|
5
|
+
@string = %{
|
6
|
+
0123456789
|
7
|
+
012345
|
8
|
+
01234567
|
9
|
+
0123
|
10
|
+
}.tabto(0).strip
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can translate indices to column numbers" do
|
14
|
+
@string.column_of(0).should == 1
|
15
|
+
@string.column_of(5).should == 6
|
16
|
+
@string.column_of(10).should == 11
|
17
|
+
@string.column_of(11).should == 1
|
18
|
+
@string.column_of(17).should == 7
|
19
|
+
@string.column_of(18).should == 1
|
20
|
+
@string.column_of(24).should == 7
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can translate indices to line numbers" do
|
24
|
+
@string.line_of(0).should == 1
|
25
|
+
@string.line_of(5).should == 1
|
26
|
+
@string.line_of(10).should == 1
|
27
|
+
@string.line_of(11).should == 2
|
28
|
+
@string.line_of(17).should == 2
|
29
|
+
@string.line_of(18).should == 3
|
30
|
+
@string.line_of(24).should == 3
|
31
|
+
end
|
32
|
+
end
|