From 0f11fd21bdf5417e8cbf86b554c60b9a7c3d464a Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Wed, 5 Dec 2012 09:41:49 -0800 Subject: [PATCH] Allow negative numbers in type definitions. --- lib/jsduck/type_parser.rb | 6 +++--- spec/type_parser_spec.rb | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/jsduck/type_parser.rb b/lib/jsduck/type_parser.rb index f38fcd50..7763574e 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 fd814e8d..35435a99 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 -- GitLab