Class: TodoNext::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/todo_next/parser.rb

Class Method Summary collapse

Class Method Details

.extract_meaningful_lines(text) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/todo_next/parser.rb', line 18

def self.extract_meaningful_lines(text)
   text.
       split("\n").
       collect do |text|
     col_offset = text =~ /\S/
     Line.new(text.strip, col_offset)
   end.
       reject{|l| l.blank?  }.
       reject{|l| l.comment?}.
       reject{|l| l.passed?}
end

.parse(text, prune_example_nodes = true) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/todo_next/parser.rb', line 8

def self.parse(text, prune_example_nodes=true)
  lines = extract_meaningful_lines(text)
  tree  = Tree::Factory.build(lines)
  if prune_example_nodes
    tree.visit(TodoNext::Tree::Visitor::ExampleNodesRemover.new)
    tree.visit(TodoNext::Tree::Visitor::LeafMaker          .new)
  end
  tree
end