Class: RubySourceStructureParser
- Inherits:
-
SourceStructure
- Object
- SourceStructure
- RubySourceStructureParser
- Includes:
- RubySourceStructureUtils
- Defined in:
- ext/ae-editor/ae-editor.rb
Instance Attribute Summary
Attributes included from RubySourceStructureUtils
Attributes inherited from SourceStructure
Instance Method Summary collapse
-
#initialize(_source) ⇒ RubySourceStructureParser
constructor
attr_reader :injected_row.
- #parse_source(_source) ⇒ Object
Methods included from RubySourceStructureUtils
Methods inherited from SourceStructure
#class_node_by_line, #deep_node_by_line, #node_by_line, root
Constructor Details
#initialize(_source) ⇒ RubySourceStructureParser
attr_reader :injected_row
351 352 353 354 |
# File 'ext/ae-editor/ae-editor.rb', line 351 def initialize(_source) super() parse_source(_source) end |
Instance Method Details
#parse_source(_source) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'ext/ae-editor/ae-editor.rb', line 356 def parse_source(_source) _row = 1 _liv = 0 _livs = Array.new _livs[_liv]=@root _source.each_line{|line| line = "\s"+line.split("#")[0]+"\s" m = /[\s\n\t\;]+(module|class|def|if|unless|begin|case|for|while|do)[\s\n\t\;]+/.match("\s#{line}") if m index = m.post_match.strip.length - 1 if m.post_match.strip[index,index]=='{' _row = _row +1 next end _liv>=0? _liv = _liv + 1:_liv=1 _pliv = _liv _parent = nil while (_parent == nil && _pliv>=0) _pliv = _pliv -1 _parent = _livs[_pliv] end if _parent _helptext = m.post_match.strip _label = _helptext.split('<')[0] if _label == nil || _label.strip.length==0 _label = _helptext end if (m[0].strip[0..4] == "class" && m.pre_match.strip.length==0) _kind = 'class' if m.post_match.strip[0..1]=='<<' hinner_class = true else hinner_class = false end elsif (m[0].strip[0..4] == "class" && m.pre_match.strip.length>0) _row = _row +1 _liv = _liv - 1 next elsif (m[0].strip[0..5] == "module" && m.pre_match.strip.length==0) _kind = 'module' elsif (m[0].strip[0..5] == "module" && m.pre_match.strip.length>0) _row = _row +1 _liv = _liv - 1 next elsif ((m[0].strip[0..4] == "begin")||(m[0].strip[0..3] == "case") ||(m[0].strip[0..4] == "while") || (m[0].strip[0..2] == "for") || (m[0].strip[0..1] == "do") || ((m[0].strip[0..1] == "if" || m[0].strip[0..5] == "unless") && m.pre_match.strip.length==0)) _row = _row +1 next elsif ((m[0].strip[0..1] == "if" || m[0].strip[0..5] == "unless") && m.pre_match.strip.length>0) _row = _row +1 _liv = _liv - 1 next elsif (m[0].strip[0..2] == "def" && m.pre_match.strip.length==0) _kind = 'method' if _label.include?(_parent.label + '.') _kind = 'singleton method' end # elsif (m[0].strip[0..10] == "attr_reader" && m.pre_match.strip.length==0) # _kind = 'KAttr_reader' # _liv = _liv - 1 # _row = _row +1 end if _livs[_liv-1] && (_livs[_liv-1].kind != 'method' || (_livs[_liv-1].kind == 'method' && _kind == 'class' && hinner_class)) SourceTreeNode.new(_parent, _kind){|_node| _node.label = _label _node.helptext = _helptext _node.rif = _row.to_s _livs[_pliv + 1]=_node } else SourceTreeNode.new(_livs[_liv-3], _kind){|_node| _node.label = _label _node.helptext = _helptext _node.rif = _row.to_s _livs[_pliv-1]=_node } _liv = _liv - 2 end else _row = _row +1 _liv = _liv - 1 next end end m_end = /[\s\n\t\;]+end[\s\n\t\;]+/.match(line) if m_end if _livs[_liv] _livs[_liv].rif_end = _row #p "#{_livs[_liv].helptext} rif_end = #{_livs[_liv].rif_end}" end _liv = _liv - 1 end _row = _row +1 } end |