class Rouge::Token

def [](qualname)

def [](qualname)
  return qualname unless qualname.is_a? ::String
  Token.cache[qualname]
end

def cache

def cache
  @cache ||= {}
end

def each_token(&b)

def each_token(&b)
  Token.cache.each do |(_, t)|
    b.call(t)
  end
end

def inspect

def inspect
  "<Token #{qualname}>"
end

def make_token(name, shortname, &b)

def make_token(name, shortname, &b)
  parent = self
  Class.new(parent) do
    @parent = parent
    @name = name
    @shortname = shortname
    register!
    class_eval(&b) if b
  end
end

def matches?(other)

def matches?(other)
  other.token_chain.include? self
end

def qualname

def qualname
  @qualname ||= token_chain.map(&:name).join('.')
end

def register!

def register!
  Token.cache[self.qualname] = self
  parent.sub_tokens[self.name] = self
end

def sub_tokens

def sub_tokens
  @sub_tokens ||= {}
end

def token(name, shortname, &b)

def token(name, shortname, &b)
  tok = make_token(name, shortname, &b)
  const_set(name, tok)
end

def token_chain

def token_chain
  @token_chain ||= ancestors.take_while { |x| x != Token }.reverse
end