Loading lib/jsduck/lexer.rb +5 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,9 @@ module JsDuck # # {:type => :ident, :value => "foo"} # # For doc-comments the full token also contains the field :linenr, # pointing to the line where the doc-comment began. # def next(full=false) tok = @tokens.shift full ? tok : tok[:value] Loading Loading @@ -82,6 +85,8 @@ module JsDuck elsif @input.check(/\/\*\*/) then @tokens << { :type => :doc_comment, # Calculate current line number, starting with 1 :linenr => @input.string[0...@input.pos].count("\n") + 1, :value => @input.scan_until(/\*\/|\Z/) } elsif @input.check(/"/) then Loading spec/lexer_spec.rb +17 −3 Original line number Diff line number Diff line Loading @@ -8,6 +8,9 @@ describe JsDuck::Lexer do while !lex.empty? t = lex.next(true) tokens << [t[:type], t[:value]] if t[:linenr] tokens.last << t[:linenr] end end tokens end Loading Loading @@ -96,8 +99,19 @@ describe JsDuck::Lexer do lex("a /* foo */ b").should == [[:ident, "a"], [:ident, "b"]] end it "identifies doc-comments" do lex("/** foo */").should == [[:doc_comment, "/** foo */"]] it "identifies doc-comments together with line numbers" do lex("/** foo */").should == [[:doc_comment, "/** foo */", 1]] end it "counts line numbers correctly" do tokens = lex(<<-EOS) foo = { bar: foo, /** * My comment. */ EOS tokens.last.last.should == 3 end describe "handles unfinished" do Loading @@ -111,7 +125,7 @@ describe JsDuck::Lexer do end it "doc-comment" do lex("/** ").should == [[:doc_comment, "/** "]] lex("/** ").should == [[:doc_comment, "/** ", 1]] end end Loading Loading
lib/jsduck/lexer.rb +5 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,9 @@ module JsDuck # # {:type => :ident, :value => "foo"} # # For doc-comments the full token also contains the field :linenr, # pointing to the line where the doc-comment began. # def next(full=false) tok = @tokens.shift full ? tok : tok[:value] Loading Loading @@ -82,6 +85,8 @@ module JsDuck elsif @input.check(/\/\*\*/) then @tokens << { :type => :doc_comment, # Calculate current line number, starting with 1 :linenr => @input.string[0...@input.pos].count("\n") + 1, :value => @input.scan_until(/\*\/|\Z/) } elsif @input.check(/"/) then Loading
spec/lexer_spec.rb +17 −3 Original line number Diff line number Diff line Loading @@ -8,6 +8,9 @@ describe JsDuck::Lexer do while !lex.empty? t = lex.next(true) tokens << [t[:type], t[:value]] if t[:linenr] tokens.last << t[:linenr] end end tokens end Loading Loading @@ -96,8 +99,19 @@ describe JsDuck::Lexer do lex("a /* foo */ b").should == [[:ident, "a"], [:ident, "b"]] end it "identifies doc-comments" do lex("/** foo */").should == [[:doc_comment, "/** foo */"]] it "identifies doc-comments together with line numbers" do lex("/** foo */").should == [[:doc_comment, "/** foo */", 1]] end it "counts line numbers correctly" do tokens = lex(<<-EOS) foo = { bar: foo, /** * My comment. */ EOS tokens.last.last.should == 3 end describe "handles unfinished" do Loading @@ -111,7 +125,7 @@ describe JsDuck::Lexer do end it "doc-comment" do lex("/** ").should == [[:doc_comment, "/** "]] lex("/** ").should == [[:doc_comment, "/** ", 1]] end end Loading