diff --git a/lib/jsduck/type_parser.rb b/lib/jsduck/type_parser.rb index f38fcd502ed1bc0d5d77fe4e0b8c529f89ca84a7..7763574ee4f115be9941944f1a374bdb65a33402 100644 --- a/lib/jsduck/type_parser.rb +++ b/lib/jsduck/type_parser.rb @@ -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 # - # ::= + [ "." + ] + # ::= [ "-" ] + [ "." + ] # def number_literal - @out << @input.scan(/\d+(\.\d+)?/) + @out << @input.scan(/-?\d+(\.\d+)?/) true end diff --git a/spec/type_parser_spec.rb b/spec/type_parser_spec.rb index fd814e8d9dac6fa71a098e653bc59ff27e2d59db..35435a99f42683ccc0401d8174569cbd1b3ca1b5 100644 --- a/spec/type_parser_spec.rb +++ b/spec/type_parser_spec.rb @@ -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