From db238621f0ebbac4ae7fbcba769d2b31bf7ce2b6 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Wed, 23 Jan 2013 21:42:29 +0200 Subject: [PATCH] Move use of Parser out of Source::File. With the help of our new MiniParser, we only need to change the parsing setup code in there, not touching all the related specs. --- lib/jsduck/batch_parser.rb | 5 ++++- lib/jsduck/source/file.rb | 6 ++---- spec/mini_parser.rb | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/jsduck/batch_parser.rb b/lib/jsduck/batch_parser.rb index bc722305..0eae6fe7 100644 --- a/lib/jsduck/batch_parser.rb +++ b/lib/jsduck/batch_parser.rb @@ -1,5 +1,6 @@ require 'jsduck/util/parallel' require 'jsduck/util/io' +require 'jsduck/parser' require 'jsduck/source/file' require 'jsduck/logger' @@ -13,7 +14,9 @@ module JsDuck Util::Parallel.map(opts.input_files) do |fname| Logger.log("Parsing", fname) begin - Source::File.new(Util::IO.read(fname), fname, opts) + source = Util::IO.read(fname) + docs = Parser.new.parse(source, fname, opts) + Source::File.new(source, docs, fname) rescue Logger.fatal_backtrace("Error while parsing #{fname}", $!) exit(1) diff --git a/lib/jsduck/source/file.rb b/lib/jsduck/source/file.rb index 38e686d1..80d49060 100644 --- a/lib/jsduck/source/file.rb +++ b/lib/jsduck/source/file.rb @@ -1,4 +1,3 @@ -require 'jsduck/parser' require 'jsduck/util/html' module JsDuck @@ -14,14 +13,13 @@ module JsDuck attr_reader :docs attr_reader :html_filename - def initialize(contents, filename="", options={}) + def initialize(contents, docs, filename="") @contents = contents + @docs = docs @filename = filename @html_filename = "" @links = {} - @docs = Parser.new.parse(@contents, @filename, options) - @docs.map do |docset| link(docset[:linenr], docset) end diff --git a/spec/mini_parser.rb b/spec/mini_parser.rb index 2d6fb64e..2bdf1701 100644 --- a/spec/mini_parser.rb +++ b/spec/mini_parser.rb @@ -1,4 +1,5 @@ require "jsduck/aggregator" +require "jsduck/parser" require "jsduck/class" require "jsduck/relations" require "jsduck/source/file" @@ -22,7 +23,7 @@ module Helper class MiniParser def self.parse(string, opts={}) fname = opts[:filename] || "" - file = JsDuck::Source::File.new(string, fname) + file = JsDuck::Source::File.new(string, JsDuck::Parser.new.parse(string, fname), fname) agr = JsDuck::Aggregator.new agr.aggregate(file) -- GitLab