Sha256: 2c7ea1fe07ff805edcb6603f8cf7e04322a894ce96c858b05a801a1e98c2a337

Contents?: true

Size: 855 Bytes

Versions: 6

Compression:

Stored size: 855 Bytes

Contents

module Treetop
  module Compiler
    class PredicateBlock < ParsingExpression
      def compile(index, builder, parent_expression = nil)
        super
        # REVISIT: This is distinctly dodgey, but since we can only be called from
        # two contexts, and it works in both those, I'm going with it for now, as
        # opposed to doing the major refactor of providing a proper way of accessing
        # the parent's accumulator variable.
        p = parent
        p = p.parent while p && !p.respond_to?(:accumulator_var)
        assign_result "lambda #{text_value}.call(#{p ? p.accumulator_var : ""})"
        builder.if_ '!'+result_var do
          builder << "terminal_parse_failure(#{expected})"
        end
      end

      def expected
	'"<semantic predicate>"'  # Should I include (some of) the text_value here?
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
treetop-1.6.5 lib/treetop/compiler/node_classes/predicate_block.rb
treetop-1.6.4 lib/treetop/compiler/node_classes/predicate_block.rb
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/treetop-1.6.3/lib/treetop/compiler/node_classes/predicate_block.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/treetop-1.6.3/lib/treetop/compiler/node_classes/predicate_block.rb
treetop-1.6.3 lib/treetop/compiler/node_classes/predicate_block.rb
treetop-1.6.2 lib/treetop/compiler/node_classes/predicate_block.rb