Sha256: 148b3e41159abbba27ebf6128e4616f64db78563b4fc8afc1909ba2cd994271b

Contents?: true

Size: 1.46 KB

Versions: 93

Compression:

Stored size: 1.46 KB

Contents

module Treetop
  module Compiler
    class Repetition < ParsingExpression
      def compile(address, builder, parent_expression)
        super
        repeated_expression = parent_expression.atomic
        begin_comment(parent_expression)
        use_vars :result, :accumulator, :start_index

        builder.loop do
          obtain_new_subexpression_address
          repeated_expression.compile(subexpression_address, builder)
          builder.if__ subexpression_success? do
            accumulate_subexpression_result
          end
          builder.else_ do
            builder.break
          end
        end
      end
      
      def inline_module_name
        parent_expression.inline_module_name
      end
      
      def assign_and_extend_result
        assign_result "instantiate_node(#{node_class_name},input, #{start_index_var}...index, #{accumulator_var})"
        extend_result_with_inline_module
      end
    end

  
    class ZeroOrMore < Repetition
      def compile(address, builder, parent_expression)
        super
        assign_and_extend_result
        end_comment(parent_expression)
      end
    end
  
    class OneOrMore < Repetition
      def compile(address, builder, parent_expression)
        super
        builder.if__ "#{accumulator_var}.empty?" do
          reset_index
          assign_failure start_index_var
        end
        builder.else_ do
          assign_and_extend_result
        end
        end_comment(parent_expression)
      end
    end
  end
end

Version data entries

93 entries across 93 versions & 11 rubygems

Version Path
treetop-1.4.4 lib/treetop/compiler/node_classes/repetition.rb
mail-2.1.2 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-2.1.1 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-2.1.0 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-2.0.5 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-2.0.3 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.6.0 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.5.4 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.5.3 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.5.2 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.5.1 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.5.0 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.4.3 lib/mail/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.4.2 lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.4.1 lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.4.0 lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
mail-1.3.5 lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
skylinecms-3.0.8 vendor/digitpaint/personify/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb
mail-1.3.4 lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb
skylinecms-3.0.7 vendor/digitpaint/personify/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb