Commit d029feb1 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement @enum & @override as builtin tag classes.

parent 261f4bfc
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
require "jsduck/builtins/tag"

module JsDuck::Builtins
  class Enum < Tag
    def initialize
      @pattern = "enum"
    end

    # @enum {Type} [name=default] ...
    def parse(p)
      # @enum is a special case of class
      p.add_tag(:class)
      p.current_tag[:enum] = true
      p.maybe_type
      p.maybe_name_with_default
    end

  end
end
+24 −0
Original line number Diff line number Diff line
require "jsduck/builtins/tag"

module JsDuck::Builtins
  class Override < Tag
    def initialize
      @pattern = "override"
    end

    # @override nameOfOverride
    def parse(p)
      p.add_tag(:override)
      p.maybe_ident_chain(:class)

      # When @override not followed by class name, ignore the tag.
      # That's because the current ext codebase has some methods
      # tagged with @override to denote they override something.
      # But that's not what @override is meant for in JSDuck.
      unless p.current_tag[:class]
        p.remove_last_tag
      end
    end

  end
end
+0 −25
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ module JsDuck
      "inheritdoc" => [:at_inheritdoc],
      "inheritDoc" => [:at_inheritdoc],
      "alias" => [:at_alias_or_inheritdoc],
      "enum" => [:at_enum],
      "override" => [:at_override],
    }

    def parse(input, filename="", linenr=0)
@@ -198,29 +196,6 @@ module JsDuck
    # Routines for parsing of concrete tags...
    #

    # matches @enum {type} name ...
    def at_enum
      # @enum is a special case of class
      add_tag(:class)
      @current_tag[:enum] = true
      maybe_type
      maybe_name_with_default
    end

    # matches @override name ...
    def at_override
      add_tag(:override)
      maybe_ident_chain(:class)

      # When @override not followed by class name, ignore the tag.
      # That's because the current ext codebase has some methods
      # tagged with @override to denote they override something.
      # But that's not what @override is meant for in JSDuck.
      unless @current_tag[:class]
        remove_last_tag
      end
    end

    # matches @type {type}  or  @type type
    #
    # The presence of @type implies that we are dealing with property.