Class: CoderayHighlightScanner

Inherits:
HighlightScanner show all
Defined in:
ext/ae-editor/ae-editor.rb

Instance Method Summary collapse

Methods inherited from HighlightScanner

#classes

Constructor Details

#initialize(_langs_conf) ⇒ CoderayHighlightScanner

Returns a new instance of CoderayHighlightScanner.


4263
4264
4265
4266
# File 'ext/ae-editor/ae-editor.rb', line 4263

def initialize(_langs_conf)
  super(_langs_conf)
  require 'coderay'
end

Instance Method Details

#highlight_tags(_row_begin, _code) ⇒ Object


4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
# File 'ext/ae-editor/ae-editor.rb', line 4268

def highlight_tags(_row_begin,_code)
  super(_row_begin,_code)
  c_scanner = CodeRay::Scanners[@lang].new _code
  row=_row_begin
  col=0
  tags_map = Hash.new 
  c_scanner.tokens.each{|t|
    #p tok
    if @i.nil?
      @tok = []
      @tok << t
      @i = 1
      next
    else
      @tok << t
      @i = nil
    end 
    tok = @tok
    if tok[1]==:space && tok[0].include?("\n")
      row+=tok[0].count("\n")
      begin_gap = tok[0].split("\n")[-1]
      if begin_gap && tok[0][-1..-1]!="\n"
        col = begin_gap.length
      else
        col = 0
      end
    elsif !([:open, :close, :begin_group,:end_group].include?(tok[0])&& tok[1].class==Symbol)
      toklength = tok[0].length
      t_begin="#{row}.#{col}"
      #if tok[0].include?("\n")
      if tok[0].to_s.include?("\n")
        ar = tok[0].split("\n")
        row+=tok[0].count("\n")
        begin_gap = ar[-1]
        if begin_gap && tok[0][-1..-1]!="\n"
          col = begin_gap.length
        else
          col = 0
        end
      else
        col+=toklength
      end
      t_end="#{row}.#{col}"
      if tok[1]!=:space
        tags_map[tok[1]] = [] if tags_map[tok[1]].nil?
        tags_map[tok[1]] << [t_begin,t_end]
        #Arcadia.console(self, 'msg'=>"#{tok[1]}=#{[t_begin,t_end]}", 'level'=>'error')          
        #p [t_begin,t_end]
      end
    end  
  }
  tags_map
end