Loading lib/jsduck/type_parser.rb +20 −7 Original line number Diff line number Diff line Loading @@ -31,19 +31,23 @@ module JsDuck @formatter = formatter end # Parses the type definition # # <type> ::= <varargs-type> [ "/" <type> ]* # def parse(str) @input = StringScanner.new(str) @error = :syntax @out = [] # Return immediately if base type doesn't match return false unless base_type # Return immediately if varargs-type doesn't match return false unless varargs_type # Go through enumeration of types, separated with "/" while @input.check(/\//) @out << @input.scan(/\//) # Fail if there's no base type after "/" return false unless base_type # Fail if there's no varargs-type after "/" return false unless varargs_type end # Concatenate all output Loading @@ -55,7 +59,9 @@ module JsDuck # The basic type # # <basic-type> ::= <type-name> [ "[]" ]* [ "..." ] # <varargs-type> ::= [ "..." ] <array-type> | <array-type> [ "..." ] # # <array-type> ::= <type-name> [ "[]" ] # # <type-name> ::= <ident-chain> | "*" # Loading @@ -64,7 +70,12 @@ module JsDuck # <ident> ::= [a-zA-Z0-9_]+ # # dot-separated identifiers followed by optional "[]" def base_type def varargs_type if @input.scan(/\.\.\./) varargs = true @out << "..." end type = @input.scan(/[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*|\*/) if !type Loading @@ -82,7 +93,9 @@ module JsDuck @out << "[]" end if !varargs @out << "..." if @input.scan(/\.\.\./) end true end Loading spec/type_parser_spec.rb +12 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,18 @@ describe JsDuck::TypeParser do parse("*").should == true end it "matches the varargs notation at the beginning" do parse("...String").should == true end it "doesn't accept varargs notation without a type name" do parse("...").should == false end it "doesn't accept both varargs notations at the same time" do parse("...*...").should == false end end end Loading Loading
lib/jsduck/type_parser.rb +20 −7 Original line number Diff line number Diff line Loading @@ -31,19 +31,23 @@ module JsDuck @formatter = formatter end # Parses the type definition # # <type> ::= <varargs-type> [ "/" <type> ]* # def parse(str) @input = StringScanner.new(str) @error = :syntax @out = [] # Return immediately if base type doesn't match return false unless base_type # Return immediately if varargs-type doesn't match return false unless varargs_type # Go through enumeration of types, separated with "/" while @input.check(/\//) @out << @input.scan(/\//) # Fail if there's no base type after "/" return false unless base_type # Fail if there's no varargs-type after "/" return false unless varargs_type end # Concatenate all output Loading @@ -55,7 +59,9 @@ module JsDuck # The basic type # # <basic-type> ::= <type-name> [ "[]" ]* [ "..." ] # <varargs-type> ::= [ "..." ] <array-type> | <array-type> [ "..." ] # # <array-type> ::= <type-name> [ "[]" ] # # <type-name> ::= <ident-chain> | "*" # Loading @@ -64,7 +70,12 @@ module JsDuck # <ident> ::= [a-zA-Z0-9_]+ # # dot-separated identifiers followed by optional "[]" def base_type def varargs_type if @input.scan(/\.\.\./) varargs = true @out << "..." end type = @input.scan(/[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*|\*/) if !type Loading @@ -82,7 +93,9 @@ module JsDuck @out << "[]" end if !varargs @out << "..." if @input.scan(/\.\.\./) end true end Loading
spec/type_parser_spec.rb +12 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,18 @@ describe JsDuck::TypeParser do parse("*").should == true end it "matches the varargs notation at the beginning" do parse("...String").should == true end it "doesn't accept varargs notation without a type name" do parse("...").should == false end it "doesn't accept both varargs notations at the same time" do parse("...*...").should == false end end end Loading