~singpolyma/dhall-ruby

eef5a51ad67c324885f88b93f89f3acc0fcaae6c — Stephen Paul Weber 3 years ago 60d1417
Fix lint
2 files changed, 12 insertions(+), 4 deletions(-)

M lib/dhall/parser.rb
M lib/dhall/util.rb
M lib/dhall/parser.rb => lib/dhall/parser.rb +1 -4
@@ 275,10 275,7 @@ module Dhall
		module SingleQuoteLiteral
			def value
				chunks = capture(:single_quote_continue).value
				raw = chunks.join
				indent = raw.scan(/^[ \t]*(?=[^ \t\n]|\Z)/).map(&:chars)
				            .reduce(&Util.method(:longest_common_prefix))&.length.to_i
				indent = 0 if raw.end_with?("\n")
				indent = Util.indent_size(chunks.join)

				TextLiteral.for(
					*chunks

M lib/dhall/util.rb => lib/dhall/util.rb +11 -0
@@ 181,5 181,16 @@ module Dhall
		def self.longest_common_prefix(a, b)
			a.zip(b).take_while { |(x, y)| x == y }.map(&:first)
		end

		def self.indent_size(str)
			if str.end_with?("\n")
				0
			else
				str
					.scan(/^[ \t]*(?=[^ \t\n]|\Z)/)
					.map(&:chars)
					.reduce(&method(:longest_common_prefix))&.length.to_i
			end
		end
	end
end