Sha256: ef3f7552ed916658967871cc22e4fa80d5acd45a1a5f6e60deb6e1ef5b35f939

Contents?: true

Size: 1.05 KB

Versions: 27

Compression:

Stored size: 1.05 KB

Contents

# @Opulent
module Opulent
  # @Parser
  class Parser
    # Match one line or multiline comments
    #
    # @param parent [Node] Parent node of comment
    # @param indent [Fixnum] Number of indentation characters
    #
    def comment(parent, indent)
      return unless accept :comment

      # Get first comment line
      buffer = accept(:line_feed)
      buffer += accept(:newline) || ''

      # Get indented comment lines
      buffer += get_indented_lines indent

      # If we have a comment which is visible in the output, we will
      # create a new comment element. Otherwise, we ignore the current
      # gathered text and we simply begin the root parsing again
      if buffer[0] == '!'
        offset = 1
        options = {}

        # Allow leading comment newline
        if buffer[1] == '^'
          offset = 2
          options[:newline] = true
        end

        parent[@children] << [
          :comment,
          buffer[offset..-1].strip,
          options,
          nil,
          indent
        ]
      end

      parent
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
opulent-1.8.5 lib/opulent/parser/comment.rb
opulent-1.8.4 lib/opulent/parser/comment.rb
opulent-1.8.3 lib/opulent/parser/comment.rb
opulent-1.8.2 lib/opulent/parser/comment.rb
opulent-1.8.1 lib/opulent/parser/comment.rb
opulent-1.8.0 lib/opulent/parser/comment.rb
opulent-1.7.11 lib/opulent/parser/comment.rb
opulent-1.7.10 lib/opulent/parser/comment.rb
opulent-1.7.9 lib/opulent/parser/comment.rb
opulent-1.7.8 lib/opulent/parser/comment.rb
opulent-1.7.7 lib/opulent/parser/comment.rb
opulent-1.7.6 lib/opulent/parser/comment.rb
opulent-1.7.5 lib/opulent/parser/comment.rb
opulent-1.7.4 lib/opulent/parser/comment.rb
opulent-1.7.3 lib/opulent/parser/comment.rb
opulent-1.7.2 lib/opulent/parser/comment.rb
opulent-1.7.1 lib/opulent/parser/comment.rb
opulent-1.7.0 lib/opulent/parser/comment.rb
opulent-1.6.9 lib/opulent/parser/comment.rb
opulent-1.6.8 lib/opulent/parser/comment.rb