Sha256: a5059e1a7f2f33f7a4975316d31918090e9b02d9601a87da2672dda31f98053f

Contents?: true

Size: 860 Bytes

Versions: 33

Compression:

Stored size: 860 Bytes

Contents

# frozen_string_literal: true

module Opal::MagicComments
  MAGIC_COMMENT_RE = /\A# *(\w+) *: *(\S+.*?) *$/.freeze
  EMACS_MAGIC_COMMENT_RE = /\A# *-\*- *(\w+) *: *(\S+.*?) *-\*- *$/.freeze

  def self.parse(sexp, comments)
    flags = {}

    # We have an upper limit at the first line of code
    if sexp
      first_line = sexp.loc.line
      comments = comments.take(first_line)
    end

    comments.each do |comment|
      next if first_line && comment.loc.line >= first_line

      if (parts = comment.text.scan(MAGIC_COMMENT_RE)).any? ||
         (parts = comment.text.scan(EMACS_MAGIC_COMMENT_RE)).any?
        parts.each do |key, value|
          flags[key.to_sym] =
            case value
            when 'true' then true
            when 'false' then false
            else value
            end
        end
      end
    end

    flags
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/opal/magic_comments.rb
opal-1.8.2 lib/opal/magic_comments.rb
opal-1.8.1 lib/opal/magic_comments.rb
opal-1.8.0 lib/opal/magic_comments.rb
opal-1.8.0.beta1 lib/opal/magic_comments.rb
opal-1.7.4 lib/opal/magic_comments.rb
opal-1.8.0.alpha1 lib/opal/magic_comments.rb
opal-1.7.3 lib/opal/magic_comments.rb
opal-1.7.2 lib/opal/magic_comments.rb
opal-1.7.1 lib/opal/magic_comments.rb
opal-1.7.0 lib/opal/magic_comments.rb
opal-1.7.0.rc1 lib/opal/magic_comments.rb
opal-1.6.1 lib/opal/magic_comments.rb
opal-1.6.0 lib/opal/magic_comments.rb
opal-1.6.0.rc1 lib/opal/magic_comments.rb
opal-1.6.0.alpha1 lib/opal/magic_comments.rb
opal-1.5.1 lib/opal/magic_comments.rb
opal-1.5.0 lib/opal/magic_comments.rb
opal-1.5.0.rc1 lib/opal/magic_comments.rb
opal-1.4.1 lib/opal/magic_comments.rb