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.



3886
3887
3888
3889
# File 'ext/ae-editor/ae-editor.rb', line 3886

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

Instance Method Details

#highlight_tags(_row_begin, _code) ⇒ Object



3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
# File 'ext/ae-editor/ae-editor.rb', line 3891

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