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.



3801
3802
3803
3804
# File 'ext/ae-editor/ae-editor.rb', line 3801

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

Instance Method Details

#highlight_tags(_row_begin, _code) ⇒ Object



3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
# File 'ext/ae-editor/ae-editor.rb', line 3806

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
    
    #p 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")
        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