Commit 999d170e authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move doc parsing out of JsParser & CssParser.

Instead do it in SourceFile which bind it all together with Merger.

This move brought out some glaring errors in previous benchmarks -
the JsParser also did doc-parsing while EsprimaParser did none of it.
Now things are much more equal and EsprimaParser receives a larger
performance penalty.

Again, parsing full Sencha Touch sources:

JsParser:      2.9s
EsprimaParser: 4.5s
parent 1307ebbb
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
require 'jsduck/lexer'
require 'jsduck/doc_parser'

module JsDuck

  class CssParser
    def initialize(input, options = {})
      @lex = Lexer.new(input)
      @doc_parser = DocParser.new
      @docs = []
    end

@@ -17,7 +15,7 @@ module JsDuck
        if look(:doc_comment)
          comment = @lex.next(true)
          @docs << {
            :comment => @doc_parser.parse(comment[:value]),
            :comment => comment[:value],
            :linenr => comment[:linenr],
            :code => code_block
          }
+4 −10
Original line number Diff line number Diff line
require 'jsduck/lexer'
require 'jsduck/doc_parser'
require 'jsduck/js_literal_parser'
require 'jsduck/js_literal_builder'

@@ -8,16 +7,14 @@ module JsDuck
  class JsParser < JsLiteralParser
    def initialize(input, options = {})
      @lex = Lexer.new(input)
      @doc_parser = DocParser.new
      @docs = []
      @ext_namespaces = options[:ext_namespaces] || ["Ext"]
    end

    # Parses the whole JavaScript block and returns array where for
    # each doc-comment there is a hash of three values: the comment
    # structure created by DocParser, number of the line where the
    # comment starts, and parsed structure of the code that
    # immediately follows the comment.
    # itself, the line number where the comment starts, and parsed
    # structure of the code that immediately follows the comment.
    #
    # For example with the following JavaScript input:
    #
@@ -31,10 +28,7 @@ module JsDuck
    #
    # [
    #   {
    #     :comment => [
    #       {:tagname => :default, :doc => "Method description"},
    #       {:tagname => :return, :type => "Number", :doc => ""},
    #     ],
    #     :comment => "/** * @param {String} foo */",
    #     :linenr => 1,
    #     :code => {
    #       :type => :assignment,
@@ -56,7 +50,7 @@ module JsDuck
        if look(:doc_comment)
          comment = @lex.next(true)
          @docs << {
            :comment => @doc_parser.parse(comment[:value]),
            :comment => comment[:value],
            :linenr => comment[:linenr],
            :code => code_block
          }
+5 −0
Original line number Diff line number Diff line
require 'jsduck/js_parser'
require 'jsduck/css_parser'
require 'jsduck/doc_parser'
require 'jsduck/merger'
require "cgi"

@@ -22,10 +23,14 @@ module JsDuck
      @html_filename = ""
      @links = {}

      doc_parser = DocParser.new

      merger = Merger.new
      merger.filename = @filename

      @docs = parse.map do |docset|
        merger.linenr = docset[:linenr]
        docset[:comment] = doc_parser.parse(docset[:comment])
        link(docset[:linenr], merger.merge(docset[:comment], docset[:code]))
      end
    end