treetop 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +6 -6
- data/doc/images/bottom_background.png +0 -0
- data/doc/images/middle_backgound.png +0 -0
- data/doc/images/middle_background.png +0 -0
- data/doc/images/top_background.png +0 -0
- data/doc/index.markdown +13 -8
- data/doc/screen.css +52 -0
- data/doc/site.html +34 -0
- data/doc/site.rb +41 -0
- data/examples/lambda_calculus/lambda_calculus.rb +2 -2
- data/lib/treetop/bootstrap_gen_1_metagrammar.rb +37 -0
- data/lib/treetop/compiler/metagrammar. +0 -0
- data/lib/treetop/compiler/metagrammar.rb +20 -9
- data/lib/treetop/compiler/metagrammar.treetop +1 -1
- data/lib/treetop/compiler/node_classes/declaration_sequence.rb +1 -7
- data/lib/treetop/compiler/node_classes/grammar.rb +2 -2
- data/lib/treetop/runtime/compiled_parser.rb +15 -2
- metadata +12 -74
- data/test/compilation_target/target.rb +0 -143
- data/test/compilation_target/target.treetop +0 -15
- data/test/compilation_target/target_test.rb +0 -56
- data/test/compiler/and_predicate_test.rb +0 -33
- data/test/compiler/anything_symbol_test.rb +0 -24
- data/test/compiler/character_class_test.rb +0 -45
- data/test/compiler/choice_test.rb +0 -74
- data/test/compiler/circular_compilation_test.rb +0 -20
- data/test/compiler/failure_propagation_functional_test.rb +0 -20
- data/test/compiler/grammar_compiler_test.rb +0 -58
- data/test/compiler/grammar_test.rb +0 -37
- data/test/compiler/nonterminal_symbol_test.rb +0 -38
- data/test/compiler/not_predicate_test.rb +0 -35
- data/test/compiler/one_or_more_test.rb +0 -30
- data/test/compiler/optional_test.rb +0 -32
- data/test/compiler/parenthesized_expression_test.rb +0 -17
- data/test/compiler/parsing_rule_test.rb +0 -30
- data/test/compiler/sequence_test.rb +0 -68
- data/test/compiler/terminal_symbol_test.rb +0 -35
- data/test/compiler/test_grammar.treetop +0 -7
- data/test/compiler/zero_or_more_test.rb +0 -51
- data/test/composition/a.treetop +0 -11
- data/test/composition/b.treetop +0 -11
- data/test/composition/c.treetop +0 -10
- data/test/composition/d.treetop +0 -10
- data/test/composition/grammar_composition_test.rb +0 -23
- data/test/parser/syntax_node_test.rb +0 -53
- data/test/parser/terminal_parse_failure_test.rb +0 -22
- data/test/ruby_extensions/string_test.rb +0 -33
- data/test/screw/Rakefile +0 -16
- data/test/screw/unit.rb +0 -37
- data/test/screw/unit/assertion_failed_error.rb +0 -14
- data/test/screw/unit/assertions.rb +0 -615
- data/test/screw/unit/auto_runner.rb +0 -227
- data/test/screw/unit/collector.rb +0 -45
- data/test/screw/unit/collector/dir.rb +0 -107
- data/test/screw/unit/collector/objectspace.rb +0 -28
- data/test/screw/unit/error.rb +0 -48
- data/test/screw/unit/failure.rb +0 -45
- data/test/screw/unit/sugar.rb +0 -25
- data/test/screw/unit/test_case.rb +0 -176
- data/test/screw/unit/test_result.rb +0 -73
- data/test/screw/unit/test_suite.rb +0 -70
- data/test/screw/unit/ui.rb +0 -4
- data/test/screw/unit/ui/console/test_runner.rb +0 -118
- data/test/screw/unit/ui/fox/test_runner.rb +0 -268
- data/test/screw/unit/ui/gtk/test_runner.rb +0 -416
- data/test/screw/unit/ui/gtk2/testrunner.rb +0 -465
- data/test/screw/unit/ui/test_runner_mediator.rb +0 -58
- data/test/screw/unit/ui/test_runner_utilities.rb +0 -46
- data/test/screw/unit/ui/tk/test_runner.rb +0 -260
- data/test/screw/unit/util.rb +0 -4
- data/test/screw/unit/util/backtrace_filter.rb +0 -40
- data/test/screw/unit/util/observable.rb +0 -82
- data/test/screw/unit/util/proc_wrapper.rb +0 -48
- data/test/test_helper.rb +0 -90
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class GrammarTest < CompilerTestCase
|
4
|
-
module Bar
|
5
|
-
end
|
6
|
-
|
7
|
-
testing_grammar %{
|
8
|
-
grammar Foo
|
9
|
-
include Bar
|
10
|
-
|
11
|
-
rule foo
|
12
|
-
bar / baz
|
13
|
-
end
|
14
|
-
|
15
|
-
rule bar
|
16
|
-
'bar' 'bar'
|
17
|
-
end
|
18
|
-
|
19
|
-
rule baz
|
20
|
-
'baz' 'baz'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
}
|
24
|
-
|
25
|
-
it "parses matching input" do
|
26
|
-
parse('barbar').should be_success
|
27
|
-
parse('bazbaz').should be_success
|
28
|
-
end
|
29
|
-
|
30
|
-
it "fails if it does not parse all input" do
|
31
|
-
parse('barbarbazbaz').should be_failure
|
32
|
-
end
|
33
|
-
|
34
|
-
it "mixes in included modules" do
|
35
|
-
Foo.ancestors.should include(Bar)
|
36
|
-
end
|
37
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
describe "A nonterminal symbol followed by a block", :extend => CompilerTestCase do
|
4
|
-
testing_expression 'foo { def a_method; end }'
|
5
|
-
|
6
|
-
parser_class_under_test.class_eval do
|
7
|
-
def _nt_foo
|
8
|
-
'_nt_foo called'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "compiles to a method call, extending its results with the anonymous module for the block" do
|
13
|
-
result = parse('')
|
14
|
-
result.should == '_nt_foo called'
|
15
|
-
result.should respond_to(:a_method)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class NonterminalWithModuleDeclationTest < CompilerTestCase
|
20
|
-
module TestModule
|
21
|
-
def a_method
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
testing_expression 'foo <TestModule>'
|
26
|
-
|
27
|
-
parser_class_under_test.class_eval do
|
28
|
-
def _nt_foo
|
29
|
-
'_nt_foo called'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it "compiles to a method call, extending its results with the anonymous module for the block" do
|
34
|
-
result = parse('')
|
35
|
-
result.should == '_nt_foo called'
|
36
|
-
result.should respond_to(:a_method)
|
37
|
-
end
|
38
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
describe "A !-predicated terminal symbol", :extend => CompilerTestCase do
|
4
|
-
testing_expression '!"foo"'
|
5
|
-
|
6
|
-
it "fails to parse input matching the terminal symbol" do
|
7
|
-
parse('foo').should be_failure
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "A sequence of a terminal and an and another !-predicated terminal", :extend => CompilerTestCase do
|
12
|
-
testing_expression '"foo" !"bar"'
|
13
|
-
|
14
|
-
it "fails to match input matching both terminals" do
|
15
|
-
parse('foobar').should be_failure
|
16
|
-
end
|
17
|
-
|
18
|
-
it "successfully parses input matching the first terminal and not the second, with the failure of the second as a nested failure" do
|
19
|
-
parse('foo') do |result|
|
20
|
-
result.should be_success
|
21
|
-
result.nested_failures.size.should == 1
|
22
|
-
nested_failure = result.nested_failures[0]
|
23
|
-
nested_failure.index.should == 3
|
24
|
-
nested_failure.expected_string.should == 'bar'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "A !-predicated sequence", :extend => CompilerTestCase do
|
30
|
-
testing_expression '!("a" "b" "c")'
|
31
|
-
|
32
|
-
it "fails to parse matching input" do
|
33
|
-
parse('abc').should be_failure
|
34
|
-
end
|
35
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class OneOrMoreOfTerminalTest < CompilerTestCase
|
4
|
-
testing_expression '"foo"+ <Foo> { def a_method; end }'
|
5
|
-
|
6
|
-
class Foo < Treetop::Runtime::SyntaxNode
|
7
|
-
end
|
8
|
-
|
9
|
-
it "fails to parse epsilon with a nested failure" do
|
10
|
-
parse('') do |result|
|
11
|
-
result.should be_failure
|
12
|
-
result.nested_failures.size.should == 1
|
13
|
-
nested_failure = result.nested_failures.first
|
14
|
-
nested_failure.index.should == 0
|
15
|
-
nested_failure.expected_string.should == 'foo'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "successfully parses two of that terminal in a row, returning an instance of the declared node class with a nested failure representing the third attempt" do
|
20
|
-
parse("foofoo") do |result|
|
21
|
-
result.should be_success
|
22
|
-
result.should be_an_instance_of(Foo)
|
23
|
-
result.should respond_to(:a_method)
|
24
|
-
result.nested_failures.size.should == 1
|
25
|
-
nested_failure = result.nested_failures.first
|
26
|
-
nested_failure.index.should == 6
|
27
|
-
nested_failure.expected_string.should == 'foo'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
describe "An optional terminal symbol", :extend => CompilerTestCase do
|
4
|
-
testing_expression '"foo"?'
|
5
|
-
|
6
|
-
it "parses input matching the terminal" do
|
7
|
-
parse('foo').should be_success
|
8
|
-
end
|
9
|
-
|
10
|
-
it "parses epsilon, with a nested failure" do
|
11
|
-
parse('') do |result|
|
12
|
-
result.should be_success
|
13
|
-
result.interval.should == (0...0)
|
14
|
-
result.nested_failures.size.should == 1
|
15
|
-
nested_failure = result.nested_failures.first
|
16
|
-
nested_failure.index.should == 0
|
17
|
-
nested_failure.expected_string.should == 'foo'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it "parses input not matching the terminal, returning an epsilon result with a nested failure" do
|
22
|
-
parse('bar') do |result|
|
23
|
-
result.should be_success
|
24
|
-
result.interval.should == (0...0)
|
25
|
-
result.nested_failures.size.should == 1
|
26
|
-
nested_failure = result.nested_failures.first
|
27
|
-
nested_failure.index.should == 0
|
28
|
-
nested_failure.expected_string.should == 'foo'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
describe "An unadorned expression inside of parentheses", :extend => CompilerTestCase do
|
4
|
-
testing_expression '("foo")'
|
5
|
-
|
6
|
-
it "should behave as normal" do
|
7
|
-
parse('foo').should be_success
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "A prefixed-expression inside of parentheses", :extend => CompilerTestCase do
|
12
|
-
testing_expression '(!"foo")'
|
13
|
-
|
14
|
-
it "should behave as normal" do
|
15
|
-
parse('foo').should_not be_success
|
16
|
-
end
|
17
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class ParsingRuleTest < CompilerTestCase
|
4
|
-
|
5
|
-
testing_grammar %{
|
6
|
-
grammar Foo
|
7
|
-
rule bar
|
8
|
-
"baz"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
}
|
12
|
-
|
13
|
-
test "node cache storage and retrieval" do
|
14
|
-
parser = FooParser.new
|
15
|
-
parser.send(:prepare_to_parse, 'baz')
|
16
|
-
node_cache = parser.send(:node_cache)
|
17
|
-
|
18
|
-
node_cache[:bar][0].should be_nil
|
19
|
-
|
20
|
-
parser._nt_bar
|
21
|
-
|
22
|
-
cached_node = node_cache[:bar][0]
|
23
|
-
cached_node.should be_an_instance_of(Runtime::SyntaxNode)
|
24
|
-
cached_node.text_value.should == 'baz'
|
25
|
-
|
26
|
-
parser.instance_eval { @index = 0 }
|
27
|
-
parser._nt_bar.should equal(cached_node)
|
28
|
-
parser.index.should == cached_node.interval.end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class SequenceOfTerminalsTest < CompilerTestCase
|
4
|
-
|
5
|
-
class Foo < Treetop::Runtime::SyntaxNode
|
6
|
-
end
|
7
|
-
|
8
|
-
testing_expression 'foo:"foo" bar:"bar" baz:"baz" <Foo> { def a_method; end }'
|
9
|
-
|
10
|
-
test "successful result is 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 be_success
|
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
|
-
test "matching at a non-zero index" do
|
22
|
-
parse('---foobarbaz', :at_index => 3) do |result|
|
23
|
-
result.should be_success
|
24
|
-
result.should be_nonterminal
|
25
|
-
(result.elements.map {|elt| elt.text_value}).join.should == 'foobarbaz'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
test "non-matching input fails with a nested failure at the first terminal that did not match" do
|
30
|
-
parse('---foobazbaz', :at_index => 3) do |result|
|
31
|
-
result.should be_failure
|
32
|
-
result.index.should == 3
|
33
|
-
result.nested_failures.size.should == 1
|
34
|
-
nested_failure = result.nested_failures.first
|
35
|
-
nested_failure.index.should == 6
|
36
|
-
nested_failure.expected_string.should == 'bar'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class SequenceOfNonterminalsTest < CompilerTestCase
|
42
|
-
|
43
|
-
testing_grammar %{
|
44
|
-
grammar TestGrammar
|
45
|
-
rule sequence
|
46
|
-
foo bar baz {
|
47
|
-
def baz
|
48
|
-
'override' + super.text_value
|
49
|
-
end
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
rule foo 'foo' end
|
54
|
-
rule bar 'bar' end
|
55
|
-
rule baz 'baz' end
|
56
|
-
end
|
57
|
-
}
|
58
|
-
|
59
|
-
test "accessors for nonterminals are automatically defined and can be overridden in the inline block" do
|
60
|
-
parse('foobarbaz') do |result|
|
61
|
-
result.foo.text_value.should == 'foo'
|
62
|
-
result.bar.text_value.should == 'bar'
|
63
|
-
result.baz.should == 'overridebaz'
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class TerminalSymbolTest < CompilerTestCase
|
4
|
-
class Foo < Treetop::Runtime::SyntaxNode
|
5
|
-
end
|
6
|
-
|
7
|
-
testing_expression "'foo' <Foo> { def a_method; end }"
|
8
|
-
|
9
|
-
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
|
10
|
-
parse "foo", :at_index => 0 do |result|
|
11
|
-
result.should be_an_instance_of(Foo)
|
12
|
-
result.should respond_to(:a_method)
|
13
|
-
result.interval.should == (0...3)
|
14
|
-
result.text_value.should == 'foo'
|
15
|
-
end
|
16
|
-
|
17
|
-
parse "xfoo", :at_index => 1 do |result|
|
18
|
-
result.should be_an_instance_of(Foo)
|
19
|
-
result.should respond_to(:a_method)
|
20
|
-
result.interval.should == (1...4)
|
21
|
-
result.text_value.should == 'foo'
|
22
|
-
end
|
23
|
-
|
24
|
-
parse "---foo", :at_index => 3 do |result|
|
25
|
-
result.should be_an_instance_of(Foo)
|
26
|
-
result.should respond_to(:a_method)
|
27
|
-
result.interval.should == (3...6)
|
28
|
-
result.text_value.should == 'foo'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "fails to parse nonmatching input at the index even if a match occurs later" do
|
33
|
-
parse(" foo", :at_index => 0).should be_failure
|
34
|
-
end
|
35
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class ZeroOrMoreOfATerminalWithNodeClassDeclarationTest < CompilerTestCase
|
4
|
-
|
5
|
-
class Foo < Treetop::Runtime::SyntaxNode
|
6
|
-
end
|
7
|
-
|
8
|
-
testing_expression '"foo"* <Foo> { def a_method; end }'
|
9
|
-
|
10
|
-
it "successfully parses epsilon, returning an instance declared node class with a nested failure" do
|
11
|
-
parse('') do |result|
|
12
|
-
result.should be_success
|
13
|
-
result.should be_an_instance_of(Foo)
|
14
|
-
result.should respond_to(:a_method)
|
15
|
-
result.nested_failures.size.should == 1
|
16
|
-
nested_failure = result.nested_failures.first
|
17
|
-
nested_failure.index.should == 0
|
18
|
-
nested_failure.expected_string.should == 'foo'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "successfully parses two of that terminal in a row, returning an instance of the declared node class with a nested failure representing the third attempt " do
|
23
|
-
parse("foofoo") do |result|
|
24
|
-
result.should be_success
|
25
|
-
result.should be_an_instance_of(Foo)
|
26
|
-
result.nested_failures.size.should == 1
|
27
|
-
nested_failure = result.nested_failures.first
|
28
|
-
nested_failure.index.should == 6
|
29
|
-
nested_failure.expected_string.should == 'foo'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "Zero or more of a sequence", :extend => CompilerTestCase do
|
35
|
-
testing_expression '("foo" "bar")*'
|
36
|
-
|
37
|
-
it "resets the index appropriately following partially matcing input" do
|
38
|
-
parse('foobarfoo') do |result|
|
39
|
-
result.should be_success
|
40
|
-
result.interval.should == (0...6)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "Zero or more of a choice", :extend => CompilerTestCase do
|
46
|
-
testing_expression '("a" / "b")*'
|
47
|
-
|
48
|
-
it "successfully parses matching input" do
|
49
|
-
parse('abba').should be_success
|
50
|
-
end
|
51
|
-
end
|
data/test/composition/a.treetop
DELETED
data/test/composition/b.treetop
DELETED
data/test/composition/c.treetop
DELETED