1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/hamlit/ruby_expression.rb
2015-11-23 17:05:37 +09:00

31 lines
582 B
Ruby

require 'ripper'
module Hamlit
class RubyExpression < Ripper
class ParseError < StandardError; end
def self.syntax_error?(code)
self.new(code).parse
false
rescue ParseError
true
end
def self.string_literal?(code)
return false if syntax_error?(code)
type, instructions = Ripper.sexp(code)
return false if type != :program
return false if instructions.size > 1
type, _ = instructions.first
type == :string_literal
end
private
def on_parse_error(*)
raise ParseError
end
end
end