Loading lib/jsduck/lexer.rb +1 −2 Original line number Diff line number Diff line Loading @@ -135,8 +135,7 @@ module JsDuck nr = @input.scan(/[0-9]+(\.[0-9]*)?/) @tokens << { :type => :number, # When number ends with ".", append "0" so Ruby eval will work :value => eval(/\.$/ =~ nr ? nr+"0" : nr) :value => nr } elsif @input.check(/\$/) value = @input.scan(/\$\w*/) Loading spec/lexer_spec.rb +3 −7 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ describe JsDuck::Lexer do [:keyword, "var"], [:ident, "foo"], [:operator, "="], [:number, 8], [:number, "8"], [:operator, ";"] ] end Loading @@ -35,7 +35,7 @@ describe JsDuck::Lexer do [:operator, ";"], [:ident, "y"], [:operator, "/"], [:number, 2] [:number, "2"] ] end Loading @@ -61,7 +61,7 @@ describe JsDuck::Lexer do lex("this / 3").should == [ [:keyword, "this"], [:operator, "/"], [:number, 3] [:number, "3"] ] end end Loading Loading @@ -91,10 +91,6 @@ 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 "identifies $ as beginning of identifier" do lex("$1a").should == [[:ident, "$1a"]] end Loading Loading
lib/jsduck/lexer.rb +1 −2 Original line number Diff line number Diff line Loading @@ -135,8 +135,7 @@ module JsDuck nr = @input.scan(/[0-9]+(\.[0-9]*)?/) @tokens << { :type => :number, # When number ends with ".", append "0" so Ruby eval will work :value => eval(/\.$/ =~ nr ? nr+"0" : nr) :value => nr } elsif @input.check(/\$/) value = @input.scan(/\$\w*/) Loading
spec/lexer_spec.rb +3 −7 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ describe JsDuck::Lexer do [:keyword, "var"], [:ident, "foo"], [:operator, "="], [:number, 8], [:number, "8"], [:operator, ";"] ] end Loading @@ -35,7 +35,7 @@ describe JsDuck::Lexer do [:operator, ";"], [:ident, "y"], [:operator, "/"], [:number, 2] [:number, "2"] ] end Loading @@ -61,7 +61,7 @@ describe JsDuck::Lexer do lex("this / 3").should == [ [:keyword, "this"], [:operator, "/"], [:number, 3] [:number, "3"] ] end end Loading Loading @@ -91,10 +91,6 @@ 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 "identifies $ as beginning of identifier" do lex("$1a").should == [[:ident, "$1a"]] end Loading