Sha256: 09d0a9a9c34aad9acddd29928b785056ee0a466111b96355a0f61c2ce2658142

Contents?: true

Size: 709 Bytes

Versions: 11

Compression:

Stored size: 709 Bytes

Contents

# frozen_string_literal: true

module DeadEnd
  # Takes in a source, and returns blocks containing each heredoc
  class HeredocBlockParse
    private; attr_reader :code_lines, :lex; public

    def initialize(source:, code_lines: )
      @code_lines = code_lines
      @lex = LexAll.new(source: source)
    end

    def call
      blocks = []
      beginning = []
      @lex.each do |lex|
        case lex.type
        when :on_heredoc_beg
          beginning << lex.line
        when :on_heredoc_end
          start_index = beginning.pop - 1
          end_index = lex.line - 1
          blocks << CodeBlock.new(lines: code_lines[start_index..end_index])
        end
      end

      blocks
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dead_end-1.1.7 lib/dead_end/heredoc_block_parse.rb
dead_end-1.1.6 lib/dead_end/heredoc_block_parse.rb
dead_end-1.1.5 lib/dead_end/heredoc_block_parse.rb
dead_end-1.1.4 lib/dead_end/heredoc_block_parse.rb
dead_end-1.1.3 lib/dead_end/heredoc_block_parse.rb
dead_end-1.1.2 lib/dead_end/heredoc_block_parse.rb
dead_end-1.1.1 lib/dead_end/heredoc_block_parse.rb
dead_end-1.1.0 lib/dead_end/heredoc_block_parse.rb
dead_end-1.0.2 lib/dead_end/heredoc_block_parse.rb
dead_end-1.0.1 lib/dead_end/heredoc_block_parse.rb
dead_end-1.0.0 lib/dead_end/heredoc_block_parse.rb