Sha256: 71e5fafc0e55022f2b2dcb0d0017babe54e6e80da14ea78a125f23228be29aee

Contents?: true

Size: 582 Bytes

Versions: 18

Compression:

Stored size: 582 Bytes

Contents

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
hamlit-2.2.4 lib/hamlit/ruby_expression.rb
hamlit-2.6.1 lib/hamlit/ruby_expression.rb
hamlit-2.6.0 lib/hamlit/ruby_expression.rb
hamlit-2.5.0 lib/hamlit/ruby_expression.rb
hamlit-2.4.2 lib/hamlit/ruby_expression.rb
hamlit-2.4.1 lib/hamlit/ruby_expression.rb
hamlit-2.4.0 lib/hamlit/ruby_expression.rb
hamlit-2.3.1 lib/hamlit/ruby_expression.rb
hamlit-2.3.0 lib/hamlit/ruby_expression.rb
hamlit-2.2.3 lib/hamlit/ruby_expression.rb
hamlit-2.2.2 lib/hamlit/ruby_expression.rb
hamlit-2.2.1 lib/hamlit/ruby_expression.rb
hamlit-2.2.0 lib/hamlit/ruby_expression.rb
hamlit-2.1.2 lib/hamlit/ruby_expression.rb
hamlit-2.1.1 lib/hamlit/ruby_expression.rb
hamlit-2.1.0 lib/hamlit/ruby_expression.rb
hamlit-2.0.2 lib/hamlit/ruby_expression.rb
hamlit-2.0.1 lib/hamlit/ruby_expression.rb