Sha256: 2741e59cc7cda7a95802fb93268218f4a05adedc078bc220285e4dce0018e0d0

Contents?: true

Size: 1.87 KB

Versions: 36

Compression:

Stored size: 1.87 KB

Contents

module OrigenTesters
  module Decompiler
    class Pattern
      class VectorDelimiterBase
        attr_reader :current_vector
        attr_reader :parent

        def initialize(parent)
          @current_vector = []
          @delimited = false
          @in_comment_block = false

          @parent = parent
        end

        def comment_start
          parent.comment_start
        end

        def in_comment_block?
          @in_comment_block
        end

        def shift(line)
          if @in_comment_block
            if !line.strip.start_with?(comment_start)
              # End of the comment block.
              # Signal that this vector is over, but don't include the
              # newly shifted line.
              @delimited = true
              @include_last_line = false
            else
              @current_vector << line
            end
          else
            if current_vector.empty? && line.strip.start_with?(comment_start)
              # Currently in an empty vector and encountered a comment.
              # Start a new comment block.
              @in_comment_block = true
              @current_vector << line
            elsif !current_vector.empty? && line.strip.start_with?(comment_start)
              # Not in an empty vector, but not in a comment block.
              # Signal the end of this vector and start a new one with
              # this vector.
              @delimited = true
              @include_last_line = false
            else
              # Standard single vector
              @delimited = true
              @include_last_line = true
              @current_vector << line
            end
          end
        end

        def current_vector!
          current_vector.join('')
        end

        def delimited?
          @delimited
        end

        def include_last_line?
          @include_last_line
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
origen_testers-0.48.3 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.48.2 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.48.1 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.48.0 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.47.0 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.46.1 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.46.0 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.45.4 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.45.3 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.45.2 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.45.1 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.45.0 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.44.1 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.44.0 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.43.0 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb
origen_testers-0.42.0 lib/origen_testers/decompiler/pattern/vector_delimiter_base.rb