1 dir = File.dirname(__FILE__)
6 unless $bootstrapped_gen_1_metagrammar
7 load File.join(dir, '..', 'lib', 'treetop', 'bootstrap_gen_1_metagrammar.rb')
11 Spec::Runner.configure do |config|
16 class TreetopExampleGroup < Spec::Example::ExampleGroup
18 attr_accessor :parser_class_under_test
20 def testing_expression(expression_under_test)
23 rule expression_under_test
24 }+expression_under_test+%{
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)
37 def parse_with_metagrammar(input, root)
38 parser = Treetop::Compiler::MetagrammarParser.new
40 node = parser.parse(input)
41 raise parser.failure_reason unless node
49 def parse_with_metagrammar(input, root)
50 self.class.parse_with_metagrammar(input, root)
53 def parser_class_under_test
54 self.class.parser_class_under_test
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)
62 result = parser.parse(input, options)
63 yield result if block_given?
67 def compiling_grammar(grammar_under_test)
69 grammar_node = parse_with_metagrammar(grammar_under_test.strip, :grammar)
70 parser_code = grammar_node.compile
71 [grammar_node, parser_code]
75 def compiling_expression(expression_under_test)
78 rule expression_under_test
79 #{expression_under_test}
85 def optionally_benchmark(&block)
95 Spec::Example::ExampleGroupFactory.register(:compiler, self)
96 Spec::Example::ExampleGroupFactory.register(:runtime, self)