class DGD::Doc::SourceFile
Attributes
parser[R]
Public Class Methods
new(path, dgd_root:)
click to toggle source
# File lib/dgd-tools/dgd-doc.rb, line 17 def initialize(path, dgd_root:) unless File.exist?(path) raise "No such source file for DGD::Doc::Sourcefile: #{path.inspect}" end @parser = DGDGrammarParser.new @path = path @dgd_root = dgd_root parse_contents end
Private Instance Methods
clean_tree(root_node)
click to toggle source
# File lib/dgd-tools/dgd-doc.rb, line 49 def clean_tree(root_node) return if(root_node.elements.nil?) root_node.elements.each {|node| self.clean_tree(node) } root_node.elements.delete_if {|node| node.class.name == "Treetop::Runtime::SyntaxNode" && node.text_value.size < 20 } end
parse_contents()
click to toggle source
# File lib/dgd-tools/dgd-doc.rb, line 31 def parse_contents preproc_output = `cpp -C -I#{@dgd_root}/include -D__DGD__ #{@path}` preproc_output.gsub!(/\n+/, "\n") # The preprocessor often winds up leaving a lot of newlines from various sources preproc_output.gsub!(/^# \d+ ".*"\w*\d*$/, "") data = @parser.parse(preproc_output) if data clean_tree(data) #puts data.inspect else puts @parser.failure_reason puts @parser.failure_line puts @parser.failure_column #puts "Preproc output was:#{preproc_output}\n\n\n" raise "Parse error!" end end