Commit 7c8f74f3 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement all member tags as builtin tag classes.

parent a4ed5e49
Loading
Loading
Loading
Loading
+5 −12
Original line number Diff line number Diff line
require "jsduck/builtins/tag"

module JsDuck::Builtins
  # Implementation of @cfg tag.
  class Cfg
  class Cfg < Tag
    def initialize
      @pattern = "cfg"
    end

    # @cfg {Type} [name=default] (required) ...
    def parse(p)
      p.add_tag(:cfg)
      p.maybe_type
      p.maybe_name_with_default
      maybe_required(p)
    end

    # matches: "(required)"
    def maybe_required(p)
      p.skip_horiz_white
      if p.look(/\(required\)/i)
        p.match(/\(required\)/i)
        p.current_tag[:optional] = false
      end
      p.maybe_required
    end
  end
end
+15 −0
Original line number Diff line number Diff line
require "jsduck/builtins/tag"

module JsDuck::Builtins
  class Event < Tag
    def initialize
      @pattern = "event"
    end

    # @event name ...
    def parse(p)
      p.add_tag(:event)
      p.maybe_name
    end
  end
end
+16 −0
Original line number Diff line number Diff line
require "jsduck/builtins/tag"

module JsDuck::Builtins
  # Implementation of @method tag.
  class Method < Tag
    def initialize
      @pattern = "method"
    end

    # @method name ...
    def parse(p)
      p.add_tag(:method)
      p.maybe_name
    end
  end
end
+16 −0
Original line number Diff line number Diff line
require "jsduck/builtins/tag"

module JsDuck::Builtins
  class Property < Tag
    def initialize
      @pattern = "property"
    end

    # @property {Type} [name=default] ...
    def parse(p)
      p.add_tag(:property)
      p.maybe_type
      p.maybe_name_with_default
    end
  end
end
+23 −0
Original line number Diff line number Diff line
module JsDuck::Builtins
  # Base class for all builtin tags.
  class Tag
    # Defines the name of the @tag.
    # The name itself must not contain the "@" sign.
    # For example: "cfg"
    attr_reader :pattern

    # Called by DocParser when the @tag is reached to do the parsing
    # from that point forward.  Gets passed an instance of DocParser.
    def parse(p)
    end

    # Returns all descendants of JsDuck::Builtins::Tag class.
    def self.descendants
      result = []
      ObjectSpace.each_object(::Class) do |cls|
        result << cls if cls < self
      end
      result
    end
  end
end
Loading