lib/jsduck/parser.rb in jsduck-0.1 vs lib/jsduck/parser.rb in jsduck-0.2
- old
+ new
@@ -7,13 +7,14 @@
@lex = Lexer.new(input)
@docs = []
end
# Parses the whole JavaScript block and returns array where for
- # each doc-comment there is a hash of two values: the comment
- # itself as string and parsed structure of the code that
- # immediately follows the comment.
+ # each doc-comment there is a hash of three values: the comment
+ # itself as string, number of the line where the comment starts,
+ # and parsed structure of the code that immediately follows the
+ # comment.
#
# For example with the following JavaScript input:
#
# /**
# * @param {String} foo
@@ -24,10 +25,11 @@
# The return value of this function will be:
#
# [
# {
# :comment => "/**\n * @param {String} foo\n */",
+ # :linenr => 1,
# :code => {
# :type => :assignment,
# :left => ["MyClass", "doIt"],
# :right => {
# :type => :function,
@@ -42,11 +44,13 @@
# ]
#
def parse
while !@lex.empty? do
if look(:doc_comment) then
+ comment = @lex.next(true)
@docs << {
- :comment => match(:doc_comment),
+ :comment => comment[:value],
+ :linenr => comment[:linenr],
:code => code_block
}
else
@lex.next
end