1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Drop RubyExpression.strip_comment

This commit is contained in:
Takashi Kokubun 2015-11-23 17:05:37 +09:00
parent 4388c09d50
commit 0dc4c4ebd6
3 changed files with 2 additions and 25 deletions

View file

@ -22,18 +22,6 @@ module Hamlit
type == :string_literal
end
def self.strip_comment(code)
code = code.strip
return code if syntax_error?(code)
tokens = Ripper.lex(code)
while tokens.last && %i[on_comment on_sp].include?(tokens.last[1])
_, _, str = tokens.pop
code.sub!(/#{str}\z/, '')
end
code
end
private
def on_parse_error(*)

View file

@ -1,13 +1,12 @@
require 'ripper'
require 'hamlit/ruby_expression'
module Hamlit::StringInterpolation
class << self
# `code` param must be valid string literal
def compile(code)
[].tap do |exps|
code = Hamlit::RubyExpression.strip_comment(code)
tokens = Ripper.lex(code)
tokens = Ripper.lex(code.strip)
tokens.pop while tokens.last && %i[on_comment on_sp].include?(tokens.last[1])
if tokens.size < 2
raise Hamlit::InternalError.new("Expected token size >= 2 but got: #{tokens.size}")

View file

@ -41,14 +41,4 @@ describe Hamlit::RubyExpression do
it { assert_literal(false, %Q|''\n''|) }
end
end
describe '.strip_comment' do
def assert_strip(expected, code)
actual = Hamlit::RubyExpression.strip_comment(code)
assert_equal expected, actual
end
it { assert_strip(%q|"hello"|, %q| "hello" # world|) }
it { assert_strip(%q|"hello"|, %q| "hello" |) }
end
end