Sha256: a1d4307754ee8dd0bf49d77d409fded0c4ffc662e32a0a52237fd2b40eff8482

Contents?: true

Size: 696 Bytes

Versions: 9

Compression:

Stored size: 696 Bytes

Contents

module Faml
  module RubyMultiline
    def self.read(line_parser, current_text)
      buf = []
      while is_ruby_multiline?(current_text)
        current_text = line_parser.next_line
        buf << current_text
      end
      buf.join(' ')
    end

    # `text' is a Ruby multiline block if it:
    # - ends with a comma
    # - but not "?," which is a character literal
    #   (however, "x?," is a method call and not a literal)
    # - and not "?\," which is a character literal
    def self.is_ruby_multiline?(text)
      text && text.length > 1 && text[-1] == ?, &&
        !((text[-3, 2] =~ /\W\?/) || text[-3, 2] == "?\\")
    end
    private_class_method :is_ruby_multiline?
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
faml-0.2.8 lib/faml/ruby_multiline.rb
faml-0.2.7 lib/faml/ruby_multiline.rb
faml-0.2.6 lib/faml/ruby_multiline.rb
faml-0.2.5 lib/faml/ruby_multiline.rb
faml-0.2.4 lib/faml/ruby_multiline.rb
faml-0.2.3 lib/faml/ruby_multiline.rb
faml-0.2.2 lib/faml/ruby_multiline.rb
faml-0.2.1 lib/faml/ruby_multiline.rb
faml-0.2.0 lib/faml/ruby_multiline.rb