Commit 397074f7 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Fix parsing of floats that end with dot.

parent ee8380a9
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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+/)
+4 −0
Original line number Diff line number Diff line
@@ -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