Loading lib/jsduck/type_parser.rb +28 −1 Original line number Diff line number Diff line Loading @@ -111,7 +111,11 @@ module JsDuck end # # <type-name> ::= <ident-chain> | "*" # <type-name> ::= <type-application> | "*" # # <type-application> ::= <ident-chain> [ "." "<" <type-arguments> ">" ] # # <type-arguments> ::= <alteration-type> [ "," <alteration-type> ]* # # <ident-chain> ::= <ident> [ "." <ident> ]* # Loading @@ -131,6 +135,29 @@ module JsDuck return false end # All type names besides * can be followed by .<arguments> if name != "*" && @input.scan(/\.</) return false unless type_arguments return false unless @input.scan(/>/) end true end # # <type-arguments> ::= <alteration-type> [ "," <alteration-type> ]* # def type_arguments # First argument is required return false unless alteration_type # Go through additional arguments, separated with "," while @input.check(/,/) @out << @input.scan(/,/) # Fail if there's no alteration-type after "," return false unless alteration_type end true end Loading spec/type_parser_spec.rb +21 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ describe JsDuck::TypeParser do "String", "Number", "RegExp", "Array", "Ext.form.Panel", "Ext.Element", "Ext.fx2.Anim", Loading Loading @@ -170,6 +171,26 @@ describe JsDuck::TypeParser do parse("String=").should == false end it "matches single type argument" do parse("Array.<Number>").should == true end it "matches multiple type arguments" do parse("Ext.Element.<String,Number>").should == true end it "matches nested type arguments" do parse("Array.<Array.<String>|Array.<Number>>").should == true end it "doesn't accept type arguments on type union" do parse("(Array,RegExp).<String>").should == false end it "doesn't accept empty type arguments block" do parse("Array.<>").should == false end end end Loading Loading
lib/jsduck/type_parser.rb +28 −1 Original line number Diff line number Diff line Loading @@ -111,7 +111,11 @@ module JsDuck end # # <type-name> ::= <ident-chain> | "*" # <type-name> ::= <type-application> | "*" # # <type-application> ::= <ident-chain> [ "." "<" <type-arguments> ">" ] # # <type-arguments> ::= <alteration-type> [ "," <alteration-type> ]* # # <ident-chain> ::= <ident> [ "." <ident> ]* # Loading @@ -131,6 +135,29 @@ module JsDuck return false end # All type names besides * can be followed by .<arguments> if name != "*" && @input.scan(/\.</) return false unless type_arguments return false unless @input.scan(/>/) end true end # # <type-arguments> ::= <alteration-type> [ "," <alteration-type> ]* # def type_arguments # First argument is required return false unless alteration_type # Go through additional arguments, separated with "," while @input.check(/,/) @out << @input.scan(/,/) # Fail if there's no alteration-type after "," return false unless alteration_type end true end Loading
spec/type_parser_spec.rb +21 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ describe JsDuck::TypeParser do "String", "Number", "RegExp", "Array", "Ext.form.Panel", "Ext.Element", "Ext.fx2.Anim", Loading Loading @@ -170,6 +171,26 @@ describe JsDuck::TypeParser do parse("String=").should == false end it "matches single type argument" do parse("Array.<Number>").should == true end it "matches multiple type arguments" do parse("Ext.Element.<String,Number>").should == true end it "matches nested type arguments" do parse("Array.<Array.<String>|Array.<Number>>").should == true end it "doesn't accept type arguments on type union" do parse("(Array,RegExp).<String>").should == false end it "doesn't accept empty type arguments block" do parse("Array.<>").should == false end end end Loading