This file is indexed.

/usr/lib/ruby/vendor_ruby/rugments/lexers/haml.rb is in ruby-rugments 1.0.0~beta8-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
module Rugments
  module Lexers
    # A lexer for the Haml templating system for Ruby.
    # @see http://haml.info
    class Haml < RegexLexer
      include Indentation

      title 'Haml'
      desc 'The Haml templating system for Ruby (haml.info)'

      tag 'haml'
      aliases 'HAML'

      filenames '*.haml'
      mimetypes 'text/x-haml'

      def self.analyze_text(text)
        return 0.1 if text.start_with? '!!!'
      end

      # @option opts :filters
      #   A hash of filter name to lexer of how various filters should be
      #   highlighted.  By default, :javascript, :css, :ruby, and :erb
      #   are supported.
      def initialize(opts = {})
        (opts.delete(:filters) || {}).each do |name, lexer|
          unless lexer.respond_to? :lex
            lexer = Lexer.find(lexer) or fail "unknown lexer: #{lexer}"
            lexer = lexer.new(options)
          end

          filters[name.to_s] = lexer
        end

        super(opts)
      end

      def ruby
        @ruby ||= Ruby.new(options)
      end

      def html
        @html ||= HTML.new(options)
      end

      def filters
        @filters ||= {
          'javascript' => Javascript.new(options),
          'css' => CSS.new(options),
          'ruby' => ruby,
          'erb' => ERB.new(options),
          'markdown' => Markdown.new(options),
          # TODO
          # 'sass' => Sass.new(options),
          # 'textile' => Textile.new(options),
          # 'maruku' => Maruku.new(options),
        }
      end

      start { ruby.reset!; html.reset! }

      identifier = /[\w:-]+/
      ruby_var = /[a-z]\w*/

      # Haml can include " |\n" anywhere,
      # which is ignored and used to wrap long lines.
      # To accomodate this, use this custom faux dot instead.
      dot = /[ ]\|\n(?=.*[ ]\|)|./

      # In certain places, a comma at the end of the line
      # allows line wrapping as well.
      comma_dot = /,\s*\n|#{dot}/

      state :root do
        rule /\s*\n/, Text
        rule(/\s*/) { |m| token Text; indentation(m[0]) }
      end

      state :content do
        mixin :css
        rule(/%#{identifier}/) { token Name::Tag; goto :tag }
        rule /!!!#{dot}*\n/, Name::Namespace, :pop!
        rule %r{
          (/) (\[#{dot}*?\]) (#{dot}*\n)
                }x do
          groups Comment, Comment::Special, Comment
          pop!
        end

        rule %r{/#{dot}*\n} do
          token Comment
          pop!
          starts_block :html_comment_block
        end

        rule /-##{dot}*\n/ do
          token Comment
          pop!
          starts_block :haml_comment_block
        end

        rule /-/ do
          token Punctuation
          reset_stack
          push :ruby_line
        end

        # filters
        rule /:(#{dot}*)\n/ do |m|
          token Name::Decorator
          pop!
          starts_block :filter_block

          filter_name = m[1].strip

          @filter_lexer = filters[filter_name]
          @filter_lexer.reset! unless @filter_lexer.nil?

          puts "    haml: filter #{filter_name.inspect} #{@filter_lexer.inspect}" if @debug
        end

        mixin :eval_or_plain
      end

      state :css do
        rule(/\.#{identifier}/) { token Name::Class; goto :tag }
        rule(/##{identifier}/) { token Name::Function; goto :tag }
      end

      state :tag do
        mixin :css
        rule(/\{#{comma_dot}*?\}/) { delegate ruby }
        rule(/\[#{dot}*?\]/) { delegate ruby }
        rule /\(/, Punctuation, :html_attributes
        rule /\s*\n/, Text, :pop!

        # whitespace chompers
        rule /[<>]{1,2}(?=[ \t=])/, Punctuation

        mixin :eval_or_plain
      end

      state :plain do
        rule(/([^#\n]|#[^{\n]|(\\\\)*\\#\{)+/) { delegate html }
        mixin :interpolation
        rule(/\n/) { token Text; reset_stack }
      end

      state :eval_or_plain do
        rule /[&!]?==/, Punctuation, :plain
        rule /[&!]?[=!]/ do
          token Punctuation
          reset_stack
          push :ruby_line
        end

        rule(//) { push :plain }
      end

      state :ruby_line do
        rule /\n/, Text, :pop!
        rule(/,[ \t]*\n/) { delegate ruby }
        rule /[ ]\|[ \t]*\n/, Str::Escape
        rule(/.*?(?=(,$| \|)?[ \t]*$)/) { delegate ruby }
      end

      state :html_attributes do
        rule /\s+/, Text
        rule /#{identifier}\s*=/, Name::Attribute, :html_attribute_value
        rule identifier, Name::Attribute
        rule /\)/, Text, :pop!
      end

      state :html_attribute_value do
        rule /\s+/, Text
        rule ruby_var, Name::Variable, :pop!
        rule /@#{ruby_var}/, Name::Variable::Instance, :pop!
        rule /\$#{ruby_var}/, Name::Variable::Global, :pop!
        rule /'(\\\\|\\'|[^'\n])*'/, Str, :pop!
        rule /"(\\\\|\\"|[^"\n])*"/, Str, :pop!
      end

      state :html_comment_block do
        rule /#{dot}+/, Comment
        mixin :indented_block
      end

      state :haml_comment_block do
        rule /#{dot}+/, Comment::Preproc
        mixin :indented_block
      end

      state :filter_block do
        rule /([^#\n]|#[^{\n]|(\\\\)*\\#\{)+/ do
          if @filter_lexer
            delegate @filter_lexer
          else
            token Name::Decorator
          end
        end

        mixin :interpolation
        mixin :indented_block
      end

      state :interpolation do
        rule /#[{]/, Str::Interpol, :ruby
      end

      state :ruby do
        rule /[}]/, Str::Interpol, :pop!
        mixin :ruby_inner
      end

      state :ruby_inner do
        rule(/[{]/) { delegate ruby; push :ruby_inner }
        rule(/[}]/) { delegate ruby; pop! }
        rule(/[^{}]+/) { delegate ruby }
      end

      state :indented_block do
        rule(/\n/) { token Text; reset_stack }
      end
    end
  end
end