Commit 0f11fd21 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Allow negative numbers in type definitions.

parent 8a7b3721
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ module JsDuck
        return false unless function_type
      elsif @input.check(/['"]/)
        return false unless string_literal
      elsif @input.check(/\d/)
      elsif @input.check(/[\d-]/)
        return false unless number_literal
      else
        return false unless type_name
@@ -305,10 +305,10 @@ module JsDuck
    end

    #
    #     <number-literal> ::= <digit>+ [ "." <digit>+ ]
    #     <number-literal> ::= [ "-" ] <digit>+ [ "." <digit>+ ]
    #
    def number_literal
      @out << @input.scan(/\d+(\.\d+)?/)
      @out << @input.scan(/-?\d+(\.\d+)?/)

      true
    end
+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ describe JsDuck::TypeParser do
    parse('42').should == true
  end

  it "matches negative number literal" do
    parse('-6').should == true
  end

  it "matches float number literal" do
    parse('3.14').should == true
  end