treetop 1.5.3 → 1.6.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +5 -13
  2. data/Gemfile +12 -0
  3. data/History.txt +18 -0
  4. data/README.md +4 -0
  5. data/Rakefile +20 -40
  6. data/Treetop.tmbundle/Preferences/Comments.tmPreferences +28 -0
  7. data/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
  8. data/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
  9. data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
  10. data/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
  11. data/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
  12. data/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +358 -0
  13. data/Treetop.tmbundle/info.plist +10 -0
  14. data/doc/pitfalls_and_advanced_techniques.markdown +7 -1
  15. data/doc/syntactic_recognition.markdown +7 -2
  16. data/doc/tt.1 +1 -1
  17. data/examples/indented_blocks/indented_blocks.tt +73 -0
  18. data/examples/indented_blocks/indented_blocks_test.rb +24 -0
  19. data/lib/treetop/compiler/grammar_compiler.rb +6 -3
  20. data/lib/treetop/compiler/metagrammar.rb +301 -159
  21. data/lib/treetop/compiler/metagrammar.treetop +96 -13
  22. data/lib/treetop/compiler/node_classes/anything_symbol.rb +10 -2
  23. data/lib/treetop/compiler/node_classes/atomic_expression.rb +2 -2
  24. data/lib/treetop/compiler/node_classes/character_class.rb +10 -2
  25. data/lib/treetop/compiler/node_classes/choice.rb +11 -7
  26. data/lib/treetop/compiler/node_classes/nonterminal.rb +6 -2
  27. data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +5 -1
  28. data/lib/treetop/compiler/node_classes/parsing_expression.rb +10 -1
  29. data/lib/treetop/compiler/node_classes/parsing_rule.rb +1 -1
  30. data/lib/treetop/compiler/node_classes/predicate.rb +8 -1
  31. data/lib/treetop/compiler/node_classes/predicate_block.rb +7 -0
  32. data/lib/treetop/compiler/node_classes/repetition.rb +28 -8
  33. data/lib/treetop/compiler/node_classes/sequence.rb +5 -1
  34. data/lib/treetop/compiler/node_classes/terminal.rb +36 -22
  35. data/lib/treetop/compiler/ruby_builder.rb +2 -2
  36. data/lib/treetop/ruby_extensions/string.rb +0 -6
  37. data/lib/treetop/runtime/compiled_parser.rb +33 -14
  38. data/lib/treetop/runtime/syntax_node.rb +24 -15
  39. data/lib/treetop/runtime/terminal_parse_failure.rb +4 -3
  40. data/lib/treetop/runtime/terminal_syntax_node.rb +4 -4
  41. data/lib/treetop/version.rb +2 -2
  42. data/treetop.gemspec +25 -165
  43. metadata +43 -98
  44. data/doc/site.rb +0 -112
  45. data/doc/sitegen.rb +0 -65
  46. data/examples/lambda_calculus/lambda_calculus +0 -0
  47. data/spec/compiler/and_predicate_spec.rb +0 -36
  48. data/spec/compiler/anything_symbol_spec.rb +0 -44
  49. data/spec/compiler/character_class_spec.rb +0 -301
  50. data/spec/compiler/choice_spec.rb +0 -80
  51. data/spec/compiler/circular_compilation_spec.rb +0 -30
  52. data/spec/compiler/failure_propagation_functional_spec.rb +0 -21
  53. data/spec/compiler/grammar_compiler_spec.rb +0 -113
  54. data/spec/compiler/grammar_spec.rb +0 -41
  55. data/spec/compiler/multibyte_chars_spec.rb +0 -38
  56. data/spec/compiler/namespace_spec.rb +0 -42
  57. data/spec/compiler/nonterminal_symbol_spec.rb +0 -40
  58. data/spec/compiler/not_predicate_spec.rb +0 -38
  59. data/spec/compiler/occurrence_range_spec.rb +0 -189
  60. data/spec/compiler/one_or_more_spec.rb +0 -35
  61. data/spec/compiler/optional_spec.rb +0 -37
  62. data/spec/compiler/parenthesized_expression_spec.rb +0 -19
  63. data/spec/compiler/parsing_rule_spec.rb +0 -61
  64. data/spec/compiler/repeated_subrule_spec.rb +0 -29
  65. data/spec/compiler/semantic_predicate_spec.rb +0 -175
  66. data/spec/compiler/sequence_spec.rb +0 -129
  67. data/spec/compiler/terminal_spec.rb +0 -170
  68. data/spec/compiler/terminal_symbol_spec.rb +0 -37
  69. data/spec/compiler/test_grammar.treetop +0 -7
  70. data/spec/compiler/test_grammar.tt +0 -7
  71. data/spec/compiler/test_grammar_do.treetop +0 -7
  72. data/spec/compiler/test_grammar_magic_coding.treetop +0 -8
  73. data/spec/compiler/test_grammar_magic_encoding.treetop +0 -8
  74. data/spec/compiler/tt_compiler_spec.rb +0 -224
  75. data/spec/compiler/zero_or_more_spec.rb +0 -56
  76. data/spec/composition/a.treetop +0 -11
  77. data/spec/composition/b.treetop +0 -11
  78. data/spec/composition/c.treetop +0 -10
  79. data/spec/composition/d.treetop +0 -10
  80. data/spec/composition/f.treetop +0 -17
  81. data/spec/composition/grammar_composition_spec.rb +0 -40
  82. data/spec/composition/subfolder/e_includes_c.treetop +0 -15
  83. data/spec/ruby_extensions/string_spec.rb +0 -32
  84. data/spec/runtime/compiled_parser_spec.rb +0 -123
  85. data/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
  86. data/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
  87. data/spec/runtime/interval_skip_list/insert_and_delete_node_spec.rb +0 -385
  88. data/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
  89. data/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
  90. data/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
  91. data/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -35
  92. data/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -163
  93. data/spec/runtime/interval_skip_list/spec_helper.rb +0 -91
  94. data/spec/runtime/syntax_node_spec.rb +0 -77
  95. data/spec/spec_helper.rb +0 -115
@@ -1,10 +0,0 @@
1
- module Test
2
- grammar C
3
- include A
4
- include B
5
-
6
- rule c
7
- a b 'c'
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module Test
2
- grammar D
3
- include A
4
- include B
5
-
6
- rule inherit
7
- super 'works'
8
- end
9
- end
10
- end
@@ -1,17 +0,0 @@
1
-
2
- require "a"
3
-
4
- require File.dirname(__FILE__) + "/b"
5
- require File.dirname(__FILE__) + "/subfolder/e_includes_c"
6
-
7
- module Test
8
- grammar F
9
- include A
10
- include B
11
- include E
12
-
13
- rule f
14
- c e 'f'
15
- end
16
- end
17
- end
@@ -1,40 +0,0 @@
1
- require '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('abbc').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('abbcef').should_not be_nil
37
- end
38
-
39
- end
40
- end
@@ -1,15 +0,0 @@
1
- require File.dirname(__FILE__) + "/../c"
2
-
3
- module Test
4
- grammar E
5
- include C
6
-
7
- rule e
8
- 'e'
9
- end
10
-
11
- rule inherit
12
- 'super'
13
- end
14
- end
15
- end
@@ -1,32 +0,0 @@
1
- require '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
@@ -1,123 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module CompiledParserSpec
4
- describe Runtime::CompiledParser, "for a grammar with two rules" do
5
- attr_reader :parser
6
-
7
- testing_grammar %{
8
- grammar TwoRules
9
- rule a
10
- 'a'
11
- end
12
-
13
- rule b
14
- 'bb'
15
- end
16
- end
17
- }
18
-
19
- before do
20
- @parser = parser_class_under_test.new
21
- end
22
-
23
- it "allows its root to be specified" do
24
- parser.parse('a').should_not be_nil
25
- parser.parse('b').should be_nil
26
-
27
- # Check that the temporary-override works:
28
- parser.parse('bb', :root => :b).should_not be_nil
29
- parser.parse('a', :root => :b).should be_nil
30
-
31
- # Check that the temporary-override isn't sticky:
32
- parser.parse('a').should_not be_nil
33
-
34
- # Try a permanent override:
35
- parser.root = :b
36
- parser.parse('bb').should_not be_nil
37
- parser.parse('a').should be_nil
38
- end
39
-
40
- it "allows the requirement that all input be consumed to be disabled" do
41
- parser.parse('ab').should be_nil
42
-
43
- # Try a temporary override, and check it's not sticky:
44
- result = parser.parse('ab', :consume_all_input => false)
45
- result.should_not be_nil
46
- result.interval.should == (0...1)
47
- parser.parse('ab').should be_nil
48
-
49
- # Now a permanent override:
50
- parser.consume_all_input = false
51
- result = parser.parse('ab')
52
- result.should_not be_nil
53
- result.interval.should == (0...1)
54
- end
55
-
56
- it "allows input to be parsed at a given index" do
57
- parser.parse('ba').should be_nil
58
- parser.parse('ba', :index => 1).should_not be_nil
59
- # Check that the index defaults again to zero:
60
- parser.parse('a').should_not be_nil
61
-
62
- result = parser.parse('ba', :consume_all_input => false, :index => 1)
63
- result.should_not be_nil
64
- result.interval.should == (1...2)
65
- end
66
-
67
- end
68
-
69
- describe Runtime::CompiledParser, "for a grammar with a choice between terminals" do
70
- attr_reader :parser
71
-
72
- testing_grammar %{
73
- grammar Choice
74
- rule choice
75
- 'a' / 'b' / 'c'
76
- end
77
- end
78
- }
79
-
80
- before do
81
- @parser = parser_class_under_test.new
82
- end
83
-
84
- it "provides #failure_reason, #failure_column, and #failure_line when there is a parse failure" do
85
- parser.parse('z').should be_nil
86
- parser.failure_reason.should == "Expected one of a, b, c at line 1, column 1 (byte 1) after "
87
- parser.failure_line.should == 1
88
- parser.failure_column.should == 1
89
- end
90
- end
91
-
92
- describe Runtime::CompiledParser, "#terminal_failures" do
93
- attr_reader:parser
94
-
95
- testing_grammar %{
96
- grammar SequenceOfTerminals
97
- rule foo
98
- 'a' 'b' 'c'
99
- end
100
- end
101
- }
102
-
103
- before do
104
- @parser = parser_class_under_test.new
105
- end
106
-
107
- it "is reset between parses" do
108
- parser.parse('ac')
109
- terminal_failures = parser.terminal_failures
110
- terminal_failures.size.should == 1
111
- failure = terminal_failures.first
112
- failure.index.should == 1
113
- failure.expected_string.should == 'b'
114
-
115
- parser.parse('b')
116
- terminal_failures = parser.terminal_failures
117
- terminal_failures.size.should == 1
118
- failure = terminal_failures.first
119
- failure.index.should == 0
120
- failure.expected_string.should == 'a'
121
- end
122
- end
123
- end
@@ -1,147 +0,0 @@
1
- require 'runtime/interval_skip_list/spec_helper'
2
-
3
- class IntervalSkipList
4
- public :insert_node, :delete_node, :head, :nodes
5
- end
6
-
7
- describe IntervalSkipList, :palindromic => true do
8
- include PalindromicFixtureSharedContext
9
-
10
- describe " when :c is deleted" do
11
- before do
12
- list.delete(:c)
13
- end
14
-
15
- describe "[0]" do
16
- before do
17
- @node = list.nodes[0]
18
- end
19
-
20
- it "has a key of 1 and a height of 3" do
21
- node.key.should == 1
22
- node.height.should == 3
23
- end
24
-
25
- it "has :f as its only forward marker at level 2" do
26
- node.forward_markers[2].should have_markers(:f)
27
- end
28
-
29
- it "has :a, :b, :d, and :e as its only forward markers at level 1" do
30
- node.forward_markers[1].should have_markers(:a, :b, :d, :e)
31
- end
32
-
33
- it "has no forward markers at level 0" do
34
- node.forward_markers[0].should be_empty
35
- end
36
-
37
- it "has no markers" do
38
- node.markers.should be_empty
39
- end
40
- end
41
-
42
- describe "[1]" do
43
- before do
44
- @node = list.nodes[1]
45
- end
46
-
47
- it "has a key of 3 and a height of 2" do
48
- node.key.should == 3
49
- node.height.should == 2
50
- end
51
-
52
- it "has :e as its only forward marker at level 1" do
53
- node.forward_markers[1].should have_markers(:e)
54
- end
55
-
56
- it "has :b and :d as its only forward markers at level 0" do
57
- node.forward_markers[0].should have_markers(:b, :d)
58
- end
59
-
60
- it "has :a, :b, :d, and :e as its only markers" do
61
- node.markers.should have_markers(:a, :b, :d, :e)
62
- end
63
- end
64
-
65
- describe "[2]" do
66
- before do
67
- @node = list.nodes[2]
68
- end
69
-
70
- it "has a key of 5 and a height of 1" do
71
- node.key.should == 5
72
- node.height.should == 1
73
- end
74
-
75
- it "has :d and :g as its only forward markers at level 0" do
76
- node.forward_markers[0].should have_markers(:d, :g)
77
- end
78
-
79
- it "has :b and :d as its only markers" do
80
- node.markers.should have_markers(:b, :d)
81
- end
82
- end
83
-
84
- describe "[3]" do
85
- before do
86
- @node = list.nodes[3]
87
- end
88
-
89
- it "has a key of 9 and a height of 1" do
90
- node.key.should == 9
91
- node.height.should == 1
92
- end
93
-
94
- it "has :g as its only forward marker at level 0" do
95
- node.forward_markers[0].should have_markers(:g)
96
- end
97
-
98
- it "has :d and :g as its only markers" do
99
- node.markers.should have_markers(:d, :g)
100
- end
101
- end
102
-
103
- describe "[4]" do
104
- before do
105
- @node = list.nodes[4]
106
- end
107
-
108
- it "has a key of 11 and a height of 2" do
109
- node.key.should == 11
110
- node.height.should == 2
111
- end
112
-
113
- it "has :g as its only forward marker at level 1" do
114
- node.forward_markers[1].should have_markers(:g)
115
- end
116
-
117
- it "has no forward markers at level 0" do
118
- node.forward_markers[0].should be_empty
119
- end
120
-
121
- it "has :e and :g as its only markers" do
122
- node.markers.should have_markers(:e, :g)
123
- end
124
- end
125
-
126
- describe "[5]" do
127
- before do
128
- @node = list.nodes[5]
129
- end
130
-
131
- it "has a key of 13 and a height of 3" do
132
- node.key.should == 13
133
- node.height.should == 3
134
- end
135
-
136
- it "has no forward markers at any level" do
137
- node.forward_markers[0].should be_empty
138
- node.forward_markers[1].should be_empty
139
- node.forward_markers[2].should be_empty
140
- end
141
-
142
- it "has :f and :g as its only markers" do
143
- node.markers.should have_markers(:f, :g)
144
- end
145
- end
146
- end
147
- end