treetop 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. data/README +3 -0
  2. data/Rakefile +35 -0
  3. data/bin/tt +25 -0
  4. data/lib/treetop.rb +10 -6
  5. data/lib/treetop/compiler.rb +7 -0
  6. data/lib/treetop/compiler/grammar_compiler.rb +21 -0
  7. data/lib/treetop/compiler/lexical_address_space.rb +17 -0
  8. data/lib/treetop/compiler/load_grammar.rb +7 -0
  9. data/lib/treetop/compiler/metagrammar.rb +2441 -0
  10. data/lib/treetop/compiler/metagrammar.treetop +384 -0
  11. data/lib/treetop/compiler/node_classes.rb +18 -0
  12. data/lib/treetop/compiler/node_classes/anything_symbol.rb +10 -0
  13. data/lib/treetop/compiler/node_classes/atomic_expression.rb +9 -0
  14. data/lib/treetop/compiler/node_classes/character_class.rb +10 -0
  15. data/lib/treetop/compiler/node_classes/choice.rb +31 -0
  16. data/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
  17. data/lib/treetop/compiler/node_classes/grammar.rb +28 -0
  18. data/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
  19. data/lib/treetop/compiler/node_classes/nonterminal.rb +11 -0
  20. data/lib/treetop/compiler/node_classes/optional.rb +19 -0
  21. data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
  22. data/lib/treetop/compiler/node_classes/parsing_expression.rb +132 -0
  23. data/lib/treetop/compiler/node_classes/parsing_rule.rb +55 -0
  24. data/lib/treetop/compiler/node_classes/predicate.rb +45 -0
  25. data/lib/treetop/compiler/node_classes/repetition.rb +56 -0
  26. data/lib/treetop/compiler/node_classes/sequence.rb +64 -0
  27. data/lib/treetop/compiler/node_classes/terminal.rb +10 -0
  28. data/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
  29. data/lib/treetop/compiler/ruby_builder.rb +109 -0
  30. data/lib/treetop/ruby_extensions.rb +2 -0
  31. data/lib/treetop/ruby_extensions/string.rb +19 -0
  32. data/lib/treetop/runtime.rb +9 -0
  33. data/lib/treetop/runtime/compiled_parser.rb +66 -0
  34. data/lib/treetop/runtime/node_cache.rb +27 -0
  35. data/lib/treetop/runtime/parse_cache.rb +19 -0
  36. data/lib/treetop/runtime/parse_failure.rb +32 -0
  37. data/lib/treetop/runtime/parse_result.rb +30 -0
  38. data/lib/treetop/runtime/syntax_node.rb +53 -0
  39. data/lib/treetop/runtime/terminal_parse_failure.rb +33 -0
  40. data/lib/treetop/runtime/terminal_syntax_node.rb +12 -0
  41. data/test/compilation_target/target.rb +143 -0
  42. data/test/compilation_target/target.treetop +15 -0
  43. data/test/compilation_target/target_test.rb +56 -0
  44. data/test/compiler/and_predicate_test.rb +33 -0
  45. data/test/compiler/anything_symbol_test.rb +24 -0
  46. data/test/compiler/character_class_test.rb +45 -0
  47. data/test/compiler/choice_test.rb +49 -0
  48. data/test/compiler/circular_compilation_test.rb +20 -0
  49. data/test/compiler/failure_propagation_functional_test.rb +20 -0
  50. data/test/compiler/grammar_compiler_test.rb +58 -0
  51. data/test/compiler/grammar_test.rb +33 -0
  52. data/test/compiler/nonterminal_symbol_test.rb +15 -0
  53. data/test/compiler/not_predicate_test.rb +35 -0
  54. data/test/compiler/one_or_more_test.rb +30 -0
  55. data/test/compiler/optional_test.rb +32 -0
  56. data/test/compiler/parsing_rule_test.rb +30 -0
  57. data/test/compiler/sequence_test.rb +68 -0
  58. data/test/compiler/terminal_symbol_test.rb +35 -0
  59. data/test/compiler/test_grammar.treetop +7 -0
  60. data/test/compiler/zero_or_more_test.rb +51 -0
  61. data/test/composition/a.treetop +11 -0
  62. data/test/composition/b.treetop +11 -0
  63. data/test/composition/c.treetop +10 -0
  64. data/test/composition/d.treetop +10 -0
  65. data/test/composition/grammar_composition_test.rb +23 -0
  66. data/test/parser/syntax_node_test.rb +53 -0
  67. data/test/parser/terminal_parse_failure_test.rb +22 -0
  68. data/test/ruby_extensions/string_test.rb +33 -0
  69. data/test/screw/Rakefile +16 -0
  70. data/test/screw/unit.rb +37 -0
  71. data/test/screw/unit/assertion_failed_error.rb +14 -0
  72. data/test/screw/unit/assertions.rb +615 -0
  73. data/test/screw/unit/auto_runner.rb +227 -0
  74. data/test/screw/unit/collector.rb +45 -0
  75. data/test/screw/unit/collector/dir.rb +107 -0
  76. data/test/screw/unit/collector/objectspace.rb +28 -0
  77. data/test/screw/unit/error.rb +48 -0
  78. data/test/screw/unit/failure.rb +45 -0
  79. data/test/screw/unit/sugar.rb +25 -0
  80. data/test/screw/unit/test_case.rb +176 -0
  81. data/test/screw/unit/test_result.rb +73 -0
  82. data/test/screw/unit/test_suite.rb +70 -0
  83. data/test/screw/unit/ui.rb +4 -0
  84. data/test/screw/unit/ui/console/test_runner.rb +118 -0
  85. data/test/screw/unit/ui/fox/test_runner.rb +268 -0
  86. data/test/screw/unit/ui/gtk/test_runner.rb +416 -0
  87. data/test/screw/unit/ui/gtk2/testrunner.rb +465 -0
  88. data/test/screw/unit/ui/test_runner_mediator.rb +58 -0
  89. data/test/screw/unit/ui/test_runner_utilities.rb +46 -0
  90. data/test/screw/unit/ui/tk/test_runner.rb +260 -0
  91. data/test/screw/unit/util.rb +4 -0
  92. data/test/screw/unit/util/backtrace_filter.rb +40 -0
  93. data/test/screw/unit/util/observable.rb +82 -0
  94. data/test/screw/unit/util/proc_wrapper.rb +48 -0
  95. data/test/test_helper.rb +89 -0
  96. metadata +127 -69
  97. data/lib/treetop/api.rb +0 -3
  98. data/lib/treetop/api/load_grammar.rb +0 -16
  99. data/lib/treetop/api/malformed_grammar_exception.rb +0 -9
  100. data/lib/treetop/grammar.rb +0 -7
  101. data/lib/treetop/grammar/grammar.rb +0 -48
  102. data/lib/treetop/grammar/grammar_builder.rb +0 -35
  103. data/lib/treetop/grammar/parsing_expression_builder.rb +0 -5
  104. data/lib/treetop/grammar/parsing_expression_builder_helper.rb +0 -121
  105. data/lib/treetop/grammar/parsing_expressions.rb +0 -18
  106. data/lib/treetop/grammar/parsing_expressions/and_predicate.rb +0 -17
  107. data/lib/treetop/grammar/parsing_expressions/anything_symbol.rb +0 -20
  108. data/lib/treetop/grammar/parsing_expressions/character_class.rb +0 -24
  109. data/lib/treetop/grammar/parsing_expressions/node_instantiating_parsing_expression.rb +0 -14
  110. data/lib/treetop/grammar/parsing_expressions/node_propagating_parsing_expression.rb +0 -4
  111. data/lib/treetop/grammar/parsing_expressions/nonterminal_symbol.rb +0 -42
  112. data/lib/treetop/grammar/parsing_expressions/not_predicate.rb +0 -18
  113. data/lib/treetop/grammar/parsing_expressions/one_or_more.rb +0 -12
  114. data/lib/treetop/grammar/parsing_expressions/optional.rb +0 -14
  115. data/lib/treetop/grammar/parsing_expressions/ordered_choice.rb +0 -27
  116. data/lib/treetop/grammar/parsing_expressions/parsing_expression.rb +0 -36
  117. data/lib/treetop/grammar/parsing_expressions/predicate.rb +0 -25
  118. data/lib/treetop/grammar/parsing_expressions/repeating_parsing_expression.rb +0 -29
  119. data/lib/treetop/grammar/parsing_expressions/sequence.rb +0 -41
  120. data/lib/treetop/grammar/parsing_expressions/terminal_parsing_expression.rb +0 -11
  121. data/lib/treetop/grammar/parsing_expressions/terminal_symbol.rb +0 -31
  122. data/lib/treetop/grammar/parsing_expressions/zero_or_more.rb +0 -11
  123. data/lib/treetop/grammar/parsing_rule.rb +0 -10
  124. data/lib/treetop/metagrammar.rb +0 -2
  125. data/lib/treetop/metagrammar/metagrammar.rb +0 -14
  126. data/lib/treetop/metagrammar/metagrammar.treetop +0 -320
  127. data/lib/treetop/parser.rb +0 -11
  128. data/lib/treetop/parser/node_cache.rb +0 -25
  129. data/lib/treetop/parser/parse_cache.rb +0 -17
  130. data/lib/treetop/parser/parse_failure.rb +0 -22
  131. data/lib/treetop/parser/parse_result.rb +0 -26
  132. data/lib/treetop/parser/parser.rb +0 -24
  133. data/lib/treetop/parser/sequence_syntax_node.rb +0 -14
  134. data/lib/treetop/parser/syntax_node.rb +0 -31
  135. data/lib/treetop/parser/terminal_parse_failure.rb +0 -18
  136. data/lib/treetop/parser/terminal_syntax_node.rb +0 -7
  137. data/lib/treetop/protometagrammar.rb +0 -16
  138. data/lib/treetop/protometagrammar/anything_symbol_expression_builder.rb +0 -13
  139. data/lib/treetop/protometagrammar/block_expression_builder.rb +0 -17
  140. data/lib/treetop/protometagrammar/character_class_expression_builder.rb +0 -25
  141. data/lib/treetop/protometagrammar/grammar_expression_builder.rb +0 -38
  142. data/lib/treetop/protometagrammar/nonterminal_symbol_expression_builder.rb +0 -45
  143. data/lib/treetop/protometagrammar/ordered_choice_expression_builder.rb +0 -21
  144. data/lib/treetop/protometagrammar/parsing_rule_expression_builder.rb +0 -23
  145. data/lib/treetop/protometagrammar/parsing_rule_sequence_expression_builder.rb +0 -14
  146. data/lib/treetop/protometagrammar/prefix_expression_builder.rb +0 -25
  147. data/lib/treetop/protometagrammar/primary_expression_builder.rb +0 -71
  148. data/lib/treetop/protometagrammar/protometagrammar.rb +0 -25
  149. data/lib/treetop/protometagrammar/sequence_expression_builder.rb +0 -37
  150. data/lib/treetop/protometagrammar/suffix_expression_builder.rb +0 -33
  151. data/lib/treetop/protometagrammar/terminal_symbol_expression_builder.rb +0 -52
  152. data/lib/treetop/protometagrammar/trailing_block_expression_builder.rb +0 -30
  153. data/lib/treetop/ruby_extension.rb +0 -11
@@ -0,0 +1,48 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
5
+ # License:: Ruby license.
6
+
7
+ module Screw
8
+ module Unit
9
+ module Util
10
+
11
+ # Allows the storage of a Proc passed through '&' in a
12
+ # hash.
13
+ #
14
+ # Note: this may be inefficient, since the hash being
15
+ # used is not necessarily very good. In Observable,
16
+ # efficiency is not too important, since the hash is
17
+ # only accessed when adding and removing listeners,
18
+ # not when notifying.
19
+
20
+ class ProcWrapper
21
+
22
+ # Creates a new wrapper for a_proc.
23
+ def initialize(a_proc)
24
+ @a_proc = a_proc
25
+ @hash = a_proc.inspect.sub(/^(#<#{a_proc.class}:)/){''}.sub(/(>)$/){''}.hex
26
+ end
27
+
28
+ def hash
29
+ return @hash
30
+ end
31
+
32
+ def ==(other)
33
+ case(other)
34
+ when ProcWrapper
35
+ return @a_proc == other.to_proc
36
+ else
37
+ return super
38
+ end
39
+ end
40
+ alias :eql? :==
41
+
42
+ def to_proc
43
+ return @a_proc
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,89 @@
1
+ dir = File.dirname(__FILE__)
2
+ $:.unshift(File.join(dir, *%w[.. lib]))
3
+ require File.expand_path(File.join(dir, 'screw', 'unit'))
4
+ require 'treetop'
5
+
6
+ include Treetop
7
+
8
+ unless Object.const_defined?(:METAGRAMMAR_PATH)
9
+ METAGRAMMAR_PATH = File.join(TREETOP_ROOT, 'compiler', 'metagrammar.treetop')
10
+ fresh_metagrammar_source = Compiler::GrammarCompiler.new.ruby_source(METAGRAMMAR_PATH)
11
+ Compiler.send(:remove_const, :Metagrammar)
12
+ Object.class_eval(fresh_metagrammar_source)
13
+ end
14
+
15
+ class CompilerTestCase < Screw::Unit::TestCase
16
+ class << self
17
+ attr_accessor :parser_class_under_test
18
+
19
+ def testing_expression(expression_to_test)
20
+ rule_node = parse_with_metagrammar_2("rule test_expression\n" + expression_to_test + "\nend", :parsing_rule)
21
+ test_parser_code = generate_test_parser_for_expression(rule_node)
22
+ #puts test_parser_code
23
+ class_eval(test_parser_code)
24
+ self.parser_class_under_test = const_get(:TestParser)
25
+ end
26
+
27
+ def testing_grammar(grammar_to_test)
28
+ grammar_node = parse_with_metagrammar_2(grammar_to_test.strip, :grammar)
29
+ test_parser_code = grammar_node.compile
30
+ # puts test_parser_code
31
+ class_eval(test_parser_code)
32
+ self.parser_class_under_test = const_get(grammar_node.parser_name.to_sym)
33
+ end
34
+
35
+ def generate_test_parser_for_expression(expression_node)
36
+ builder = Compiler::RubyBuilder.new
37
+ address = builder.next_address
38
+ expression_node.compile(builder)
39
+ %{
40
+ class TestParser < Treetop::Runtime::CompiledParser
41
+ include Treetop::Runtime
42
+
43
+ attr_accessor :test_index
44
+
45
+ def root
46
+ _nt_test_expression
47
+ end
48
+
49
+ def reset_index
50
+ @index = @test_index || 0
51
+ end
52
+
53
+ #{builder.ruby.tabrestto(10)}
54
+ end
55
+ }.tabto(0)
56
+ end
57
+
58
+ def parse_with_metagrammar_2(input, root)
59
+ parser = Treetop::Compiler::MetagrammarParser.new
60
+ parser.send(:prepare_to_parse, input)
61
+ node = parser.send("_nt_#{root}".to_sym)
62
+ raise "#{input} cannot be parsed by the metagrammar: #{node.nested_failures.map {|f| f.to_s}.join("\n")}" if node.failure?
63
+ node
64
+ end
65
+
66
+ end
67
+
68
+ def parse_with_metagrammar_2(input, root)
69
+ self.class.parse_with_metagrammar_2(input, root)
70
+ end
71
+
72
+ def parser_class_under_test
73
+ self.class.parser_class_under_test
74
+ end
75
+
76
+ def parse(input, options = {})
77
+ test_parser = parser_class_under_test.new
78
+ test_parser.test_index = options[:at_index] if options[:at_index]
79
+ result = test_parser.parse(input)
80
+ yield result if block_given?
81
+ result
82
+ end
83
+ end
84
+
85
+ class String
86
+ def tabrestto(n)
87
+ self.gsub(/\n^/, "\n" + ' ' * n)
88
+ end
89
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: treetop
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-05-22 00:00:00 -07:00
6
+ version: 1.0.0
7
+ date: 2007-09-14 00:00:00 -07:00
8
8
  summary: A Ruby-based text parsing and interpretation DSL
9
9
  require_paths:
10
10
  - lib
@@ -29,82 +29,140 @@ post_install_message:
29
29
  authors:
30
30
  - Nathan Sobo
31
31
  files:
32
+ - README
33
+ - Rakefile
34
+ - test/compilation_target
35
+ - test/compilation_target/target.rb
36
+ - test/compilation_target/target.treetop
37
+ - test/compilation_target/target_test.rb
38
+ - test/compiler
39
+ - test/compiler/and_predicate_test.rb
40
+ - test/compiler/anything_symbol_test.rb
41
+ - test/compiler/character_class_test.rb
42
+ - test/compiler/choice_test.rb
43
+ - test/compiler/circular_compilation_test.rb
44
+ - test/compiler/failure_propagation_functional_test.rb
45
+ - test/compiler/grammar_compiler_test.rb
46
+ - test/compiler/grammar_test.rb
47
+ - test/compiler/nonterminal_symbol_test.rb
48
+ - test/compiler/not_predicate_test.rb
49
+ - test/compiler/one_or_more_test.rb
50
+ - test/compiler/optional_test.rb
51
+ - test/compiler/parsing_rule_test.rb
52
+ - test/compiler/sequence_test.rb
53
+ - test/compiler/terminal_symbol_test.rb
54
+ - test/compiler/test_grammar.treetop
55
+ - test/compiler/zero_or_more_test.rb
56
+ - test/composition
57
+ - test/composition/a.treetop
58
+ - test/composition/b.treetop
59
+ - test/composition/c.treetop
60
+ - test/composition/d.treetop
61
+ - test/composition/grammar_composition_test.rb
62
+ - test/parser
63
+ - test/parser/syntax_node_test.rb
64
+ - test/parser/terminal_parse_failure_test.rb
65
+ - test/ruby_extensions
66
+ - test/ruby_extensions/string_test.rb
67
+ - test/screw
68
+ - test/screw/Rakefile
69
+ - test/screw/unit
70
+ - test/screw/unit/assertion_failed_error.rb
71
+ - test/screw/unit/assertions.rb
72
+ - test/screw/unit/auto_runner.rb
73
+ - test/screw/unit/collector
74
+ - test/screw/unit/collector/dir.rb
75
+ - test/screw/unit/collector/objectspace.rb
76
+ - test/screw/unit/collector.rb
77
+ - test/screw/unit/error.rb
78
+ - test/screw/unit/failure.rb
79
+ - test/screw/unit/sugar.rb
80
+ - test/screw/unit/test_case.rb
81
+ - test/screw/unit/test_result.rb
82
+ - test/screw/unit/test_suite.rb
83
+ - test/screw/unit/ui
84
+ - test/screw/unit/ui/console
85
+ - test/screw/unit/ui/console/test_runner.rb
86
+ - test/screw/unit/ui/fox
87
+ - test/screw/unit/ui/fox/test_runner.rb
88
+ - test/screw/unit/ui/gtk
89
+ - test/screw/unit/ui/gtk/test_runner.rb
90
+ - test/screw/unit/ui/gtk2
91
+ - test/screw/unit/ui/gtk2/testrunner.rb
92
+ - test/screw/unit/ui/test_runner_mediator.rb
93
+ - test/screw/unit/ui/test_runner_utilities.rb
94
+ - test/screw/unit/ui/tk
95
+ - test/screw/unit/ui/tk/test_runner.rb
96
+ - test/screw/unit/ui.rb
97
+ - test/screw/unit/util
98
+ - test/screw/unit/util/backtrace_filter.rb
99
+ - test/screw/unit/util/observable.rb
100
+ - test/screw/unit/util/proc_wrapper.rb
101
+ - test/screw/unit/util.rb
102
+ - test/screw/unit.rb
103
+ - test/test_helper.rb
32
104
  - lib/treetop
33
- - lib/treetop/api
34
- - lib/treetop/api/load_grammar.rb
35
- - lib/treetop/api/malformed_grammar_exception.rb
36
- - lib/treetop/api.rb
37
- - lib/treetop/grammar
38
- - lib/treetop/grammar/grammar.rb
39
- - lib/treetop/grammar/grammar_builder.rb
40
- - lib/treetop/grammar/parsing_expression_builder.rb
41
- - lib/treetop/grammar/parsing_expression_builder_helper.rb
42
- - lib/treetop/grammar/parsing_expressions
43
- - lib/treetop/grammar/parsing_expressions/and_predicate.rb
44
- - lib/treetop/grammar/parsing_expressions/anything_symbol.rb
45
- - lib/treetop/grammar/parsing_expressions/character_class.rb
46
- - lib/treetop/grammar/parsing_expressions/node_instantiating_parsing_expression.rb
47
- - lib/treetop/grammar/parsing_expressions/node_propagating_parsing_expression.rb
48
- - lib/treetop/grammar/parsing_expressions/nonterminal_symbol.rb
49
- - lib/treetop/grammar/parsing_expressions/not_predicate.rb
50
- - lib/treetop/grammar/parsing_expressions/one_or_more.rb
51
- - lib/treetop/grammar/parsing_expressions/optional.rb
52
- - lib/treetop/grammar/parsing_expressions/ordered_choice.rb
53
- - lib/treetop/grammar/parsing_expressions/parsing_expression.rb
54
- - lib/treetop/grammar/parsing_expressions/predicate.rb
55
- - lib/treetop/grammar/parsing_expressions/repeating_parsing_expression.rb
56
- - lib/treetop/grammar/parsing_expressions/sequence.rb
57
- - lib/treetop/grammar/parsing_expressions/terminal_parsing_expression.rb
58
- - lib/treetop/grammar/parsing_expressions/terminal_symbol.rb
59
- - lib/treetop/grammar/parsing_expressions/zero_or_more.rb
60
- - lib/treetop/grammar/parsing_expressions.rb
61
- - lib/treetop/grammar/parsing_rule.rb
62
- - lib/treetop/grammar.rb
63
- - lib/treetop/metagrammar
64
- - lib/treetop/metagrammar/metagrammar.rb
65
- - lib/treetop/metagrammar/metagrammar.treetop
66
- - lib/treetop/metagrammar.rb
67
- - lib/treetop/parser
68
- - lib/treetop/parser/node_cache.rb
69
- - lib/treetop/parser/parse_cache.rb
70
- - lib/treetop/parser/parse_failure.rb
71
- - lib/treetop/parser/parse_result.rb
72
- - lib/treetop/parser/parser.rb
73
- - lib/treetop/parser/sequence_syntax_node.rb
74
- - lib/treetop/parser/syntax_node.rb
75
- - lib/treetop/parser/terminal_parse_failure.rb
76
- - lib/treetop/parser/terminal_syntax_node.rb
77
- - lib/treetop/parser.rb
78
- - lib/treetop/protometagrammar
79
- - lib/treetop/protometagrammar/anything_symbol_expression_builder.rb
80
- - lib/treetop/protometagrammar/block_expression_builder.rb
81
- - lib/treetop/protometagrammar/character_class_expression_builder.rb
82
- - lib/treetop/protometagrammar/grammar_expression_builder.rb
83
- - lib/treetop/protometagrammar/nonterminal_symbol_expression_builder.rb
84
- - lib/treetop/protometagrammar/ordered_choice_expression_builder.rb
85
- - lib/treetop/protometagrammar/parsing_rule_expression_builder.rb
86
- - lib/treetop/protometagrammar/parsing_rule_sequence_expression_builder.rb
87
- - lib/treetop/protometagrammar/prefix_expression_builder.rb
88
- - lib/treetop/protometagrammar/primary_expression_builder.rb
89
- - lib/treetop/protometagrammar/protometagrammar.rb
90
- - lib/treetop/protometagrammar/sequence_expression_builder.rb
91
- - lib/treetop/protometagrammar/suffix_expression_builder.rb
92
- - lib/treetop/protometagrammar/terminal_symbol_expression_builder.rb
93
- - lib/treetop/protometagrammar/trailing_block_expression_builder.rb
94
- - lib/treetop/protometagrammar.rb
95
- - lib/treetop/ruby_extension.rb
105
+ - lib/treetop/compiler
106
+ - lib/treetop/compiler/grammar_compiler.rb
107
+ - lib/treetop/compiler/lexical_address_space.rb
108
+ - lib/treetop/compiler/load_grammar.rb
109
+ - lib/treetop/compiler/metagrammar.rb
110
+ - lib/treetop/compiler/metagrammar.treetop
111
+ - lib/treetop/compiler/node_classes
112
+ - lib/treetop/compiler/node_classes/anything_symbol.rb
113
+ - lib/treetop/compiler/node_classes/atomic_expression.rb
114
+ - lib/treetop/compiler/node_classes/character_class.rb
115
+ - lib/treetop/compiler/node_classes/choice.rb
116
+ - lib/treetop/compiler/node_classes/declaration_sequence.rb
117
+ - lib/treetop/compiler/node_classes/grammar.rb
118
+ - lib/treetop/compiler/node_classes/inline_module.rb
119
+ - lib/treetop/compiler/node_classes/nonterminal.rb
120
+ - lib/treetop/compiler/node_classes/optional.rb
121
+ - lib/treetop/compiler/node_classes/parenthesized_expression.rb
122
+ - lib/treetop/compiler/node_classes/parsing_expression.rb
123
+ - lib/treetop/compiler/node_classes/parsing_rule.rb
124
+ - lib/treetop/compiler/node_classes/predicate.rb
125
+ - lib/treetop/compiler/node_classes/repetition.rb
126
+ - lib/treetop/compiler/node_classes/sequence.rb
127
+ - lib/treetop/compiler/node_classes/terminal.rb
128
+ - lib/treetop/compiler/node_classes/treetop_file.rb
129
+ - lib/treetop/compiler/node_classes.rb
130
+ - lib/treetop/compiler/ruby_builder.rb
131
+ - lib/treetop/compiler.rb
132
+ - lib/treetop/ruby_extensions
133
+ - lib/treetop/ruby_extensions/string.rb
134
+ - lib/treetop/ruby_extensions.rb
135
+ - lib/treetop/runtime
136
+ - lib/treetop/runtime/compiled_parser.rb
137
+ - lib/treetop/runtime/node_cache.rb
138
+ - lib/treetop/runtime/parse_cache.rb
139
+ - lib/treetop/runtime/parse_failure.rb
140
+ - lib/treetop/runtime/parse_result.rb
141
+ - lib/treetop/runtime/syntax_node.rb
142
+ - lib/treetop/runtime/terminal_parse_failure.rb
143
+ - lib/treetop/runtime/terminal_syntax_node.rb
144
+ - lib/treetop/runtime.rb
96
145
  - lib/treetop.rb
146
+ - bin/tt
97
147
  test_files: []
98
148
 
99
149
  rdoc_options: []
100
150
 
101
151
  extra_rdoc_files: []
102
152
 
103
- executables: []
104
-
153
+ executables:
154
+ - tt
105
155
  extensions: []
106
156
 
107
157
  requirements: []
108
158
 
109
- dependencies: []
110
-
159
+ dependencies:
160
+ - !ruby/object:Gem::Dependency
161
+ name: facets
162
+ version_requirement:
163
+ version_requirements: !ruby/object:Gem::Version::Requirement
164
+ requirements:
165
+ - - ">"
166
+ - !ruby/object:Gem::Version
167
+ version: 0.0.0
168
+ version:
data/lib/treetop/api.rb DELETED
@@ -1,3 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/api/load_grammar"
3
- require "#{dir}/api/malformed_grammar_exception"
@@ -1,16 +0,0 @@
1
- class Object
2
- def load_grammar(treetop_file_path)
3
- treetop_file_path += ".treetop" unless treetop_file_path =~ /\.treetop$/
4
-
5
- File.open("#{treetop_file_path}", 'r') do |grammar_file|
6
- result = Metagrammar.new_parser.parse(grammar_file.read)
7
-
8
- if result.success?
9
- grammar = result.value
10
- Object.instance_eval { const_set(grammar.name, grammar) }
11
- else
12
- raise MalformedGrammarException.new(result.nested_failures)
13
- end
14
- end
15
- end
16
- end
@@ -1,9 +0,0 @@
1
- class MalformedGrammarException < Exception
2
- attr_reader :errors
3
-
4
- def initialize(errors)
5
- @errors = errors
6
- expected_expressions = errors.collect(&:expression)
7
- super("String matching #{expected_expressions.join(' or ')} expected at position #{errors.first.index}.")
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/grammar/grammar"
3
- require "#{dir}/grammar/parsing_expression_builder_helper"
4
- require "#{dir}/grammar/grammar_builder"
5
- require "#{dir}/grammar/parsing_expression_builder"
6
- require "#{dir}/grammar/parsing_expressions"
7
- require "#{dir}/grammar/parsing_rule"
@@ -1,48 +0,0 @@
1
- module Treetop
2
- class Grammar
3
- attr_accessor :root, :builder, :name
4
-
5
- def initialize(name = nil, &block)
6
- @name = name
7
- @parsing_rules = Hash.new
8
- @nonterminal_symbols = Hash.new
9
- self.builder = GrammarBuilder.new(self)
10
- build &block if block
11
- end
12
-
13
- def new_parser
14
- Parser.new(self)
15
- end
16
-
17
- def nonterminal_symbol(ruby_sym)
18
- @nonterminal_symbols[ruby_sym] ||= NonterminalSymbol.new(ruby_sym, self)
19
- end
20
-
21
- def add_parsing_rule(parsing_rule_or_nonterminal, expression = nil)
22
- rule = make_parsing_rule(parsing_rule_or_nonterminal, expression)
23
- @parsing_rules[rule.nonterminal_symbol.name] = rule
24
- self.root ||= rule.nonterminal_symbol
25
- end
26
-
27
- def get_parsing_expression(nonterminal_symbol)
28
- if @parsing_rules[nonterminal_symbol.name]
29
- @parsing_rules[nonterminal_symbol.name].parsing_expression
30
- else
31
- raise "No parsing rule found named #{nonterminal_symbol}."
32
- end
33
- end
34
-
35
- def build(&block)
36
- builder.build &block
37
- end
38
-
39
- private
40
- def make_parsing_rule(rule_or_nonterminal, expression)
41
- if rule_or_nonterminal.is_a? NonterminalSymbol
42
- return ParsingRule.new(rule_or_nonterminal, expression)
43
- else
44
- return rule_or_nonterminal
45
- end
46
- end
47
- end
48
- end