Class: ReHighlightScanner

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) ⇒ ReHighlightScanner

Returns a new instance of ReHighlightScanner.



3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
# File 'ext/ae-editor/ae-editor.rb', line 3841

def initialize(_langs_conf)
  super(_langs_conf)
  @h_re = Hash.new
  @op_to_end_line = Array.new
  @op_to_end_line.concat(@langs_conf['re_op.to_line_end'].split(',')) if @langs_conf['re_op.to_line_end']

  @op_only_first = Array.new
  @op_only_first.concat(@langs_conf['re_op.only_first'].split(',')) if @langs_conf['re_op.only_first']
  
  self.classes.each{|c|
    @h_re[c]=Regexp::new(@langs_conf["re.#{c}"].strip) if @langs_conf["re.#{c}"]
  }
end

Instance Method Details

#find_tag(_tag, _row, _line_txt) ⇒ Object



3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
# File 'ext/ae-editor/ae-editor.rb', line 3856

def find_tag(_tag, _row, _line_txt)
  _txt = _line_txt
  to_ret = []
  _re = @h_re[_tag]
  m = _re.match(_txt)
  _end = 0
#    index = _line_txt.index("oldaccel1")
#    stampa = index && index >0
#    stampa=true
#    p "_line_txt=#{_line_txt}" if stampa
#    p "_tag=#{_tag}" if stampa
  while m && (_txt=m.post_match)
    if !defined?(_old_txt) || _txt != _old_txt
      b1 = _line_txt[m.begin(0)+_end-1..m.begin(0)+_end-1]
      b2 = _line_txt[m.begin(0)+_end..m.begin(0)+_end]
      e1 = _line_txt[m.end(0)+_end..m.end(0)+_end]        
      e2 = _line_txt[m.end(0)-1+_end..m.end(0)+_end-1]
      achar = ["\s","\t","\n",nil,')',']','}','',':','=',">","<"]
      
      ok = (achar.include?(b1)||achar.include?(b2)) && (achar.include?(e1)||achar.include?(e2))
      ok = ok || _line_txt[m.begin(0)+_end..m.end(0)+_end-1].strip.length==1
      
      

#        p "" if stampa
#        p "_line_txt[m.begin(0)+_end..m.begin(0)+_end]=#{_line_txt[m.begin(0)+_end..m.begin(0)+_end]}"   if stampa
#        p "_line_txt[m.end(0)+_end..m.end(0)+_end]=#{_line_txt[m.end(0)+_end..m.end(0)+_end]}"   if stampa
#        p "_line_txt[m.begin(0)+_end..m.end(0)+_end]=#{_line_txt[m.begin(0)+_end..m.end(0)+_end]}"   if stampa
#        p "ok=#{ok}"  if stampa
      
      if ok
        _old_txt = _txt
        _ibegin = _row.to_s+'.'+(m.begin(0)+_end).to_s
        _end = m.end(0) + _end  
        _iend = _row.to_s+'.'+(_end.to_s)
        to_ret << [_ibegin, _iend]
      end
      if @op_only_first.include?(_tag) && ok
        m = nil
      else
        m = _re.match(_txt)
      end
    else
      m = nil
    end
  end
  to_ret
end

#highlight_tags(_row_begin, _code, _classes = self.classes) ⇒ Object



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
# File 'ext/ae-editor/ae-editor.rb', line 3905

def highlight_tags(_row_begin,_code,_classes=self.classes)
  super(_row_begin,_code)
  tags_map = Hash.new 
  lines = _code.split("\n")
  lines.each_with_index{|_line,_i|
    _line+="\n"
    _row = _row_begin+_i
    #p "_row=#{_row}-_line=#{_line}"
    _txt = _line
    _end = 0
    @op_to_end_line.each{|c|
      if _classes.include?(c) && @h_re[c]
        m_c = @h_re[c].match(_txt)
        if m_c then
          _ibegin = _row.to_s+'.'+(m_c.begin(0)).to_s
          _iend = _row.to_s+'.'+(_line.length - 1).to_s
          tags_map[c] = [] if tags_map[c].nil?
          tags_map[c] << [_ibegin, _iend]
          _txt = m_c.pre_match
        end
      end
    } if @langs_conf['re_op.to_line_end']

    _classes.each{|c|
      if !@op_to_end_line.include?(c) && @h_re[c]
        _tags = find_tag(c, _row, _txt)
        if _tags.length >0
          tags_map[c] = [] if tags_map[c].nil?
          tags_map[c].concat(_tags)
        end
      end
    } if _txt.strip.length > 0  
  }
  tags_map
end