Commit 519e8882 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

alternateClassName now always an array.

No matter if alternateClassName is missing, is a string or an array,
the result of parsing will always be an array - even if just one
item or empty.

Simplified the parsing - using array_of_strings method to do most
of the work.
parent aaf64479
Loading
Loading
Loading
Loading
+11 −26
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ module JsDuck
      cfg
    end

    # <ext-define-cfg> := "{" ( <extend> | <mixins> | <?> )*
    # <ext-define-cfg> := "{" ( <extend> | <mixins> | <alternate-class-name> | <?> )*
    def ext_define_cfg
      match("{")
      cfg = {}
@@ -205,15 +205,12 @@ module JsDuck
        if look("extend", ":", :string)
          cfg[:extend] = ext_define_extend
          found = true
        elsif look("alternateClassName", ":", '[')
          cfg[:alternateClassName] = ext_define_alternate_class_names
          found = true
        elsif look("alternateClassName", ":", :string)
          cfg[:alternateClassName] = ext_define_alternate_class_name
          found = true
        elsif look("mixins", ":", "{")
          cfg[:mixins] = ext_define_mixins
          found = true
        elsif look("alternateClassName", ":")
          cfg[:alternateClassName] = ext_define_alternate_class_name
          found = true
        elsif look(:ident, ":")
          match(:ident, ":")
          if look(:string) || look(:number) || look(:regex) ||
@@ -237,25 +234,15 @@ module JsDuck
      match("extend", ":", :string)
    end

    # <ext-define-alternate-class-name> := "alternateClassName" ":" <string>
    # <ext-define-alternate-class-name> := "alternateClassName" ":" ( <string> | <array-of-strings> )
    def ext_define_alternate_class_name
      match("alternateClassName", ":", :string)
    end

    # <ext-define-alternate-class-name> := "alternateClassName" ":" <string>
    def ext_define_alternate_class_names
      match("alternateClassName", ":", "[")
      strs = []
      while look(:string)
        strs << match(:string)
        match(",") if look(",")
      end

      if look("]")
        match("]")
        strs
      match("alternateClassName", ":")
      if look(:string)
        [ match(:string) ]
      elsif look("[")
        array_of_strings
      else
        false
        []
      end
    end

@@ -274,9 +261,7 @@ module JsDuck
    # <array-of-strings> := "[" [ <string> ","? ]* "]"
    def array_of_strings
      match("[")
      
      strs = []
      
      while look(:string)
        strs << match(:string)
        match(",") if look(",")
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ module JsDuck
        :doc => detect_doc(docs),
        :extends => detect_extends(doc_map, code),
        :mixins => detect_mixins(doc_map, code),
        :alternateClassName => code[:alternateClassName],
        :alternateClassName => code[:alternateClassName] || [],
        :xtype => detect_xtype(doc_map),
        :author => detect_author(doc_map),
        :singleton => !!doc_map[:singleton],