Class: Treetop::TreetopExampleGroup
- Inherits:
-
Spec::Example::ExampleGroup
- Object
- Spec::Example::ExampleGroup
- Treetop::TreetopExampleGroup
- Defined in:
- lib/vendor/treetop/spec/spec_helper.rb
Class Attribute Summary collapse
-
.parser_class_under_test ⇒ Object
Returns the value of attribute parser_class_under_test.
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Class Method Summary collapse
- .parse_with_metagrammar(input, root) ⇒ Object
- .testing_expression(expression_under_test) ⇒ Object
- .testing_grammar(grammar_under_test) ⇒ Object
Instance Method Summary collapse
- #compiling_expression(expression_under_test) ⇒ Object
- #compiling_grammar(grammar_under_test) ⇒ Object
- #optionally_benchmark(&block) ⇒ Object
- #parse(input, options = {}) {|result| ... } ⇒ Object
- #parse_with_metagrammar(input, root) ⇒ Object
- #parser_class_under_test ⇒ Object
Class Attribute Details
.parser_class_under_test ⇒ Object
Returns the value of attribute parser_class_under_test.
18 19 20 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 18 def parser_class_under_test @parser_class_under_test end |
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
47 48 49 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 47 def parser @parser end |
Class Method Details
.parse_with_metagrammar(input, root) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 37 def (input, root) parser = Treetop::Compiler::MetagrammarParser.new parser.root = root node = parser.parse(input) raise parser.failure_reason unless node node end |
.testing_expression(expression_under_test) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 20 def testing_expression(expression_under_test) testing_grammar(%{ grammar Test rule expression_under_test }+expression_under_test+%{ end end }.tabto(0)) end |
.testing_grammar(grammar_under_test) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 30 def testing_grammar(grammar_under_test) grammar_node = (grammar_under_test.strip, :grammar) parser_code = grammar_node.compile class_eval(parser_code) self.parser_class_under_test = const_get(grammar_node.parser_name.to_sym) end |
Instance Method Details
#compiling_expression(expression_under_test) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 75 def compiling_expression(expression_under_test) compiling_grammar(%{ grammar Test rule expression_under_test #{expression_under_test} end end }.tabto(0)) end |
#compiling_grammar(grammar_under_test) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 67 def compiling_grammar(grammar_under_test) lambda { grammar_node = (grammar_under_test.strip, :grammar) parser_code = grammar_node.compile [grammar_node, parser_code] } end |
#optionally_benchmark(&block) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 85 def optionally_benchmark(&block) if BENCHMARK Benchmark.bm do |x| x.report(&block) end else yield end end |
#parse(input, options = {}) {|result| ... } ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 57 def parse(input, = {}) @parser = parser_class_under_test.new unless [:consume_all_input].nil? parser.consume_all_input = .delete(:consume_all_input) end result = parser.parse(input, ) yield result if block_given? result end |
#parse_with_metagrammar(input, root) ⇒ Object
49 50 51 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 49 def (input, root) self.class.(input, root) end |
#parser_class_under_test ⇒ Object
53 54 55 |
# File 'lib/vendor/treetop/spec/spec_helper.rb', line 53 def parser_class_under_test self.class.parser_class_under_test end |