Loading lib/jsduck/lexer.rb +3 −1 Original line number Diff line number Diff line Loading @@ -72,9 +72,11 @@ module JsDuck while !@input.eos? do skip_white_and_comments if @input.check(/[0-9]+/) nr = @input.scan(/[0-9]+(\.[0-9]*)?/) @tokens << { :type => :number, :value => eval(@input.scan(/[0-9]+(\.[0-9]*)?/)) # When number ends with ".", append "0" so Ruby eval will work :value => eval(/\.$/ =~ nr ? nr+"0" : nr) } elsif @input.check(/\w+/) value = @input.scan(/\w+/) Loading spec/lexer_spec.rb +4 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,10 @@ describe JsDuck::Lexer do end end it "evaluates floating-point numbers with no digits after dot" do lex("alert(5.)")[2].should == [:number, 5.0] end it "ignores one-line comments" do lex("a // foo\n b").should == [[:ident, "a"], [:ident, "b"]] end Loading Loading
lib/jsduck/lexer.rb +3 −1 Original line number Diff line number Diff line Loading @@ -72,9 +72,11 @@ module JsDuck while !@input.eos? do skip_white_and_comments if @input.check(/[0-9]+/) nr = @input.scan(/[0-9]+(\.[0-9]*)?/) @tokens << { :type => :number, :value => eval(@input.scan(/[0-9]+(\.[0-9]*)?/)) # When number ends with ".", append "0" so Ruby eval will work :value => eval(/\.$/ =~ nr ? nr+"0" : nr) } elsif @input.check(/\w+/) value = @input.scan(/\w+/) Loading
spec/lexer_spec.rb +4 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,10 @@ describe JsDuck::Lexer do end end it "evaluates floating-point numbers with no digits after dot" do lex("alert(5.)")[2].should == [:number, 5.0] end it "ignores one-line comments" do lex("a // foo\n b").should == [[:ident, "a"], [:ident, "b"]] end Loading