language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | Homebrew | brew | 61a7ffb999963a2ef8d8f0b247956c8280cb831a.json | development_tools: add type signatures | Library/Homebrew/os/mac/xcode.rb | @@ -1,4 +1,4 @@
-# typed: false
+# typed: true
# frozen_string_literal: true
module OS
@@ -89,6 +89,7 @@ def without_clt?
# Returns a Pathname object corresponding to Xcode.app's Developer
# directory or nil if Xcode.app is not installed.
+ sig { returns(Pathname) }
def prefix
@prefix ||=
begin
@@ -109,6 +110,7 @@ def toolchain_path
Pathname("#{prefix}/Toolchains/XcodeDefault.xctoolchain")
end
+ sig { returns(T.nilable(Pathname)) }
def bundle_path
# Use the default location if it exists.
return DEFAULT_BUNDLE_PATH if DEFAULT_BUNDLE_PATH.exist?
@@ -124,18 +126,22 @@ def installed?
!prefix.nil?
end
+ sig { returns(XcodeSDKLocator) }
def sdk_locator
@sdk_locator ||= XcodeSDKLocator.new
end
+ sig { params(v: T.nilable(MacOS::Version)).returns(T.nilable(SDK)) }
def sdk(v = nil)
sdk_locator.sdk_if_applicable(v)
end
+ sig { params(v: T.nilable(MacOS::Version)).returns(T.nilable(Pathname)) }
def sdk_path(v = nil)
sdk(v)&.path
end
+ sig { returns(String) }
def installation_instructions
if OS::Mac.version.prerelease?
<<~EOS
@@ -163,6 +169,7 @@ def update_instructions
end
end
+ sig { returns(::Version) }
def version
# may return a version string
# that is guessed based on the compiler, so do not
@@ -174,6 +181,7 @@ def version
end
end
+ sig { returns(T.nilable(String)) }
def detect_version
# This is a separate function as you can't cache the value out of a block
# if return is used in the middle, which we do many times in here.
@@ -231,6 +239,7 @@ def detect_version_from_clang_version
end
end
+ sig { returns(T::Boolean) }
def default_prefix?
prefix.to_s == "/Applications/Xcode.app/Contents/Developer"
end
@@ -255,26 +264,32 @@ def installed?
!version.null?
end
+ sig { returns(T::Boolean) }
def separate_header_package?
version >= "10" && MacOS.version >= "10.14"
end
+ sig { returns(T::Boolean) }
def provides_sdk?
version >= "8"
end
+ sig { returns(CLTSDKLocator) }
def sdk_locator
@sdk_locator ||= CLTSDKLocator.new
end
+ sig { params(v: T.nilable(MacOS::Version)).returns(T.nilable(SDK)) }
def sdk(v = nil)
sdk_locator.sdk_if_applicable(v)
end
+ sig { params(v: T.nilable(MacOS::Version)).returns(T.nilable(Pathname)) }
def sdk_path(v = nil)
sdk(v)&.path
end
+ sig { returns(String) }
def installation_instructions
if MacOS.version == "10.14"
# This is not available from `xcode-select`
@@ -344,6 +359,7 @@ def minimum_version
end
end
+ sig { returns(T::Boolean) }
def below_minimum_version?
return false unless installed?
@@ -358,18 +374,21 @@ def outdated?
::Version.new(clang_version) < latest_clang_version
end
+ sig { returns(T.nilable(String)) }
def detect_clang_version
version_output = Utils.popen_read("#{PKG_PATH}/usr/bin/clang", "--version")
version_output[/clang-(\d+\.\d+\.\d+(\.\d+)?)/, 1]
end
+ sig { returns(T.nilable(String)) }
def detect_version_from_clang_version
detect_clang_version&.sub(/^(\d+)0(\d)\./, "\\1.\\2.")
end
# Version string (a pretty long one) of the CLT package.
# Note that the different ways of installing the CLTs lead to different
# version numbers.
+ sig { returns(::Version) }
def version
if @version ||= detect_version
::Version.new @version
@@ -378,8 +397,9 @@ def version
end
end
+ sig { returns(T.nilable(String)) }
def detect_version
- version = nil
+ version = T.let(nil, T.nilable(String))
[EXECUTABLE_PKG_ID, MAVERICKS_NEW_PKG_ID].each do |id|
next unless File.exist?("#{PKG_PATH}/usr/bin/clang")
| true |
Other | Homebrew | brew | 61a7ffb999963a2ef8d8f0b247956c8280cb831a.json | development_tools: add type signatures | Library/Homebrew/os/mac/xcode.rbi | @@ -0,0 +1,9 @@
+# typed: strict
+
+module OS
+ module Mac
+ module Xcode
+ include Kernel
+ end
+ end
+end | true |
Other | Homebrew | brew | 4685120692e0bdea960d7a389801c2fc249b9d59.json | add cask option to brew log | Library/Homebrew/cmd/log.rb | @@ -1,7 +1,6 @@
# typed: false
# frozen_string_literal: true
-require "formula"
require "cli/parser"
module Homebrew
@@ -26,10 +25,15 @@ def log_args
description: "Print only one commit."
flag "-n", "--max-count=",
description: "Print only a specified number of commits."
+ switch "--formula", "--formulae",
+ description: "Treat all named arguments as formulae."
+ switch "--cask", "--casks",
+ description: "Treat all named arguments as casks."
conflicts "-1", "--max-count"
+ conflicts "--formula", "--cask"
- named_args :formula, max: 1
+ named_args [:formula, :cask], max: 1
end
end
@@ -43,7 +47,7 @@ def log
if args.no_named?
git_log HOMEBREW_REPOSITORY, args: args
else
- path = Formulary.path(args.named.first)
+ path = args.named.to_paths.first
tap = Tap.from_path(path)
git_log path.dirname, path, tap, args: args
end | false |
Other | Homebrew | brew | 35e0b1bf85c12ed39295c9f781d604be58afb6c1.json | Update RBI files for nokogiri. | Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi | @@ -9829,8 +9829,211 @@ class WeakRef
def initialize(orig); end
end
+class WebRobots
+ def allowed?(url); end
+
+ def crawl_delay(url); end
+
+ def create_cache(); end
+
+ def disallowed?(url); end
+
+ def error(url); end
+
+ def error!(url); end
+
+ def flush_cache(); end
+
+ def initialize(user_agent, options=T.unsafe(nil)); end
+
+ def option(url, token); end
+
+ def options(url); end
+
+ def reset(url); end
+
+ def sitemaps(url); end
+
+ def user_agent(); end
+end
+
+class WebRobots::Error
+end
+
+class WebRobots::Error
+end
+
+class WebRobots::ParseError
+ def initialize(message, site); end
+
+ def site(); end
+end
+
+class WebRobots::ParseError
+end
+
+class WebRobots::RobotsTxt
+ def allow?(request_uri, user_agent=T.unsafe(nil)); end
+
+ def crawl_delay(user_agent=T.unsafe(nil)); end
+
+ def error(); end
+
+ def error!(); end
+
+ def error=(error); end
+
+ def initialize(site, records, options=T.unsafe(nil)); end
+
+ def options(user_agent=T.unsafe(nil)); end
+
+ def site(); end
+
+ def sitemaps(); end
+
+ def timestamp(); end
+ DISALLOW_ALL = ::T.let(nil, ::T.untyped)
+end
+
+class WebRobots::RobotsTxt::AccessControlLine
+ def match?(request_uri); end
+end
+
+class WebRobots::RobotsTxt::AccessControlLine
+end
+
+class WebRobots::RobotsTxt::AgentLine
+ def pattern(); end
+end
+
+class WebRobots::RobotsTxt::AgentLine
+end
+
+class WebRobots::RobotsTxt::AllowLine
+ def allow?(); end
+end
+
+class WebRobots::RobotsTxt::AllowLine
+end
+
+class WebRobots::RobotsTxt::CrawlDelayLine
+ def delay(); end
+end
+
+class WebRobots::RobotsTxt::CrawlDelayLine
+end
+
+class WebRobots::RobotsTxt::DisallowLine
+ def allow?(); end
+end
+
+class WebRobots::RobotsTxt::DisallowLine
+end
+
+class WebRobots::RobotsTxt::ExtentionLine
+end
+
+class WebRobots::RobotsTxt::ExtentionLine
+end
+
+class WebRobots::RobotsTxt::Line
+ def compile(); end
+
+ def initialize(token, value); end
+
+ def token(); end
+
+ def value(); end
+end
+
+class WebRobots::RobotsTxt::Line
+end
+
class WebRobots::RobotsTxt::Parser
+ def _reduce_1(val, _values, result); end
+
+ def _reduce_17(val, _values, result); end
+
+ def _reduce_18(val, _values, result); end
+
+ def _reduce_19(val, _values, result); end
+
+ def _reduce_2(val, _values, result); end
+
+ def _reduce_20(val, _values, result); end
+
+ def _reduce_21(val, _values, result); end
+
+ def _reduce_24(val, _values, result); end
+
+ def _reduce_25(val, _values, result); end
+
+ def _reduce_26(val, _values, result); end
+
+ def _reduce_28(val, _values, result); end
+
+ def _reduce_31(val, _values, result); end
+
+ def _reduce_32(val, _values, result); end
+
+ def _reduce_38(val, _values, result); end
+
+ def _reduce_39(val, _values, result); end
+
+ def _reduce_40(val, _values, result); end
+
+ def _reduce_41(val, _values, result); end
+
+ def _reduce_none(val, _values, result); end
+
+ def initialize(target, crawl_delay_handler=T.unsafe(nil)); end
+
+ def on_error(token_id, value, stack); end
+
+ def parse(input, site); end
+
+ def parse!(input, site); end
+
+ def parse_error(message); end
+ KNOWN_TOKENS = ::T.let(nil, ::T.untyped)
+ RE_KNOWN_TOKENS = ::T.let(nil, ::T.untyped)
+ Racc_arg = ::T.let(nil, ::T.untyped)
Racc_debug_parser = ::T.let(nil, ::T.untyped)
+ Racc_token_to_s_table = ::T.let(nil, ::T.untyped)
+end
+
+class WebRobots::RobotsTxt::Parser
+end
+
+class WebRobots::RobotsTxt::Record
+ def allow?(request_uri); end
+
+ def default?(); end
+
+ def delay(); end
+
+ def initialize(agentlines, rulelines); end
+
+ def match?(user_agent); end
+
+ def options(); end
+end
+
+class WebRobots::RobotsTxt::Record
+end
+
+class WebRobots::RobotsTxt
+ def self.unfetchable(site, reason, target=T.unsafe(nil)); end
+end
+
+class WebRobots
+end
+
+module Webrobots
+ VERSION = ::T.let(nil, ::T.untyped)
+end
+
+module Webrobots
end
class Zlib::Deflate | false |
Other | Homebrew | brew | 8398be5cde653f4637a81af8f7e078ddacc49417.json | docs/Installation: update commands for untar-anywhere method | docs/Homebrew-on-Linux.md | @@ -78,17 +78,6 @@ You may need to install your own Ruby using your system package manager, a PPA,
Homebrew does not currently support 32-bit x86 platforms. It would be possible for Homebrew to work on 32-bit x86 platforms with some effort. An interested and dedicated person could maintain a fork of Homebrew to develop support for 32-bit x86.
-## Alternative Installation
-
-Extract or `git clone` Homebrew wherever you want. Use `/home/linuxbrew/.linuxbrew` if possible (to enable the use of binary packages).
-
-```sh
-git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew
-mkdir ~/.linuxbrew/bin
-ln -s ~/.linuxbrew/Homebrew/bin/brew ~/.linuxbrew/bin
-eval "$(~/.linuxbrew/bin/brew shellenv)"
-```
-
## Homebrew on Linux Community
- [@HomebrewOnLinux on Twitter](https://twitter.com/HomebrewOnLinux) | true |
Other | Homebrew | brew | 8398be5cde653f4637a81af8f7e078ddacc49417.json | docs/Installation: update commands for untar-anywhere method | docs/Installation.md | @@ -53,6 +53,20 @@ here. *Pick another prefix at your peril!*
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
```
+or
+
+```sh
+git clone https://github.com/Homebrew/brew homebrew
+```
+
+then
+
+```sh
+eval "$(homebrew/bin/brew shellenv)"
+brew update --force --quiet
+chmod -R go-w "$(brew --prefix)/share/zsh"
+```
+
### Multiple installations
Create a Homebrew installation wherever you extract the tarball. Whichever `brew` command is called is where the packages will be installed. You can use this as you see fit, e.g. a system set of libs in the default prefix and tweaked formulae for development in `~/homebrew`. | true |
Other | Homebrew | brew | 0109c699bcc0174d36aad0e0957b9b32b0e5d90c.json | Update RBI files for nokogiri. | Library/Homebrew/sorbet/rbi/gems/mini_portile2@2.6.1.rbi | @@ -32,6 +32,9 @@ class MiniPortile
def patch_files; end
def patch_files=(_arg0); end
def path; end
+ def prepare_build_directory; end
+ def source_directory; end
+ def source_directory=(path); end
def target; end
def target=(_arg0); end
def version; end | true |
Other | Homebrew | brew | 0109c699bcc0174d36aad0e0957b9b32b0e5d90c.json | Update RBI files for nokogiri. | Library/Homebrew/sorbet/rbi/gems/nokogiri@1.12.5.rbi | @@ -6,14 +6,17 @@
module Nokogiri
class << self
- def HTML(thing, url = T.unsafe(nil), encoding = T.unsafe(nil), options = T.unsafe(nil), &block); end
+ def HTML(input, url = T.unsafe(nil), encoding = T.unsafe(nil), options = T.unsafe(nil), &block); end
+ def HTML4(input, url = T.unsafe(nil), encoding = T.unsafe(nil), options = T.unsafe(nil), &block); end
+ def HTML5(input, url = T.unsafe(nil), encoding = T.unsafe(nil), **options, &block); end
def Slop(*args, &block); end
def XML(thing, url = T.unsafe(nil), encoding = T.unsafe(nil), options = T.unsafe(nil), &block); end
def XSLT(stylesheet, modules = T.unsafe(nil)); end
def install_default_aliases; end
def jruby?; end
def make(input = T.unsafe(nil), opts = T.unsafe(nil), &blk); end
def parse(string, url = T.unsafe(nil), encoding = T.unsafe(nil), options = T.unsafe(nil)); end
+ def uses_gumbo?; end
def uses_libxml?(requirement = T.unsafe(nil)); end
end
end
@@ -201,18 +204,30 @@ class Nokogiri::EncodingHandler
end
end
-module Nokogiri::HTML
+module Nokogiri::Gumbo
+ class << self
+ def fragment(_arg0, _arg1, _arg2, _arg3, _arg4, _arg5); end
+ def parse(_arg0, _arg1, _arg2, _arg3, _arg4); end
+ end
+end
+
+Nokogiri::Gumbo::DEFAULT_MAX_ATTRIBUTES = T.let(T.unsafe(nil), Integer)
+Nokogiri::Gumbo::DEFAULT_MAX_ERRORS = T.let(T.unsafe(nil), Integer)
+Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH = T.let(T.unsafe(nil), Integer)
+Nokogiri::HTML = Nokogiri::HTML4
+
+module Nokogiri::HTML4
class << self
def fragment(string, encoding = T.unsafe(nil)); end
- def parse(thing, url = T.unsafe(nil), encoding = T.unsafe(nil), options = T.unsafe(nil), &block); end
+ def parse(input, url = T.unsafe(nil), encoding = T.unsafe(nil), options = T.unsafe(nil), &block); end
end
end
-class Nokogiri::HTML::Builder < ::Nokogiri::XML::Builder
+class Nokogiri::HTML4::Builder < ::Nokogiri::XML::Builder
def to_html; end
end
-class Nokogiri::HTML::Document < ::Nokogiri::XML::Document
+class Nokogiri::HTML4::Document < ::Nokogiri::XML::Document
def fragment(tags = T.unsafe(nil)); end
def meta_encoding; end
def meta_encoding=(encoding); end
@@ -238,13 +253,13 @@ class Nokogiri::HTML::Document < ::Nokogiri::XML::Document
end
end
-class Nokogiri::HTML::Document::EncodingFound < ::StandardError
+class Nokogiri::HTML4::Document::EncodingFound < ::StandardError
def initialize(encoding); end
def found_encoding; end
end
-class Nokogiri::HTML::Document::EncodingReader
+class Nokogiri::HTML4::Document::EncodingReader
def initialize(io); end
def encoding_found; end
@@ -255,28 +270,28 @@ class Nokogiri::HTML::Document::EncodingReader
end
end
-class Nokogiri::HTML::Document::EncodingReader::JumpSAXHandler < ::Nokogiri::HTML::Document::EncodingReader::SAXHandler
+class Nokogiri::HTML4::Document::EncodingReader::JumpSAXHandler < ::Nokogiri::HTML4::Document::EncodingReader::SAXHandler
def initialize(jumptag); end
def start_element(name, attrs = T.unsafe(nil)); end
end
-class Nokogiri::HTML::Document::EncodingReader::SAXHandler < ::Nokogiri::XML::SAX::Document
+class Nokogiri::HTML4::Document::EncodingReader::SAXHandler < ::Nokogiri::XML::SAX::Document
def initialize; end
def encoding; end
def start_element(name, attrs = T.unsafe(nil)); end
end
-class Nokogiri::HTML::DocumentFragment < ::Nokogiri::XML::DocumentFragment
+class Nokogiri::HTML4::DocumentFragment < ::Nokogiri::XML::DocumentFragment
def initialize(document, tags = T.unsafe(nil), ctx = T.unsafe(nil)); end
class << self
def parse(tags, encoding = T.unsafe(nil)); end
end
end
-class Nokogiri::HTML::ElementDescription
+class Nokogiri::HTML4::ElementDescription
def block?; end
def default_sub_element; end
def deprecated?; end
@@ -303,132 +318,132 @@ class Nokogiri::HTML::ElementDescription
end
end
-Nokogiri::HTML::ElementDescription::ACTION_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::ALIGN_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::ALT_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::APPLET_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::AREA_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::A_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::BASEFONT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::BGCOLOR_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::BLOCK = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::BLOCKLI_ELT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::BODY_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::BODY_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::BODY_DEPR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::BUTTON_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::CELLHALIGN = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::CELLVALIGN = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::CLEAR_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::COL_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::COL_ELT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::COMPACT_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::COMPACT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::CONTENT_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::COREATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::CORE_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::CORE_I18N_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::DIR_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::DL_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::DefaultDescriptions = T.let(T.unsafe(nil), Hash)
-Nokogiri::HTML::ElementDescription::Desc = Struct
-Nokogiri::HTML::ElementDescription::EDIT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::EMBED_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::EMPTY = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::EVENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FIELDSET_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FLOW = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FLOW_PARAM = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FONTSTYLE = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FONT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FORMCTRL = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FORM_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FORM_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FRAMESET_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FRAMESET_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::FRAME_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HEADING = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HEAD_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HEAD_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HREF_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HR_DEPR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HTML_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HTML_CDATA = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HTML_CONTENT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HTML_FLOW = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HTML_INLINE = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::HTML_PCDATA = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::I18N = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::I18N_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::IFRAME_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::IMG_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::INLINE = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::INLINE_P = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::INPUT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::LABEL_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::LABEL_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::LANGUAGE_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::LEGEND_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::LINK_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::LIST = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::LI_ELT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::MAP_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::META_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::MODIFIER = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::NAME_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::NOFRAMES_CONTENT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::OBJECT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::OBJECT_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::OBJECT_DEPR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::OL_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::OPTGROUP_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::OPTION_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::OPTION_ELT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::PARAM_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::PCDATA = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::PHRASE = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::PRE_CONTENT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::PROMPT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::QUOTE_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::ROWS_COLS_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::SCRIPT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::SELECT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::SELECT_CONTENT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::SPECIAL = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::SRC_ALT_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::STYLE_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TABLE_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TABLE_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TABLE_DEPR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TALIGN_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TARGET_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TEXTAREA_ATTRS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TH_TD_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TH_TD_DEPR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TR_CONTENTS = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TR_ELT = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::TYPE_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::UL_DEPR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::VERSION_ATTR = T.let(T.unsafe(nil), Array)
-Nokogiri::HTML::ElementDescription::WIDTH_ATTR = T.let(T.unsafe(nil), Array)
-class Nokogiri::HTML::EntityDescription < ::Struct; end
-
-class Nokogiri::HTML::EntityLookup
+Nokogiri::HTML4::ElementDescription::ACTION_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::ALIGN_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::ALT_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::APPLET_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::AREA_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::A_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::BASEFONT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::BGCOLOR_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::BLOCK = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::BLOCKLI_ELT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::BODY_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::BODY_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::BODY_DEPR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::BUTTON_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::CELLHALIGN = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::CELLVALIGN = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::CLEAR_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::COL_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::COL_ELT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::COMPACT_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::COMPACT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::CONTENT_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::COREATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::CORE_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::CORE_I18N_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::DIR_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::DL_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::DefaultDescriptions = T.let(T.unsafe(nil), Hash)
+Nokogiri::HTML4::ElementDescription::Desc = Struct
+Nokogiri::HTML4::ElementDescription::EDIT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::EMBED_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::EMPTY = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::EVENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FIELDSET_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FLOW = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FLOW_PARAM = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FONTSTYLE = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FONT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FORMCTRL = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FORM_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FORM_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FRAMESET_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FRAMESET_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::FRAME_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HEADING = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HEAD_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HEAD_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HREF_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HR_DEPR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HTML_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HTML_CDATA = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HTML_CONTENT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HTML_FLOW = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HTML_INLINE = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::HTML_PCDATA = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::I18N = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::I18N_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::IFRAME_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::IMG_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::INLINE = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::INLINE_P = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::INPUT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::LABEL_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::LABEL_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::LANGUAGE_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::LEGEND_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::LINK_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::LIST = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::LI_ELT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::MAP_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::META_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::MODIFIER = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::NAME_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::NOFRAMES_CONTENT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::OBJECT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::OBJECT_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::OBJECT_DEPR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::OL_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::OPTGROUP_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::OPTION_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::OPTION_ELT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::PARAM_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::PCDATA = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::PHRASE = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::PRE_CONTENT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::PROMPT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::QUOTE_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::ROWS_COLS_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::SCRIPT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::SELECT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::SELECT_CONTENT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::SPECIAL = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::SRC_ALT_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::STYLE_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TABLE_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TABLE_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TABLE_DEPR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TALIGN_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TARGET_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TEXTAREA_ATTRS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TH_TD_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TH_TD_DEPR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TR_CONTENTS = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TR_ELT = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::TYPE_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::UL_DEPR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::VERSION_ATTR = T.let(T.unsafe(nil), Array)
+Nokogiri::HTML4::ElementDescription::WIDTH_ATTR = T.let(T.unsafe(nil), Array)
+class Nokogiri::HTML4::EntityDescription < ::Struct; end
+
+class Nokogiri::HTML4::EntityLookup
def [](name); end
def get(_arg0); end
end
-Nokogiri::HTML::NamedCharacters = T.let(T.unsafe(nil), Nokogiri::HTML::EntityLookup)
-module Nokogiri::HTML::SAX; end
+Nokogiri::HTML4::NamedCharacters = T.let(T.unsafe(nil), Nokogiri::HTML4::EntityLookup)
+module Nokogiri::HTML4::SAX; end
-class Nokogiri::HTML::SAX::Parser < ::Nokogiri::XML::SAX::Parser
+class Nokogiri::HTML4::SAX::Parser < ::Nokogiri::XML::SAX::Parser
def parse_file(filename, encoding = T.unsafe(nil)); end
def parse_io(io, encoding = T.unsafe(nil)); end
def parse_memory(data, encoding = T.unsafe(nil)); end
end
-class Nokogiri::HTML::SAX::ParserContext < ::Nokogiri::XML::SAX::ParserContext
+class Nokogiri::HTML4::SAX::ParserContext < ::Nokogiri::XML::SAX::ParserContext
def parse_with(_arg0); end
class << self
@@ -438,7 +453,7 @@ class Nokogiri::HTML::SAX::ParserContext < ::Nokogiri::XML::SAX::ParserContext
end
end
-class Nokogiri::HTML::SAX::PushParser < ::Nokogiri::XML::SAX::PushParser
+class Nokogiri::HTML4::SAX::PushParser < ::Nokogiri::XML::SAX::PushParser
def initialize(doc = T.unsafe(nil), file_name = T.unsafe(nil), encoding = T.unsafe(nil)); end
def <<(chunk, last_chunk = T.unsafe(nil)); end
@@ -453,12 +468,71 @@ class Nokogiri::HTML::SAX::PushParser < ::Nokogiri::XML::SAX::PushParser
def native_write(_arg0, _arg1); end
end
+module Nokogiri::HTML5
+ class << self
+ def escape_text(text, encoding, attribute_mode); end
+ def fragment(string, encoding = T.unsafe(nil), **options); end
+ def get(uri, options = T.unsafe(nil)); end
+ def get_impl(uri, options = T.unsafe(nil)); end
+ def parse(string, url = T.unsafe(nil), encoding = T.unsafe(nil), **options, &block); end
+ def prepend_newline?(node); end
+ def read_and_encode(string, encoding); end
+ def reencode(body, content_type = T.unsafe(nil)); end
+ def serialize_node_internal(current_node, io, encoding, options); end
+ end
+end
+
+class Nokogiri::HTML5::Document < ::Nokogiri::HTML4::Document
+ def fragment(tags = T.unsafe(nil)); end
+ def to_xml(options = T.unsafe(nil), &block); end
+
+ class << self
+ def do_parse(string_or_io, url, encoding, options); end
+ def parse(string_or_io, url = T.unsafe(nil), encoding = T.unsafe(nil), **options, &block); end
+ def read_io(io, url = T.unsafe(nil), encoding = T.unsafe(nil), **options); end
+ def read_memory(string, url = T.unsafe(nil), encoding = T.unsafe(nil), **options); end
+ end
+end
+
+class Nokogiri::HTML5::DocumentFragment < ::Nokogiri::HTML4::DocumentFragment
+ def initialize(doc, tags = T.unsafe(nil), ctx = T.unsafe(nil), options = T.unsafe(nil)); end
+
+ def document; end
+ def document=(_arg0); end
+ def errors; end
+ def errors=(_arg0); end
+ def extract_params(params); end
+ def serialize(options = T.unsafe(nil), &block); end
+
+ class << self
+ def parse(tags, encoding = T.unsafe(nil), options = T.unsafe(nil)); end
+ end
+end
+
+Nokogiri::HTML5::HTML_NAMESPACE = T.let(T.unsafe(nil), String)
+Nokogiri::HTML5::MATHML_NAMESPACE = T.let(T.unsafe(nil), String)
+
+module Nokogiri::HTML5::Node
+ def fragment(tags); end
+ def inner_html(options = T.unsafe(nil)); end
+ def write_to(io, *options); end
+
+ private
+
+ def add_child_node_and_reparent_attrs(node); end
+end
+
+Nokogiri::HTML5::SVG_NAMESPACE = T.let(T.unsafe(nil), String)
+Nokogiri::HTML5::XLINK_NAMESPACE = T.let(T.unsafe(nil), String)
+Nokogiri::HTML5::XMLNS_NAMESPACE = T.let(T.unsafe(nil), String)
+Nokogiri::HTML5::XML_NAMESPACE = T.let(T.unsafe(nil), String)
Nokogiri::LIBXML2_PATCHES = T.let(T.unsafe(nil), Array)
Nokogiri::LIBXML_COMPILED_VERSION = T.let(T.unsafe(nil), String)
Nokogiri::LIBXML_ICONV_ENABLED = T.let(T.unsafe(nil), TrueClass)
Nokogiri::LIBXML_LOADED_VERSION = T.let(T.unsafe(nil), String)
Nokogiri::LIBXML_MEMORY_MANAGEMENT = T.let(T.unsafe(nil), String)
Nokogiri::LIBXSLT_COMPILED_VERSION = T.let(T.unsafe(nil), String)
+Nokogiri::LIBXSLT_DATETIME_ENABLED = T.let(T.unsafe(nil), TrueClass)
Nokogiri::LIBXSLT_LOADED_VERSION = T.let(T.unsafe(nil), String)
Nokogiri::LIBXSLT_PATCHES = T.let(T.unsafe(nil), Array)
Nokogiri::OTHER_LIBRARY_VERSIONS = T.let(T.unsafe(nil), String)
@@ -488,6 +562,7 @@ class Nokogiri::VersionInfo
def libxml2_precompiled?; end
def libxml2_using_packaged?; end
def libxml2_using_system?; end
+ def libxslt_has_datetime?; end
def loaded_libxml_version; end
def loaded_libxslt_version; end
def ruby_minor; end
@@ -561,6 +636,8 @@ class Nokogiri::XML::Builder
end
end
+Nokogiri::XML::Builder::DEFAULT_DOCUMENT_OPTIONS = T.let(T.unsafe(nil), Hash)
+
class Nokogiri::XML::Builder::NodeBuilder
def initialize(node, doc_builder); end
@@ -624,6 +701,8 @@ class Nokogiri::XML::Document < ::Nokogiri::XML::Node
def errors=(_arg0); end
def fragment(tags = T.unsafe(nil)); end
def name; end
+ def namespace_inheritance; end
+ def namespace_inheritance=(_arg0); end
def namespaces; end
def remove_namespaces!; end
def root; end
@@ -752,6 +831,7 @@ class Nokogiri::XML::Namespace
end
class Nokogiri::XML::Node
+ include ::Nokogiri::HTML5::Node
include ::Nokogiri::XML::PP::Node
include ::Nokogiri::XML::Searchable
include ::Enumerable
@@ -810,12 +890,10 @@ class Nokogiri::XML::Node
def encode_special_chars(_arg0); end
def external_subset; end
def first_element_child; end
- def fragment(tags); end
def fragment?; end
def get_attribute(name); end
def has_attribute?(_arg0); end
def html?; end
- def inner_html(*args); end
def inner_html=(node_or_tags); end
def inner_text; end
def internal_subset; end
@@ -880,7 +958,6 @@ class Nokogiri::XML::Node
def values; end
def wrap(html); end
def write_html_to(io, options = T.unsafe(nil)); end
- def write_to(io, *options); end
def write_xhtml_to(io, options = T.unsafe(nil)); end
def write_xml_to(io, options = T.unsafe(nil)); end
def xml?; end
@@ -892,7 +969,6 @@ class Nokogiri::XML::Node
private
def add_child_node(_arg0); end
- def add_child_node_and_reparent_attrs(node); end
def add_next_sibling_node(_arg0); end
def add_previous_sibling_node(_arg0); end
def add_sibling(next_or_previous, node_or_tags); end
@@ -1065,6 +1141,8 @@ class Nokogiri::XML::ParseOptions
def default_schema?; end
def default_xml; end
def default_xml?; end
+ def default_xslt; end
+ def default_xslt?; end
def dtdattr; end
def dtdattr?; end
def dtdload; end
@@ -1084,6 +1162,7 @@ class Nokogiri::XML::ParseOptions
def nodefault_html; end
def nodefault_schema; end
def nodefault_xml; end
+ def nodefault_xslt; end
def nodict; end
def nodict?; end
def nodtdattr; end
@@ -1138,6 +1217,7 @@ Nokogiri::XML::ParseOptions::COMPACT = T.let(T.unsafe(nil), Integer)
Nokogiri::XML::ParseOptions::DEFAULT_HTML = T.let(T.unsafe(nil), Integer)
Nokogiri::XML::ParseOptions::DEFAULT_SCHEMA = T.let(T.unsafe(nil), Integer)
Nokogiri::XML::ParseOptions::DEFAULT_XML = T.let(T.unsafe(nil), Integer)
+Nokogiri::XML::ParseOptions::DEFAULT_XSLT = T.let(T.unsafe(nil), Integer)
Nokogiri::XML::ParseOptions::DTDATTR = T.let(T.unsafe(nil), Integer)
Nokogiri::XML::ParseOptions::DTDLOAD = T.let(T.unsafe(nil), Integer)
Nokogiri::XML::ParseOptions::DTDVALID = T.let(T.unsafe(nil), Integer) | true |
Other | Homebrew | brew | eb360dbbb054dd047b3c522c88c2c894442d8a5e.json | utils/bottle: fix local JSON handling for bottle rebuilds | Library/Homebrew/utils/bottles.rb | @@ -59,7 +59,7 @@ def resolve_formula_names(bottle_file)
receipt_file = file_from_bottle(bottle_file, receipt_file_path)
tap = Tab.from_file_content(receipt_file, "#{bottle_file}/#{receipt_file_path}").tap
"#{tap}/#{name}" if tap.present? && !tap.core_tap?
- elsif (bottle_json_path = Pathname(bottle_file.sub(/\.tar\.gz$/, ".json"))) &&
+ elsif (bottle_json_path = Pathname(bottle_file.sub(/\.(\d+\.)?tar\.gz$/, ".json"))) &&
bottle_json_path.exist? &&
(bottle_json_path_contents = bottle_json_path.read.presence) &&
(bottle_json = JSON.parse(bottle_json_path_contents).presence) &&
@@ -98,7 +98,7 @@ def path_resolved_basename(root_url, name, checksum, filename)
def load_tab(formula)
keg = Keg.new(formula.prefix)
tabfile = keg/Tab::FILENAME
- bottle_json_path = formula.local_bottle_path&.sub(/\.tar\.gz$/, ".json")
+ bottle_json_path = formula.local_bottle_path&.sub(/\.(\d+\.)?tar\.gz$/, ".json")
if (tab_attributes = formula.bottle_tab_attributes.presence)
Tab.from_file_content(tab_attributes.to_json, tabfile) | false |
Other | Homebrew | brew | ab455d1f38220a358ec67b3bc32d5defa727ae80.json | os/mac/xquartz: fix handling of XQuartz 2.8.0+ | Library/Homebrew/os/mac/xquartz.rb | @@ -11,7 +11,8 @@ module XQuartz
module_function
- DEFAULT_BUNDLE_PATH = Pathname("Applications/Utilities/XQuartz.app").freeze
+ DEFAULT_BUNDLE_PATH = Pathname("/Applications/Utilities/XQuartz.app").freeze
+ NEW_BUNDLE_PKG_ID = "org.xquartz.X11"
FORGE_BUNDLE_ID = "org.macosforge.xquartz.X11"
FORGE_PKG_ID = "org.macosforge.xquartz.pkg"
@@ -73,7 +74,7 @@ def bundle_path
# Ask Spotlight where XQuartz is. If the user didn't install XQuartz
# in the conventional place, this is our only option.
- MacOS.app_with_bundle_id(FORGE_BUNDLE_ID)
+ MacOS.app_with_bundle_id(NEW_BUNDLE_PKG_ID, FORGE_BUNDLE_ID)
end
def version_from_mdls(path)
@@ -86,8 +87,12 @@ def version_from_mdls(path)
# Upstream XQuartz *does* have a pkg-info entry, so if we can't get it
# from mdls, we can try pkgutil. This is very slow.
def version_from_pkgutil
- str = MacOS.pkgutil_info(FORGE_PKG_ID)[/version: (\d\.\d\.\d+)$/, 1]
- PKGINFO_VERSION_MAP.fetch(str, str)
+ [NEW_BUNDLE_PKG_ID, FORGE_PKG_ID].each do |id|
+ str = MacOS.pkgutil_info(id)[/version: (\d\.\d\.\d+)$/, 1]
+ return PKGINFO_VERSION_MAP.fetch(str, str) if str
+ end
+
+ nil
end
def prefix | false |
Other | Homebrew | brew | 3e4cb206bb2bce403df4e72e1eb44cbdbb4d9e80.json | rubocops: silence parser warning | Library/Homebrew/rubocops/all.rb | @@ -6,7 +6,11 @@
require "rubocop-performance"
require "rubocop-rails"
require "rubocop-rspec"
-require "rubocop-sorbet"
+
+require_relative "../warnings"
+Warnings.ignore :parser_syntax do
+ require "rubocop-sorbet"
+end
require_relative "io_read"
require_relative "shell_commands" | true |
Other | Homebrew | brew | 3e4cb206bb2bce403df4e72e1eb44cbdbb4d9e80.json | rubocops: silence parser warning | Library/Homebrew/rubocops/extend/formula.rb | @@ -1,15 +1,6 @@
# typed: false
# frozen_string_literal: true
-# Silence compatibility warning.
-begin
- old_verbosity = $VERBOSE
- $VERBOSE = nil
- require "parser/current"
-ensure
- $VERBOSE = old_verbosity
-end
-
require "extend/string"
require "rubocops/shared/helper_functions"
| true |
Other | Homebrew | brew | 3e4cb206bb2bce403df4e72e1eb44cbdbb4d9e80.json | rubocops: silence parser warning | Library/Homebrew/rubocops/shared/helper_functions.rb | @@ -3,6 +3,11 @@
require "rubocop"
+require_relative "../../warnings"
+Warnings.ignore :parser_syntax do
+ require "parser/current"
+end
+
module RuboCop
module Cop
# Helper functions for cops. | true |
Other | Homebrew | brew | f1e4add444fa7ce4848a9b51c71f7a99d42ec796.json | formula_installer: fix installation of local bottles | Library/Homebrew/formula_installer.rb | @@ -150,6 +150,8 @@ def pour_bottle?(output_warning: false)
return false
end
+ return true if formula.local_bottle_path.present?
+
bottle = formula.bottle_for_tag(Utils::Bottles.tag.to_sym)
return false if bottle.nil?
| false |
Other | Homebrew | brew | 3af7646c5fdf78a5461d9ab334cdf266b15cb735.json | Update RBI files for rubocop-rspec. | Library/Homebrew/sorbet/rbi/gems/rubocop-rspec@2.5.0.rbi | @@ -453,6 +453,23 @@ RuboCop::Cop::RSpec::ExampleWording::MSG_IT = T.let(T.unsafe(nil), String)
RuboCop::Cop::RSpec::ExampleWording::MSG_SHOULD = T.let(T.unsafe(nil), String)
RuboCop::Cop::RSpec::ExampleWording::SHOULD_PREFIX = T.let(T.unsafe(nil), Regexp)
+class RuboCop::Cop::RSpec::ExcessiveDocstringSpacing < ::RuboCop::Cop::RSpec::Base
+ extend ::RuboCop::Cop::AutoCorrector
+
+ def example_description(param0 = T.unsafe(nil)); end
+ def on_send(node); end
+
+ private
+
+ def add_whitespace_offense(node, text); end
+ def docstring(node); end
+ def excessive_whitespace?(text); end
+ def strip_excessive_whitespace(text); end
+ def text(node); end
+end
+
+RuboCop::Cop::RSpec::ExcessiveDocstringSpacing::MSG = T.let(T.unsafe(nil), String)
+
class RuboCop::Cop::RSpec::ExpectActual < ::RuboCop::Cop::RSpec::Base
extend ::RuboCop::Cop::AutoCorrector
@@ -1423,6 +1440,18 @@ end
RuboCop::Cop::RSpec::StubbedMock::MSG = T.let(T.unsafe(nil), String)
+class RuboCop::Cop::RSpec::SubjectDeclaration < ::RuboCop::Cop::RSpec::Base
+ def offensive_subject_declaration?(param0 = T.unsafe(nil)); end
+ def on_send(node); end
+
+ private
+
+ def message_for(offense); end
+end
+
+RuboCop::Cop::RSpec::SubjectDeclaration::MSG_LET = T.let(T.unsafe(nil), String)
+RuboCop::Cop::RSpec::SubjectDeclaration::MSG_REDUNDANT = T.let(T.unsafe(nil), String)
+
class RuboCop::Cop::RSpec::SubjectStub < ::RuboCop::Cop::RSpec::Base
include ::RuboCop::Cop::RSpec::TopLevelGroup
| false |
Other | Homebrew | brew | 16afcff557af2ffaea7f76ea70574f831f7f9ae2.json | formula: fix error in Formula#specified_path with aliases | Library/Homebrew/formula.rb | @@ -310,7 +310,8 @@ def full_installed_alias_name
# The path that was specified to find this formula.
def specified_path
- default_specified_path = alias_path || path
+ default_specified_path = Pathname(alias_path) if alias_path.present?
+ default_specified_path ||= path
return default_specified_path if default_specified_path.presence&.exist?
return local_bottle_path if local_bottle_path.presence&.exist? | true |
Other | Homebrew | brew | 16afcff557af2ffaea7f76ea70574f831f7f9ae2.json | formula: fix error in Formula#specified_path with aliases | Library/Homebrew/test/formula_spec.rb | @@ -28,7 +28,7 @@
let(:path) { Formulary.core_path(name) }
let(:spec) { :stable }
let(:alias_name) { "baz@1" }
- let(:alias_path) { CoreTap.instance.alias_dir/alias_name }
+ let(:alias_path) { (CoreTap.instance.alias_dir/alias_name).to_s }
let(:f) { klass.new(name, path, spec) }
let(:f_alias) { klass.new(name, path, spec, alias_path: alias_path) }
@@ -41,6 +41,7 @@
expect(f.alias_path).to be nil
expect(f.alias_name).to be nil
expect(f.full_alias_name).to be nil
+ expect(f.specified_path).to eq(path)
expect { klass.new }.to raise_error(ArgumentError)
end
@@ -51,6 +52,7 @@
expect(f_alias.alias_path).to eq(alias_path)
expect(f_alias.alias_name).to eq(alias_name)
expect(f_alias.specified_name).to eq(alias_name)
+ expect(f_alias.specified_path).to eq(Pathname(alias_path))
expect(f_alias.full_alias_name).to eq(alias_name)
expect(f_alias.full_specified_name).to eq(alias_name)
expect { klass.new }.to raise_error(ArgumentError)
@@ -71,6 +73,7 @@
expect(f.alias_path).to be nil
expect(f.alias_name).to be nil
expect(f.full_alias_name).to be nil
+ expect(f.specified_path).to eq(path)
expect { klass.new }.to raise_error(ArgumentError)
end
@@ -81,6 +84,7 @@
expect(f_alias.alias_path).to eq(alias_path)
expect(f_alias.alias_name).to eq(alias_name)
expect(f_alias.specified_name).to eq(alias_name)
+ expect(f_alias.specified_path).to eq(Pathname(alias_path))
expect(f_alias.full_alias_name).to eq(full_alias_name)
expect(f_alias.full_specified_name).to eq(full_alias_name)
expect { klass.new }.to raise_error(ArgumentError) | true |
Other | Homebrew | brew | 8dc060c88b360c26571b2549af46a108fc7a9078.json | upgrade: use greedy_* method parameters | Library/Homebrew/cask/cmd/upgrade.rb | @@ -95,8 +95,8 @@ def self.upgrade_casks(
outdated_casks = if casks.empty?
Caskroom.casks(config: Config.from_args(args)).select do |cask|
- cask.outdated?(greedy: greedy, greedy_latest: args.greedy_latest?,
- greedy_auto_updates: args.greedy_auto_updates?)
+ cask.outdated?(greedy: greedy, greedy_latest: greedy_latest,
+ greedy_auto_updates: greedy_auto_updates)
end
else
casks.select do |cask|
@@ -120,14 +120,14 @@ def self.upgrade_casks(
return false if outdated_casks.empty?
if casks.empty? && !greedy
- if !args.greedy_auto_updates? && !args.greedy_latest?
- ohai "Casks with 'auto_updates true' or 'version :latest'
- will not be upgraded; pass `--greedy` to upgrade them."
+ if !greedy_auto_updates && !greedy_latest
+ ohai "Casks with 'auto_updates true' or 'version :latest' " \
+ "will not be upgraded; pass `--greedy` to upgrade them."
end
- if args.greedy_auto_updates? && !args.greedy_latest?
+ if greedy_auto_updates && !greedy_latest
ohai "Casks with 'version :latest' will not be upgraded; pass `--greedy-latest` to upgrade them."
end
- if !args.greedy_auto_updates? && args.greedy_latest?
+ if !greedy_auto_updates && greedy_latest
ohai "Casks with 'auto_updates true' will not be upgraded; pass `--greedy-auto-updates` to upgrade them."
end
end | true |
Other | Homebrew | brew | 8dc060c88b360c26571b2549af46a108fc7a9078.json | upgrade: use greedy_* method parameters | Library/Homebrew/cmd/upgrade.rb | @@ -234,15 +234,17 @@ def upgrade_outdated_casks(casks, args:)
Cask::Cmd::Upgrade.upgrade_casks(
*casks,
- force: args.force?,
- greedy: args.greedy?,
- dry_run: args.dry_run?,
- binaries: args.binaries?,
- quarantine: args.quarantine?,
- require_sha: args.require_sha?,
- skip_cask_deps: args.skip_cask_deps?,
- verbose: args.verbose?,
- args: args,
+ force: args.force?,
+ greedy: args.greedy?,
+ greedy_latest: args.greedy_latest?,
+ greedy_auto_updates: args.greedy_auto_updates?,
+ dry_run: args.dry_run?,
+ binaries: args.binaries?,
+ quarantine: args.quarantine?,
+ require_sha: args.require_sha?,
+ skip_cask_deps: args.skip_cask_deps?,
+ verbose: args.verbose?,
+ args: args,
)
end
end | true |
Other | Homebrew | brew | 59dc0ed6521b98265230ac76e762064cedd25bcb.json | formula_installer: fix error if a compatible bottle was not found | Library/Homebrew/cmd/--cache.rb | @@ -63,7 +63,7 @@ def __cache
sig { params(formula: Formula, args: CLI::Args).void }
def print_formula_cache(formula, args:)
if fetch_bottle?(formula, args: args)
- puts formula.bottle_for_tag(args.bottle_tag).cached_download
+ puts formula.bottle_for_tag(args.bottle_tag&.to_sym).cached_download
elsif args.HEAD?
puts formula.head.cached_download
else | true |
Other | Homebrew | brew | 59dc0ed6521b98265230ac76e762064cedd25bcb.json | formula_installer: fix error if a compatible bottle was not found | Library/Homebrew/cmd/fetch.rb | @@ -93,7 +93,7 @@ def fetch
begin
f.clear_cache if args.force?
f.fetch_bottle_tab
- fetch_formula(f.bottle_for_tag(args.bottle_tag), args: args)
+ fetch_formula(f.bottle_for_tag(args.bottle_tag&.to_sym), args: args)
rescue Interrupt
raise
rescue => e | true |
Other | Homebrew | brew | 59dc0ed6521b98265230ac76e762064cedd25bcb.json | formula_installer: fix error if a compatible bottle was not found | Library/Homebrew/formula.rb | @@ -371,7 +371,7 @@ def bottle
# The Bottle object for given tag.
# @private
- sig { params(tag: T.nilable(String)).returns(T.nilable(Bottle)) }
+ sig { params(tag: T.nilable(Symbol)).returns(T.nilable(Bottle)) }
def bottle_for_tag(tag = nil)
Bottle.new(self, bottle_specification, tag) if bottled?(tag)
end | true |
Other | Homebrew | brew | 59dc0ed6521b98265230ac76e762064cedd25bcb.json | formula_installer: fix error if a compatible bottle was not found | Library/Homebrew/formula_installer.rb | @@ -150,8 +150,10 @@ def pour_bottle?(output_warning: false)
return false
end
- bottle = formula.bottle
- if bottle && !bottle.compatible_locations?
+ bottle = formula.bottle_for_tag(Utils::Bottles.tag.to_sym)
+ return false if bottle.nil?
+
+ unless bottle.compatible_locations?
if output_warning
prefix = Pathname(bottle.cellar).parent
opoo <<~EOS | true |
Other | Homebrew | brew | 946c13cd05b2e9721262c31396730adee8ef44d7.json | Update RBI files for sorbet. | Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi | @@ -9713,6 +9713,11 @@ class UnpackStrategy::Zip
extend ::T::Private::Methods::SingletonMethodHooks
end
+class UnpackStrategy::Zstd
+ extend ::T::Private::Methods::MethodHooks
+ extend ::T::Private::Methods::SingletonMethodHooks
+end
+
module UnpackStrategy
extend ::T::Private::Abstract::Hooks
extend ::T::InterfaceWrapper::Helpers
@@ -9753,6 +9758,11 @@ class Utils::Bottles::Tag
extend ::T::Private::Methods::SingletonMethodHooks
end
+class Utils::Bottles::TagSpecification
+ extend ::T::Private::Methods::MethodHooks
+ extend ::T::Private::Methods::SingletonMethodHooks
+end
+
module Utils::Curl
extend ::T::Private::Methods::MethodHooks
extend ::T::Private::Methods::SingletonMethodHooks | false |
Other | Homebrew | brew | c7badb1e5413052def6fdade669fe6da55689222.json | formula_cellar_checks: fix edge case handling in `check_binary_arches`
Currently, if formula `foo` ships both universal and non-native
binaries and `foo` is on both allowlists, then `brew audit --strict`
errors out with an empty error message:
❯ brew audit --strict foo
foo:
*
Error: 1 problem in 1 formula detected
Let's fix this (admittedly obscure) corner case by returning early when
a formula is present on both allowlists. | Library/Homebrew/formula_cellar_checks.rb | @@ -341,6 +341,8 @@ def check_binary_arches(formula)
mismatches_expected = formula.tap.blank? || tap_audit_exception(:mismatched_binary_allowlist, formula.name)
return if compatible_universal_binaries.empty? && mismatches_expected
+ return if universal_binaries_expected && mismatches_expected
+
s = ""
if mismatches.present? && !mismatches_expected | false |
Other | Homebrew | brew | e224006b4979c78c2966d7c1ef7df9b5f9dbc7d2.json | test/bash_spec: ignore cc script | Library/Homebrew/test/bash_spec.rb | @@ -48,6 +48,7 @@
next if path.directory?
next if path.symlink?
next unless path.executable?
+ next if path.basename.to_s == "cc" # `bash -n` tries to parse the Ruby part
next unless path.read(12) == "#!/bin/bash\n"
expect(path).to have_valid_bash_syntax | false |
Other | Homebrew | brew | d00b387bc244bfaff854f7c728463f6114bbdf14.json | dev-cmd/typecheck: use new tapioca command | Library/Homebrew/dev-cmd/typecheck.rb | @@ -53,7 +53,7 @@ def typecheck
]
ohai "Updating Tapioca RBI files..."
- system "bundle", "exec", "tapioca", "sync", "--exclude", *excluded_gems
+ system "bundle", "exec", "tapioca", "gem", "--exclude", *excluded_gems
system "bundle", "exec", "parlour"
system "bundle", "exec", "srb", "rbi", "hidden-definitions"
system "bundle", "exec", "srb", "rbi", "todo" | false |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | .gitignore | @@ -127,6 +127,7 @@
**/vendor/bundle/ruby/*/gems/pry-*/
**/vendor/bundle/ruby/*/gems/racc-*/
**/vendor/bundle/ruby/*/gems/rainbow-*/
+**/vendor/bundle/ruby/*/gems/rbi-*/
**/vendor/bundle/ruby/*/gems/rdiscount-*/
**/vendor/bundle/ruby/*/gems/regexp_parser-*/
**/vendor/bundle/ruby/*/gems/rexml-*/
@@ -157,6 +158,7 @@
**/vendor/bundle/ruby/*/gems/unf_ext-*/
**/vendor/bundle/ruby/*/gems/unf-*/
**/vendor/bundle/ruby/*/gems/unicode-display_width-*/
+**/vendor/bundle/ruby/*/gems/unparser-*/
**/vendor/bundle/ruby/*/gems/uri_template-*/
**/vendor/bundle/ruby/*/gems/webrobots-*/
| true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi.rb | @@ -1,23 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-require "sorbet-runtime"
-require "stringio"
-
-module RBI
- class Error < StandardError; end
-end
-
-require "rbi/loc"
-require "rbi/model"
-require "rbi/visitor"
-require "rbi/index"
-require "rbi/rewriters/add_sig_templates"
-require "rbi/rewriters/merge_trees"
-require "rbi/rewriters/nest_singleton_methods"
-require "rbi/rewriters/nest_non_public_methods"
-require "rbi/rewriters/group_nodes"
-require "rbi/rewriters/sort_nodes"
-require "rbi/parser"
-require "rbi/printer"
-require "rbi/version" | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/index.rb | @@ -1,186 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- class Index < Visitor
- extend T::Sig
- include T::Enumerable
-
- sig { params(node: Node).returns(Index) }
- def self.index(*node)
- index = Index.new
- index.visit_all(node)
- index
- end
-
- sig { void }
- def initialize
- super()
- @index = T.let({}, T::Hash[String, T::Array[Node]])
- end
-
- sig { returns(T::Array[String]) }
- def keys
- @index.keys
- end
-
- sig { params(id: String).returns(T::Array[Node]) }
- def [](id)
- @index[id] ||= []
- end
-
- sig { params(node: T.all(Indexable, Node)).void }
- def index(node)
- node.index_ids.each { |id| self[id] << node }
- end
-
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- return unless node
-
- case node
- when Scope
- index(node)
- visit_all(node.nodes)
- when Tree
- visit_all(node.nodes)
- when Indexable
- index(node)
- end
- end
- end
-
- class Tree
- extend T::Sig
-
- sig { returns(Index) }
- def index
- Index.index(self)
- end
- end
-
- # A Node that can be refered to by a unique ID inside an index
- module Indexable
- extend T::Sig
- extend T::Helpers
-
- interface!
-
- # Unique IDs that refer to this node.
- #
- # Some nodes can have multiple ids, for example an attribute accessor matches the ID of the
- # getter and the setter.
- sig { abstract.returns(T::Array[String]) }
- def index_ids; end
- end
-
- class Scope
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- [fully_qualified_name]
- end
- end
-
- class Const
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- [fully_qualified_name]
- end
- end
-
- class Attr
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- fully_qualified_names
- end
- end
-
- class Method
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- [fully_qualified_name]
- end
- end
-
- class Include
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- names.map { |name| "#{parent_scope&.fully_qualified_name}.include(#{name})" }
- end
- end
-
- class Extend
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- names.map { |name| "#{parent_scope&.fully_qualified_name}.extend(#{name})" }
- end
- end
-
- class MixesInClassMethods
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- names.map { |name| "#{parent_scope&.fully_qualified_name}.mixes_in_class_method(#{name})" }
- end
- end
-
- class Helper
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- [to_s]
- end
- end
-
- class TStructConst
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- fully_qualified_names
- end
- end
-
- class TStructProp
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- fully_qualified_names
- end
- end
-
- class TEnumBlock
- extend T::Sig
- include Indexable
-
- sig { override.returns(T::Array[String]) }
- def index_ids
- [to_s]
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/loc.rb | @@ -1,36 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- class Loc
- extend T::Sig
-
- sig { returns(T.nilable(String)) }
- attr_reader :file
-
- sig { returns(T.nilable(Integer)) }
- attr_reader :begin_line, :end_line, :begin_column, :end_column
-
- sig do
- params(
- file: T.nilable(String),
- begin_line: T.nilable(Integer),
- end_line: T.nilable(Integer),
- begin_column: T.nilable(Integer),
- end_column: T.nilable(Integer)
- ).void
- end
- def initialize(file: nil, begin_line: nil, end_line: nil, begin_column: nil, end_column: nil)
- @file = file
- @begin_line = begin_line
- @end_line = end_line
- @begin_column = begin_column
- @end_column = end_column
- end
-
- sig { returns(String) }
- def to_s
- "#{file}:#{begin_line}:#{begin_column}-#{end_line}:#{end_column}"
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/model.rb | @@ -1,1251 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- class Node
- extend T::Sig
- extend T::Helpers
-
- abstract!
-
- sig { returns(T.nilable(Tree)) }
- attr_accessor :parent_tree
-
- sig { returns(T.nilable(Loc)) }
- attr_accessor :loc
-
- sig { params(loc: T.nilable(Loc)).void }
- def initialize(loc: nil)
- @parent_tree = nil
- @loc = loc
- end
-
- sig { void }
- def detach
- tree = parent_tree
- return unless tree
- tree.nodes.delete(self)
- self.parent_tree = nil
- end
-
- sig { params(node: Node).void }
- def replace(node)
- tree = parent_tree
- raise unless tree
- index = tree.nodes.index(self)
- raise unless index
- tree.nodes[index] = node
- node.parent_tree = tree
- self.parent_tree = nil
- end
-
- sig { returns(T.nilable(Scope)) }
- def parent_scope
- parent = T.let(parent_tree, T.nilable(Tree))
- parent = parent.parent_tree until parent.is_a?(Scope) || parent.nil?
- parent
- end
- end
-
- class Comment < Node
- extend T::Sig
-
- sig { returns(String) }
- attr_accessor :text
-
- sig { params(text: String, loc: T.nilable(Loc)).void }
- def initialize(text, loc: nil)
- super(loc: loc)
- @text = text
- end
-
- sig { params(other: Object).returns(T::Boolean) }
- def ==(other)
- return false unless other.is_a?(Comment)
- text == other.text
- end
- end
-
- class EmptyComment < Comment
- extend T::Sig
-
- sig { params(loc: T.nilable(Loc)).void }
- def initialize(loc: nil)
- super("", loc: loc)
- end
- end
-
- class NodeWithComments < Node
- extend T::Sig
- extend T::Helpers
-
- abstract!
-
- sig { returns(T::Array[Comment]) }
- attr_accessor :comments
-
- sig { params(loc: T.nilable(Loc), comments: T::Array[Comment]).void }
- def initialize(loc: nil, comments: [])
- super(loc: loc)
- @comments = comments
- end
- end
-
- class Tree < NodeWithComments
- extend T::Sig
-
- sig { returns(T::Array[Node]) }
- attr_reader :nodes
-
- sig do
- params(
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Tree).void)
- ).void
- end
- def initialize(loc: nil, comments: [], &block)
- super(loc: loc, comments: comments)
- @nodes = T.let([], T::Array[Node])
- block&.call(self)
- end
-
- sig { params(node: Node).void }
- def <<(node)
- node.parent_tree = self
- @nodes << node
- end
-
- sig { returns(T::Boolean) }
- def empty?
- nodes.empty?
- end
- end
-
- class File
- extend T::Sig
-
- sig { returns(Tree) }
- attr_reader :root
-
- sig { returns(T.nilable(String)) }
- attr_reader :strictness
-
- sig { returns(T::Array[Comment]) }
- attr_accessor :comments
-
- sig do
- params(
- strictness: T.nilable(String),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(file: File).void)
- ).void
- end
- def initialize(strictness: nil, comments: [], &block)
- @root = T.let(Tree.new, Tree)
- @strictness = strictness
- @comments = comments
- block&.call(self)
- end
-
- sig { params(node: Node).void }
- def <<(node)
- @root << node
- end
- end
-
- # Scopes
-
- class Scope < Tree
- extend T::Helpers
-
- abstract!
-
- sig { abstract.returns(String) }
- def fully_qualified_name; end
-
- sig { override.returns(String) }
- def to_s
- fully_qualified_name
- end
- end
-
- class Module < Scope
- extend T::Sig
-
- sig { returns(String) }
- attr_accessor :name
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Module).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(loc: loc, comments: comments) {}
- @name = name
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def fully_qualified_name
- return name if name.start_with?("::")
- "#{parent_scope&.fully_qualified_name}::#{name}"
- end
- end
-
- class Class < Scope
- extend T::Sig
-
- sig { returns(String) }
- attr_accessor :name
-
- sig { returns(T.nilable(String)) }
- attr_accessor :superclass_name
-
- sig do
- params(
- name: String,
- superclass_name: T.nilable(String),
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Class).void)
- ).void
- end
- def initialize(name, superclass_name: nil, loc: nil, comments: [], &block)
- super(loc: loc, comments: comments) {}
- @name = name
- @superclass_name = superclass_name
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def fully_qualified_name
- return name if name.start_with?("::")
- "#{parent_scope&.fully_qualified_name}::#{name}"
- end
- end
-
- class SingletonClass < Scope
- extend T::Sig
-
- sig do
- params(
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: SingletonClass).void)
- ).void
- end
- def initialize(loc: nil, comments: [], &block)
- super(loc: loc, comments: comments) {}
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def fully_qualified_name
- "#{parent_scope&.fully_qualified_name}::<self>"
- end
- end
-
- class Struct < Scope
- extend T::Sig
-
- sig { returns(String) }
- attr_accessor :name
-
- sig { returns(T::Array[Symbol]) }
- attr_accessor :members
-
- sig { returns(T::Boolean) }
- attr_accessor :keyword_init
-
- sig do
- params(
- name: String,
- members: T::Array[Symbol],
- keyword_init: T::Boolean,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(struct: Struct).void)
- ).void
- end
- def initialize(name, members: [], keyword_init: false, loc: nil, comments: [], &block)
- super(loc: loc, comments: comments) {}
- @name = name
- @members = members
- @keyword_init = keyword_init
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def fully_qualified_name
- return name if name.start_with?("::")
- "#{parent_scope&.fully_qualified_name}::#{name}"
- end
- end
-
- # Consts
-
- class Const < NodeWithComments
- extend T::Sig
-
- sig { returns(String) }
- attr_reader :name, :value
-
- sig do
- params(
- name: String,
- value: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Const).void)
- ).void
- end
- def initialize(name, value, loc: nil, comments: [], &block)
- super(loc: loc, comments: comments)
- @name = name
- @value = value
- block&.call(self)
- end
-
- sig { returns(String) }
- def fully_qualified_name
- return name if name.start_with?("::")
- "#{parent_scope&.fully_qualified_name}::#{name}"
- end
-
- sig { override.returns(String) }
- def to_s
- fully_qualified_name
- end
- end
-
- # Attributes
-
- class Attr < NodeWithComments
- extend T::Sig
- extend T::Helpers
-
- abstract!
-
- sig { returns(T::Array[Symbol]) }
- attr_accessor :names
-
- sig { returns(Visibility) }
- attr_accessor :visibility
-
- sig { returns(T::Array[Sig]) }
- attr_reader :sigs
-
- sig do
- params(
- name: Symbol,
- names: T::Array[Symbol],
- visibility: Visibility,
- sigs: T::Array[Sig],
- loc: T.nilable(Loc),
- comments: T::Array[Comment]
- ).void
- end
- def initialize(name, names, visibility: Public.new, sigs: [], loc: nil, comments: [])
- super(loc: loc, comments: comments)
- @names = T.let([name, *names], T::Array[Symbol])
- @visibility = visibility
- @sigs = sigs
- end
-
- sig { abstract.returns(T::Array[String]) }
- def fully_qualified_names; end
- end
-
- class AttrAccessor < Attr
- extend T::Sig
-
- sig do
- params(
- name: Symbol,
- names: Symbol,
- visibility: Visibility,
- sigs: T::Array[Sig],
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: AttrAccessor).void)
- ).void
- end
- def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
- super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(T::Array[String]) }
- def fully_qualified_names
- parent_name = parent_scope&.fully_qualified_name
- names.flat_map { |name| ["#{parent_name}##{name}", "#{parent_name}##{name}="] }
- end
-
- sig { override.returns(String) }
- def to_s
- symbols = names.map { |name| ":#{name}" }.join(", ")
- "#{parent_scope&.fully_qualified_name}.attr_accessor(#{symbols})"
- end
- end
-
- class AttrReader < Attr
- extend T::Sig
-
- sig do
- params(
- name: Symbol,
- names: Symbol,
- visibility: Visibility,
- sigs: T::Array[Sig],
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: AttrReader).void)
- ).void
- end
- def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
- super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(T::Array[String]) }
- def fully_qualified_names
- parent_name = parent_scope&.fully_qualified_name
- names.map { |name| "#{parent_name}##{name}" }
- end
-
- sig { override.returns(String) }
- def to_s
- symbols = names.map { |name| ":#{name}" }.join(", ")
- "#{parent_scope&.fully_qualified_name}.attr_reader(#{symbols})"
- end
- end
-
- class AttrWriter < Attr
- extend T::Sig
-
- sig do
- params(
- name: Symbol,
- names: Symbol,
- visibility: Visibility,
- sigs: T::Array[Sig],
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: AttrWriter).void)
- ).void
- end
- def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
- super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(T::Array[String]) }
- def fully_qualified_names
- parent_name = parent_scope&.fully_qualified_name
- names.map { |name| "#{parent_name}##{name}=" }
- end
-
- sig { override.returns(String) }
- def to_s
- symbols = names.map { |name| ":#{name}" }.join(", ")
- "#{parent_scope&.fully_qualified_name}.attr_writer(#{symbols})"
- end
- end
-
- # Methods and args
-
- class Method < NodeWithComments
- extend T::Sig
-
- sig { returns(String) }
- attr_accessor :name
-
- sig { returns(T::Array[Param]) }
- attr_reader :params
-
- sig { returns(T::Boolean) }
- attr_accessor :is_singleton
-
- sig { returns(Visibility) }
- attr_accessor :visibility
-
- sig { returns(T::Array[Sig]) }
- attr_accessor :sigs
-
- sig do
- params(
- name: String,
- params: T::Array[Param],
- is_singleton: T::Boolean,
- visibility: Visibility,
- sigs: T::Array[Sig],
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Method).void)
- ).void
- end
- def initialize(
- name,
- params: [],
- is_singleton: false,
- visibility: Public.new,
- sigs: [],
- loc: nil,
- comments: [],
- &block
- )
- super(loc: loc, comments: comments)
- @name = name
- @params = params
- @is_singleton = is_singleton
- @visibility = visibility
- @sigs = sigs
- block&.call(self)
- end
-
- sig { params(param: Param).void }
- def <<(param)
- @params << param
- end
-
- sig { returns(String) }
- def fully_qualified_name
- if is_singleton
- "#{parent_scope&.fully_qualified_name}::#{name}"
- else
- "#{parent_scope&.fully_qualified_name}##{name}"
- end
- end
-
- sig { override.returns(String) }
- def to_s
- "#{fully_qualified_name}(#{params.join(", ")})"
- end
- end
-
- class Param < NodeWithComments
- extend T::Helpers
- extend T::Sig
-
- abstract!
-
- sig { returns(String) }
- attr_reader :name
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- ).void
- end
- def initialize(name, loc: nil, comments: [])
- super(loc: loc, comments: comments)
- @name = name
- end
-
- sig { override.returns(String) }
- def to_s
- name
- end
- end
-
- class ReqParam < Param
- extend T::Sig
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: ReqParam).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(name, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { params(other: T.nilable(Object)).returns(T::Boolean) }
- def ==(other)
- ReqParam === other && name == other.name
- end
- end
-
- class OptParam < Param
- extend T::Sig
-
- sig { returns(String) }
- attr_reader :value
-
- sig do
- params(
- name: String,
- value: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: OptParam).void)
- ).void
- end
- def initialize(name, value, loc: nil, comments: [], &block)
- super(name, loc: loc, comments: comments)
- @value = value
- block&.call(self)
- end
-
- sig { params(other: T.nilable(Object)).returns(T::Boolean) }
- def ==(other)
- OptParam === other && name == other.name && value == other.value
- end
- end
-
- class RestParam < Param
- extend T::Sig
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: RestParam).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(name, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "*#{name}"
- end
-
- sig { params(other: T.nilable(Object)).returns(T::Boolean) }
- def ==(other)
- RestParam === other && name == other.name
- end
- end
-
- class KwParam < Param
- extend T::Sig
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: KwParam).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(name, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "#{name}:"
- end
-
- sig { params(other: T.nilable(Object)).returns(T::Boolean) }
- def ==(other)
- KwParam === other && name == other.name
- end
- end
-
- class KwOptParam < Param
- extend T::Sig
-
- sig { returns(String) }
- attr_reader :value
-
- sig do
- params(
- name: String,
- value: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: KwOptParam).void)
- ).void
- end
- def initialize(name, value, loc: nil, comments: [], &block)
- super(name, loc: loc, comments: comments)
- @value = value
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "#{name}:"
- end
-
- sig { params(other: T.nilable(Object)).returns(T::Boolean) }
- def ==(other)
- KwOptParam === other && name == other.name && value == other.value
- end
- end
-
- class KwRestParam < Param
- extend T::Sig
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: KwRestParam).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(name, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "**#{name}:"
- end
-
- sig { params(other: T.nilable(Object)).returns(T::Boolean) }
- def ==(other)
- KwRestParam === other && name == other.name
- end
- end
-
- class BlockParam < Param
- extend T::Sig
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: BlockParam).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(name, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "&#{name}"
- end
-
- sig { params(other: T.nilable(Object)).returns(T::Boolean) }
- def ==(other)
- BlockParam === other && name == other.name
- end
- end
-
- # Mixins
-
- class Mixin < NodeWithComments
- extend T::Sig
- extend T::Helpers
-
- abstract!
-
- sig { returns(T::Array[String]) }
- attr_accessor :names
-
- sig do
- params(
- name: String,
- names: T::Array[String],
- loc: T.nilable(Loc),
- comments: T::Array[Comment]
- ).void
- end
- def initialize(name, names, loc: nil, comments: [])
- super(loc: loc, comments: comments)
- @names = T.let([name, *names], T::Array[String])
- end
- end
-
- class Include < Mixin
- extend T::Sig
-
- sig do
- params(
- name: String,
- names: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Include).void)
- ).void
- end
- def initialize(name, *names, loc: nil, comments: [], &block)
- super(name, names, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "#{parent_scope&.fully_qualified_name}.include(#{names.join(", ")})"
- end
- end
-
- class Extend < Mixin
- extend T::Sig
-
- sig do
- params(
- name: String,
- names: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Extend).void)
- ).void
- end
- def initialize(name, *names, loc: nil, comments: [], &block)
- super(name, names, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "#{parent_scope&.fully_qualified_name}.extend(#{names.join(", ")})"
- end
- end
-
- # Visibility
-
- class Visibility < NodeWithComments
- extend T::Sig
- extend T::Helpers
-
- abstract!
-
- sig { returns(Symbol) }
- attr_reader :visibility
-
- sig { params(visibility: Symbol, loc: T.nilable(Loc), comments: T::Array[Comment]).void }
- def initialize(visibility, loc: nil, comments: [])
- super(loc: loc, comments: comments)
- @visibility = visibility
- end
-
- sig { params(other: Visibility).returns(T::Boolean) }
- def ==(other)
- visibility == other.visibility
- end
-
- sig { returns(T::Boolean) }
- def public?
- visibility == :public
- end
-
- sig { returns(T::Boolean) }
- def protected?
- visibility == :protected
- end
-
- sig { returns(T::Boolean) }
- def private?
- visibility == :private
- end
- end
-
- class Public < Visibility
- extend T::Sig
-
- sig do
- params(
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Public).void)
- ).void
- end
- def initialize(loc: nil, comments: [], &block)
- super(:public, loc: loc, comments: comments)
- block&.call(self)
- end
- end
-
- class Protected < Visibility
- extend T::Sig
-
- sig do
- params(
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Protected).void)
- ).void
- end
- def initialize(loc: nil, comments: [], &block)
- super(:protected, loc: loc, comments: comments)
- block&.call(self)
- end
- end
-
- class Private < Visibility
- extend T::Sig
-
- sig do
- params(
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Private).void)
- ).void
- end
- def initialize(loc: nil, comments: [], &block)
- super(:private, loc: loc, comments: comments)
- block&.call(self)
- end
- end
-
- # Sorbet's sigs
-
- class Sig < Node
- extend T::Sig
-
- sig { returns(T::Array[SigParam]) }
- attr_reader :params
-
- sig { returns(T.nilable(String)) }
- attr_accessor :return_type
-
- sig { returns(T::Boolean) }
- attr_accessor :is_abstract, :is_override, :is_overridable
-
- sig { returns(T::Array[String]) }
- attr_reader :type_params
-
- sig { returns(T.nilable(Symbol)) }
- attr_accessor :checked
-
- sig do
- params(
- params: T::Array[SigParam],
- return_type: T.nilable(String),
- is_abstract: T::Boolean,
- is_override: T::Boolean,
- is_overridable: T::Boolean,
- type_params: T::Array[String],
- checked: T.nilable(Symbol),
- loc: T.nilable(Loc),
- block: T.nilable(T.proc.params(node: Sig).void)
- ).void
- end
- def initialize(
- params: [],
- return_type: nil,
- is_abstract: false,
- is_override: false,
- is_overridable: false,
- type_params: [],
- checked: nil,
- loc: nil,
- &block
- )
- super(loc: loc)
- @params = params
- @return_type = return_type
- @is_abstract = is_abstract
- @is_override = is_override
- @is_overridable = is_overridable
- @type_params = type_params
- @checked = checked
- block&.call(self)
- end
-
- sig { params(param: SigParam).void }
- def <<(param)
- @params << param
- end
-
- sig { params(other: Object).returns(T::Boolean) }
- def ==(other)
- return false unless other.is_a?(Sig)
- params == other.params && return_type == other.return_type && is_abstract == other.is_abstract &&
- is_override == other.is_override && is_overridable == other.is_overridable &&
- type_params == other.type_params && checked == other.checked
- end
- end
-
- class SigParam < NodeWithComments
- extend T::Sig
-
- sig { returns(String) }
- attr_reader :name, :type
-
- sig do
- params(
- name: String,
- type: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: SigParam).void)
- ).void
- end
- def initialize(name, type, loc: nil, comments: [], &block)
- super(loc: loc, comments: comments)
- @name = name
- @type = type
- block&.call(self)
- end
-
- sig { params(other: Object).returns(T::Boolean) }
- def ==(other)
- other.is_a?(SigParam) && name == other.name && type == other.type
- end
- end
-
- # Sorbet's T::Struct
-
- class TStruct < Class
- extend T::Sig
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(klass: TStruct).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(name, superclass_name: "::T::Struct", loc: loc, comments: comments) {}
- block&.call(self)
- end
- end
-
- class TStructField < NodeWithComments
- extend T::Sig
- extend T::Helpers
-
- abstract!
-
- sig { returns(String) }
- attr_accessor :name, :type
-
- sig { returns(T.nilable(String)) }
- attr_accessor :default
-
- sig do
- params(
- name: String,
- type: String,
- default: T.nilable(String),
- loc: T.nilable(Loc),
- comments: T::Array[Comment]
- ).void
- end
- def initialize(name, type, default: nil, loc: nil, comments: [])
- super(loc: loc, comments: comments)
- @name = name
- @type = type
- @default = default
- end
-
- sig { abstract.returns(T::Array[String]) }
- def fully_qualified_names; end
- end
-
- class TStructConst < TStructField
- extend T::Sig
-
- sig do
- params(
- name: String,
- type: String,
- default: T.nilable(String),
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: TStructConst).void)
- ).void
- end
- def initialize(name, type, default: nil, loc: nil, comments: [], &block)
- super(name, type, default: default, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(T::Array[String]) }
- def fully_qualified_names
- parent_name = parent_scope&.fully_qualified_name
- ["#{parent_name}##{name}"]
- end
-
- sig { override.returns(String) }
- def to_s
- "#{parent_scope&.fully_qualified_name}.const(:#{name})"
- end
- end
-
- class TStructProp < TStructField
- extend T::Sig
-
- sig do
- params(
- name: String,
- type: String,
- default: T.nilable(String),
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: TStructProp).void)
- ).void
- end
- def initialize(name, type, default: nil, loc: nil, comments: [], &block)
- super(name, type, default: default, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(T::Array[String]) }
- def fully_qualified_names
- parent_name = parent_scope&.fully_qualified_name
- ["#{parent_name}##{name}", "#{parent_name}##{name}="]
- end
-
- sig { override.returns(String) }
- def to_s
- "#{parent_scope&.fully_qualified_name}.prop(:#{name})"
- end
- end
-
- # Sorbet's T::Enum
-
- class TEnum < Class
- extend T::Sig
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(klass: TEnum).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(name, superclass_name: "::T::Enum", loc: loc, comments: comments) {}
- block&.call(self)
- end
- end
-
- class TEnumBlock < NodeWithComments
- extend T::Sig
-
- sig { returns(T::Array[String]) }
- attr_reader :names
-
- sig do
- params(
- names: T::Array[String],
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: TEnumBlock).void)
- ).void
- end
- def initialize(names = [], loc: nil, comments: [], &block)
- super(loc: loc, comments: comments)
- @names = names
- block&.call(self)
- end
-
- sig { returns(T::Boolean) }
- def empty?
- names.empty?
- end
-
- sig { params(name: String).void }
- def <<(name)
- @names << name
- end
-
- sig { override.returns(String) }
- def to_s
- "#{parent_scope&.fully_qualified_name}.enums"
- end
- end
-
- # Sorbet's misc.
-
- class Helper < NodeWithComments
- extend T::Helpers
-
- sig { returns(String) }
- attr_reader :name
-
- sig do
- params(
- name: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: Helper).void)
- ).void
- end
- def initialize(name, loc: nil, comments: [], &block)
- super(loc: loc, comments: comments)
- @name = name
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "#{parent_scope&.fully_qualified_name}.#{name}!"
- end
- end
-
- class TypeMember < NodeWithComments
- extend T::Sig
-
- sig { returns(String) }
- attr_reader :name, :value
-
- sig do
- params(
- name: String,
- value: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: TypeMember).void)
- ).void
- end
- def initialize(name, value, loc: nil, comments: [], &block)
- super(loc: loc, comments: comments)
- @name = name
- @value = value
- block&.call(self)
- end
-
- sig { returns(String) }
- def fully_qualified_name
- return name if name.start_with?("::")
- "#{parent_scope&.fully_qualified_name}::#{name}"
- end
-
- sig { override.returns(String) }
- def to_s
- fully_qualified_name
- end
- end
-
- class MixesInClassMethods < Mixin
- extend T::Sig
-
- sig do
- params(
- name: String,
- names: String,
- loc: T.nilable(Loc),
- comments: T::Array[Comment],
- block: T.nilable(T.proc.params(node: MixesInClassMethods).void)
- ).void
- end
- def initialize(name, *names, loc: nil, comments: [], &block)
- super(name, names, loc: loc, comments: comments)
- block&.call(self)
- end
-
- sig { override.returns(String) }
- def to_s
- "#{parent_scope&.fully_qualified_name}.mixes_in_class_methods(#{names.join(", ")})"
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/parser.rb | @@ -1,562 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-require "unparser"
-
-module RBI
- class ParseError < StandardError
- extend T::Sig
-
- sig { returns(Loc) }
- attr_reader :location
-
- sig { params(message: String, location: Loc).void }
- def initialize(message, location)
- super(message)
- @location = location
- end
- end
-
- class Parser
- extend T::Sig
-
- # opt-in to most recent AST format
- ::Parser::Builders::Default.emit_lambda = true
- ::Parser::Builders::Default.emit_procarg0 = true
- ::Parser::Builders::Default.emit_encoding = true
- ::Parser::Builders::Default.emit_index = true
- ::Parser::Builders::Default.emit_arg_inside_procarg0 = true
-
- sig { params(string: String).returns(Tree) }
- def self.parse_string(string)
- Parser.new.parse_string(string)
- end
-
- sig { params(path: String).returns(Tree) }
- def self.parse_file(path)
- Parser.new.parse_file(path)
- end
-
- sig { params(string: String).returns(Tree) }
- def parse_string(string)
- parse(string, file: "-")
- end
-
- sig { params(path: String).returns(Tree) }
- def parse_file(path)
- parse(::File.read(path), file: path)
- end
-
- private
-
- sig { params(content: String, file: String).returns(Tree) }
- def parse(content, file:)
- node, comments = Unparser.parse_with_comments(content)
- assoc = ::Parser::Source::Comment.associate_locations(node, comments)
- builder = TreeBuilder.new(file: file, comments: assoc)
- builder.separate_header_comments
- builder.visit(node)
- builder.assoc_dangling_comments(comments)
- builder.tree
- rescue ::Parser::SyntaxError => e
- raise ParseError.new(e.message, Loc.from_ast_loc(file, e.diagnostic.location))
- end
- end
-
- class ASTVisitor
- extend T::Helpers
- extend T::Sig
-
- abstract!
-
- sig { params(nodes: T::Array[AST::Node]).void }
- def visit_all(nodes)
- nodes.each { |node| visit(node) }
- end
-
- sig { abstract.params(node: T.nilable(AST::Node)).void }
- def visit(node); end
-
- private
-
- sig { params(node: AST::Node).returns(String) }
- def parse_name(node)
- T.must(ConstBuilder.visit(node))
- end
-
- sig { params(node: AST::Node).returns(String) }
- def parse_expr(node)
- Unparser.unparse(node)
- end
- end
-
- class TreeBuilder < ASTVisitor
- extend T::Sig
-
- sig { returns(Tree) }
- attr_reader :tree
-
- sig do
- params(
- file: String,
- comments: T::Hash[::Parser::Source::Map, T::Array[::Parser::Source::Comment]]
- ).void
- end
- def initialize(file:, comments: {})
- super()
- @file = file
- @comments = comments
- @tree = T.let(Tree.new, Tree)
- @scopes_stack = T.let([@tree], T::Array[Tree])
- @last_sigs = T.let([], T::Array[RBI::Sig])
- end
-
- sig { override.params(node: T.nilable(Object)).void }
- def visit(node)
- return unless node.is_a?(AST::Node)
- case node.type
- when :module, :class, :sclass
- scope = parse_scope(node)
- current_scope << scope
- @scopes_stack << scope
- visit_all(node.children)
- @scopes_stack.pop
- when :casgn
- current_scope << parse_const_assign(node)
- when :def, :defs
- current_scope << parse_def(node)
- when :send
- node = parse_send(node)
- current_scope << node if node
- when :block
- node = parse_block(node)
- if node.is_a?(Sig)
- @last_sigs << node
- elsif node
- current_scope << node
- end
- else
- visit_all(node.children)
- end
- end
-
- sig { void }
- def separate_header_comments
- return if @comments.empty?
-
- keep = []
- node = T.must(@comments.keys.first)
- comments = T.must(@comments.values.first)
-
- last_line = T.let(nil, T.nilable(Integer))
- comments.reverse.each do |comment|
- comment_line = comment.location.last_line
-
- break if last_line && comment_line < last_line - 1 ||
- !last_line && comment_line < node.first_line - 1
-
- keep << comment
- last_line = comment_line
- end
-
- @comments[node] = keep.reverse
- end
-
- sig { params(comments: T::Array[::Parser::Source::Comment]).void }
- def assoc_dangling_comments(comments)
- last_line = T.let(nil, T.nilable(Integer))
- (comments - @comments.values.flatten).each do |comment|
- comment_line = comment.location.last_line
- text = comment.text[1..-1].strip
- loc = Loc.from_ast_loc(@file, comment.location)
-
- if last_line && comment_line > last_line + 1
- # Preserve empty lines in file headers
- tree.comments << EmptyComment.new(loc: loc)
- end
-
- tree.comments << Comment.new(text, loc: loc)
- last_line = comment_line
- end
- end
-
- private
-
- sig { params(node: AST::Node).returns(Scope) }
- def parse_scope(node)
- loc = node_loc(node)
- comments = node_comments(node)
-
- case node.type
- when :module
- name = parse_name(node.children[0])
- Module.new(name, loc: loc, comments: comments)
- when :class
- name = parse_name(node.children[0])
- superclass_name = ConstBuilder.visit(node.children[1])
- Class.new(name, superclass_name: superclass_name, loc: loc, comments: comments)
- when :sclass
- SingletonClass.new(loc: loc, comments: comments)
- else
- raise ParseError.new("Unsupported scope node type `#{node.type}`", loc)
- end
- end
-
- sig { params(node: AST::Node).returns(RBI::Node) }
- def parse_const_assign(node)
- node_value = node.children[2]
- if struct_definition?(node_value)
- parse_struct(node)
- else
- name = parse_name(node)
- value = parse_expr(node_value)
- loc = node_loc(node)
- comments = node_comments(node)
- Const.new(name, value, loc: loc, comments: comments)
- end
- end
-
- sig { params(node: AST::Node).returns(Method) }
- def parse_def(node)
- loc = node_loc(node)
-
- case node.type
- when :def
- Method.new(
- node.children[0].to_s,
- params: node.children[1].children.map { |child| parse_param(child) },
- sigs: current_sigs,
- loc: loc,
- comments: node_comments(node)
- )
- when :defs
- Method.new(
- node.children[1].to_s,
- params: node.children[2].children.map { |child| parse_param(child) },
- is_singleton: true,
- sigs: current_sigs,
- loc: loc,
- comments: node_comments(node)
- )
- else
- raise ParseError.new("Unsupported def node type `#{node.type}`", loc)
- end
- end
-
- sig { params(node: AST::Node).returns(Param) }
- def parse_param(node)
- name = node.children[0].to_s
- loc = node_loc(node)
- comments = node_comments(node)
-
- case node.type
- when :arg
- ReqParam.new(name, loc: loc, comments: comments)
- when :optarg
- value = parse_expr(node.children[1])
- OptParam.new(name, value, loc: loc, comments: comments)
- when :restarg
- RestParam.new(name, loc: loc, comments: comments)
- when :kwarg
- KwParam.new(name, loc: loc, comments: comments)
- when :kwoptarg
- value = parse_expr(node.children[1])
- KwOptParam.new(name, value, loc: loc, comments: comments)
- when :kwrestarg
- KwRestParam.new(name, loc: loc, comments: comments)
- when :blockarg
- BlockParam.new(name, loc: loc, comments: comments)
- else
- raise ParseError.new("Unsupported param node type `#{node.type}`", loc)
- end
- end
-
- sig { params(node: AST::Node).returns(T.nilable(RBI::Node)) }
- def parse_send(node)
- recv = node.children[0]
- return nil if recv && recv != :self
-
- method_name = node.children[1]
- loc = node_loc(node)
- comments = node_comments(node)
-
- case method_name
- when :attr_reader
- symbols = node.children[2..-1].map { |child| child.children[0] }
- AttrReader.new(*symbols, sigs: current_sigs, loc: loc, comments: comments)
- when :attr_writer
- symbols = node.children[2..-1].map { |child| child.children[0] }
- AttrWriter.new(*symbols, sigs: current_sigs, loc: loc, comments: comments)
- when :attr_accessor
- symbols = node.children[2..-1].map { |child| child.children[0] }
- AttrAccessor.new(*symbols, sigs: current_sigs, loc: loc, comments: comments)
- when :include
- names = node.children[2..-1].map { |child| parse_name(child) }
- Include.new(*names, loc: loc, comments: comments)
- when :extend
- names = node.children[2..-1].map { |child| parse_name(child) }
- Extend.new(*names, loc: loc, comments: comments)
- when :abstract!, :sealed!, :interface!
- Helper.new(method_name.to_s.delete_suffix("!"), loc: loc, comments: comments)
- when :mixes_in_class_methods
- names = node.children[2..-1].map { |child| parse_name(child) }
- MixesInClassMethods.new(*names, loc: loc, comments: comments)
- when :public, :protected, :private
- visibility = Visibility.new(method_name, loc: loc)
- nested_node = node.children[2]
- case nested_node&.type
- when :def, :defs
- method = parse_def(nested_node)
- method.visibility = visibility
- method
- when :send
- snode = parse_send(nested_node)
- raise ParseError.new("Unexpected token `private` before `#{nested_node.type}`", loc) unless snode.is_a?(Attr)
- snode.visibility = visibility
- snode
- when nil
- visibility
- else
- raise ParseError.new("Unexpected token `private` before `#{nested_node.type}`", loc)
- end
- when :prop
- name, type, default_value = parse_tstruct_prop(node)
- TStructProp.new(name, type, default: default_value, loc: loc, comments: comments)
- when :const
- name, type, default_value = parse_tstruct_prop(node)
- TStructConst.new(name, type, default: default_value, loc: loc, comments: comments)
- else
- raise ParseError.new("Unsupported send node with name `#{method_name}`", loc)
- end
- end
-
- sig { params(node: AST::Node).returns(T.nilable(RBI::Node)) }
- def parse_block(node)
- name = node.children[0].children[1]
-
- case name
- when :sig
- parse_sig(node)
- when :enums
- parse_enum(node)
- else
- raise ParseError.new("Unsupported block node type `#{name}`", node_loc(node))
- end
- end
-
- sig { params(node: AST::Node).returns(T::Boolean) }
- def struct_definition?(node)
- (node.type == :send && node.children[0]&.type == :const && node.children[0].children[1] == :Struct) ||
- (node.type == :block && struct_definition?(node.children[0]))
- end
-
- sig { params(node: AST::Node).returns(RBI::Struct) }
- def parse_struct(node)
- name = parse_name(node)
- loc = node_loc(node)
- comments = node_comments(node)
-
- send = node.children[2]
- body = []
-
- if send.type == :block
- if send.children[2].type == :begin
- body = send.children[2].children
- else
- body << send.children[2]
- end
- send = send.children[0]
- end
-
- members = []
- keyword_init = T.let(false, T::Boolean)
- send.children[2..].each do |child|
- if child.type == :sym
- members << child.children[0]
- elsif child.type == :kwargs
- pair = child.children[0]
- if pair.children[0].children[0] == :keyword_init
- keyword_init = true if pair.children[1].type == :true
- end
- end
- end
-
- struct = Struct.new(name, members: members, keyword_init: keyword_init, loc: loc, comments: comments)
- @scopes_stack << struct
- visit_all(body)
- @scopes_stack.pop
-
- struct
- end
-
- sig { params(node: AST::Node).returns([String, String, T.nilable(String)]) }
- def parse_tstruct_prop(node)
- name = node.children[2].children[0].to_s
- type = parse_expr(node.children[3])
- has_default = node.children[4]
- &.children&.fetch(0, nil)
- &.children&.fetch(0, nil)
- &.children&.fetch(0, nil) == :default
- default_value = if has_default
- parse_expr(node.children.fetch(4, nil)
- &.children&.fetch(0, nil)
- &.children&.fetch(1, nil))
- end
- [name, type, default_value]
- end
-
- sig { params(node: AST::Node).returns(Sig) }
- def parse_sig(node)
- sig = SigBuilder.build(node)
- sig.loc = node_loc(node)
- sig
- end
-
- sig { params(node: AST::Node).returns(TEnumBlock) }
- def parse_enum(node)
- enum = TEnumBlock.new
- node.children[2].children.each do |child|
- enum << parse_name(child)
- end
- enum.loc = node_loc(node)
- enum
- end
-
- sig { params(node: AST::Node).returns(Loc) }
- def node_loc(node)
- Loc.from_ast_loc(@file, node.location)
- end
-
- sig { params(node: AST::Node).returns(T::Array[Comment]) }
- def node_comments(node)
- comments = @comments[node.location]
- return [] unless comments
- comments.map do |comment|
- text = comment.text[1..-1].strip
- loc = Loc.from_ast_loc(@file, comment.location)
- Comment.new(text, loc: loc)
- end
- end
-
- sig { returns(Tree) }
- def current_scope
- T.must(@scopes_stack.last) # Should never be nil since we create a Tree as the root
- end
-
- sig { returns(T::Array[Sig]) }
- def current_sigs
- sigs = @last_sigs.dup
- @last_sigs.clear
- sigs
- end
- end
-
- class ConstBuilder < ASTVisitor
- extend T::Sig
-
- sig { params(node: T.nilable(AST::Node)).returns(T.nilable(String)) }
- def self.visit(node)
- v = ConstBuilder.new
- v.visit(node)
- return nil if v.names.empty?
- v.names.join("::")
- end
-
- sig { returns(T::Array[String]) }
- attr_accessor :names
-
- sig { void }
- def initialize
- super
- @names = T.let([], T::Array[String])
- end
-
- sig { override.params(node: T.nilable(AST::Node)).void }
- def visit(node)
- return unless node
- case node.type
- when :const, :casgn
- visit(node.children[0])
- @names << node.children[1].to_s
- when :cbase
- @names << ""
- when :sym
- @names << ":#{node.children[0]}"
- end
- end
- end
-
- class SigBuilder < ASTVisitor
- extend T::Sig
-
- sig { params(node: AST::Node).returns(Sig) }
- def self.build(node)
- v = SigBuilder.new
- v.visit_all(node.children[2..-1])
- v.current
- end
-
- sig { returns(Sig) }
- attr_accessor :current
-
- sig { void }
- def initialize
- super
- @current = T.let(Sig.new, Sig)
- end
-
- sig { override.params(node: T.nilable(AST::Node)).void }
- def visit(node)
- return unless node
- case node.type
- when :send
- visit_send(node)
- end
- end
-
- sig { params(node: AST::Node).void }
- def visit_send(node)
- visit(node.children[0]) if node.children[0]
- name = node.children[1]
- case name
- when :abstract
- @current.is_abstract = true
- when :override
- @current.is_override = true
- when :overridable
- @current.is_overridable = true
- when :checked
- @current.checked = node.children[2].children[0]
- when :type_parameters
- node.children[2..-1].each do |child|
- @current.type_params << child.children[0].to_s
- end
- when :params
- node.children[2].children.each do |child|
- name = child.children[0].children[0].to_s
- type = parse_expr(child.children[1])
- @current << SigParam.new(name, type)
- end
- when :returns
- @current.return_type = parse_expr(node.children[2])
- when :void
- @current.return_type = nil
- else
- raise "#{node.location.line}: Unhandled #{name}"
- end
- end
- end
-
- class Loc
- sig { params(file: String, ast_loc: T.any(::Parser::Source::Map, ::Parser::Source::Range)).returns(Loc) }
- def self.from_ast_loc(file, ast_loc)
- Loc.new(
- file: file,
- begin_line: ast_loc.line,
- begin_column: ast_loc.column,
- end_line: ast_loc.last_line,
- end_column: ast_loc.last_column
- )
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/printer.rb | @@ -1,737 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- class Printer < Visitor
- extend T::Sig
-
- sig { returns(T::Boolean) }
- attr_accessor :print_locs, :in_visibility_group
-
- sig { returns(T.nilable(Node)) }
- attr_reader :previous_node
-
- sig { params(out: T.any(IO, StringIO), indent: Integer, print_locs: T::Boolean).void }
- def initialize(out: $stdout, indent: 0, print_locs: false)
- super()
- @out = out
- @current_indent = indent
- @print_locs = print_locs
- @in_visibility_group = T.let(false, T::Boolean)
- @previous_node = T.let(nil, T.nilable(Node))
- end
-
- # Printing
-
- sig { void }
- def indent
- @current_indent += 2
- end
-
- sig { void }
- def dedent
- @current_indent -= 2
- end
-
- # Print a string without indentation nor `\n` at the end.
- sig { params(string: String).void }
- def print(string)
- @out.print(string)
- end
-
- # Print a string without indentation but with a `\n` at the end.
- sig { params(string: T.nilable(String)).void }
- def printn(string = nil)
- print(string) if string
- print("\n")
- end
-
- # Print a string with indentation but without a `\n` at the end.
- sig { params(string: T.nilable(String)).void }
- def printt(string = nil)
- print(" " * @current_indent)
- print(string) if string
- end
-
- # Print a string with indentation and `\n` at the end.
- sig { params(string: String).void }
- def printl(string)
- printt
- printn(string)
- end
-
- sig { params(file: File).void }
- def visit_file(file)
- file.accept_printer(self)
- end
-
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- return unless node
- node.accept_printer(self)
- end
-
- sig { override.params(nodes: T::Array[Node]).void }
- def visit_all(nodes)
- previous_node = @previous_node
- @previous_node = nil
- nodes.each do |node|
- visit(node)
- @previous_node = node
- end
- @previous_node = previous_node
- end
- end
-
- class File
- extend T::Sig
-
- sig { params(v: Printer).void }
- def accept_printer(v)
- strictness = self.strictness
- if strictness
- v.printl("# typed: #{strictness}")
- end
- unless comments.empty?
- v.printn if strictness
- v.visit_all(comments)
- end
-
- unless root.empty?
- v.printn if strictness || !comments.empty?
- v.visit(root)
- end
- end
-
- sig { params(out: T.any(IO, StringIO), indent: Integer, print_locs: T::Boolean).void }
- def print(out: $stdout, indent: 0, print_locs: false)
- p = Printer.new(out: out, indent: indent, print_locs: print_locs)
- p.visit_file(self)
- end
-
- sig { params(indent: Integer, print_locs: T::Boolean).returns(String) }
- def string(indent: 0, print_locs: false)
- out = StringIO.new
- print(out: out, indent: indent, print_locs: print_locs)
- out.string
- end
- end
-
- class Node
- extend T::Sig
-
- sig { abstract.params(v: Printer).void }
- def accept_printer(v); end
-
- sig { params(out: T.any(IO, StringIO), indent: Integer, print_locs: T::Boolean).void }
- def print(out: $stdout, indent: 0, print_locs: false)
- p = Printer.new(out: out, indent: indent, print_locs: print_locs)
- p.visit(self)
- end
-
- sig { params(indent: Integer, print_locs: T::Boolean).returns(String) }
- def string(indent: 0, print_locs: false)
- out = StringIO.new
- print(out: out, indent: indent, print_locs: print_locs)
- out.string
- end
-
- sig { returns(T::Boolean) }
- def oneline?
- true
- end
- end
-
- class NodeWithComments
- extend T::Sig
-
- sig { override.returns(T::Boolean) }
- def oneline?
- comments.empty?
- end
- end
-
- class Comment
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- text = self.text.strip
- v.printt("#")
- v.print(" #{text}") unless text.empty?
- v.printn
- end
- end
-
- class EmptyComment
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.printn
- end
- end
-
- class Tree
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.visit_all(comments)
- v.printn if !comments.empty? && !empty?
- v.visit_all(nodes)
- end
-
- sig { override.returns(T::Boolean) }
- def oneline?
- comments.empty? && empty?
- end
- end
-
- class Scope
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
-
- print_header(v)
- print_body(v)
- end
-
- sig { abstract.params(v: Printer).void }
- def print_header(v); end
-
- sig { params(v: Printer).void }
- def print_body(v)
- unless empty?
- v.indent
- v.visit_all(nodes)
- v.dedent
- v.printl("end")
- end
- end
- end
-
- class Module
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def print_header(v)
- v.printt("module #{name}")
- if empty?
- v.printn("; end")
- else
- v.printn
- end
- end
- end
-
- class Class
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def print_header(v)
- v.printt("class #{name}")
- superclass = superclass_name
- v.print(" < #{superclass}") if superclass
- if empty?
- v.printn("; end")
- else
- v.printn
- end
- end
- end
-
- class Struct
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def print_header(v)
- v.printt("#{name} = ::Struct.new")
- if !members.empty? || keyword_init
- v.print("(")
- args = members.map { |member| ":#{member}" }
- args << "keyword_init: true" if keyword_init
- v.print(args.join(", "))
- v.print(")")
- end
- if empty?
- v.printn
- else
- v.printn(" do")
- end
- end
- end
-
- class SingletonClass
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def print_header(v)
- v.printt("class << self")
- if empty?
- v.printn("; end")
- else
- v.printn
- end
- end
- end
-
- class Const
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
- v.printl("#{name} = #{value}")
- end
- end
-
- class Attr
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.visit_all(comments)
- sigs.each { |sig| v.visit(sig) }
- v.printl("# #{loc}") if loc && v.print_locs
- v.printt
- unless v.in_visibility_group || visibility.public?
- v.print(visibility.visibility.to_s)
- v.print(" ")
- end
- case self
- when AttrAccessor
- v.print("attr_accessor")
- when AttrReader
- v.print("attr_reader")
- when AttrWriter
- v.print("attr_writer")
- end
- unless names.empty?
- v.print(" ")
- v.print(names.map { |name| ":#{name}" }.join(", "))
- end
- v.printn
- end
-
- sig { override.returns(T::Boolean) }
- def oneline?
- comments.empty? && sigs.empty?
- end
- end
-
- class Method
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.visit_all(comments)
- v.visit_all(sigs)
- v.printl("# #{loc}") if loc && v.print_locs
- v.printt
- unless v.in_visibility_group || visibility.public?
- v.print(visibility.visibility.to_s)
- v.print(" ")
- end
- v.print("def ")
- v.print("self.") if is_singleton
- v.print(name)
- unless params.empty?
- v.print("(")
- if inline_params?
- params.each_with_index do |param, index|
- v.print(", ") if index > 0
- v.visit(param)
- end
- else
- v.printn
- v.indent
- params.each_with_index do |param, pindex|
- v.printt
- v.visit(param)
- v.print(",") if pindex < params.size - 1
- param.comments.each_with_index do |comment, cindex|
- if cindex > 0
- param.print_comment_leading_space(v, last: pindex == params.size - 1)
- else
- v.print(" ")
- end
- v.print("# #{comment.text.strip}")
- end
- v.printn
- end
- v.dedent
- end
- v.print(")")
- end
- v.print("; end")
- v.printn
- end
-
- sig { override.returns(T::Boolean) }
- def oneline?
- comments.empty? && sigs.empty? && inline_params?
- end
-
- sig { returns(T::Boolean) }
- def inline_params?
- params.all? { |p| p.comments.empty? }
- end
- end
-
- class Param
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.print(name.to_s)
- end
-
- sig { params(v: Printer, last: T::Boolean).void }
- def print_comment_leading_space(v, last:)
- v.printn
- v.printt
- v.print(" " * (name.size + 1))
- v.print(" ") unless last
- end
- end
-
- class OptParam
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.print("#{name} = #{value}")
- end
-
- sig { override.params(v: Printer, last: T::Boolean).void }
- def print_comment_leading_space(v, last:)
- super
- v.print(" " * (value.size + 3))
- end
- end
-
- class RestParam
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.print("*#{name}")
- end
-
- sig { override.params(v: Printer, last: T::Boolean).void }
- def print_comment_leading_space(v, last:)
- super
- v.print(" ")
- end
- end
-
- class KwParam
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.print("#{name}:")
- end
-
- sig { override.params(v: Printer, last: T::Boolean).void }
- def print_comment_leading_space(v, last:)
- super
- v.print(" ")
- end
- end
-
- class KwOptParam
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.print("#{name}: #{value}")
- end
-
- sig { override.params(v: Printer, last: T::Boolean).void }
- def print_comment_leading_space(v, last:)
- super
- v.print(" " * (value.size + 2))
- end
- end
-
- class KwRestParam
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.print("**#{name}")
- end
-
- sig { override.params(v: Printer, last: T::Boolean).void }
- def print_comment_leading_space(v, last:)
- super
- v.print(" ")
- end
- end
-
- class BlockParam
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.print("&#{name}")
- end
-
- sig { override.params(v: Printer, last: T::Boolean).void }
- def print_comment_leading_space(v, last:)
- super
- v.print(" ")
- end
- end
-
- class Mixin
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
- case self
- when Include
- v.printt("include")
- when Extend
- v.printt("extend")
- when MixesInClassMethods
- v.printt("mixes_in_class_methods")
- end
- v.printn(" #{names.join(", ")}")
- end
- end
-
- class Visibility
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
- v.printl(visibility.to_s)
- end
- end
-
- class Sig
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.printl("# #{loc}") if loc && v.print_locs
- if oneline?
- v.printt("sig { ")
- else
- v.printl("sig do")
- v.indent
- end
- v.print("abstract.") if is_abstract
- v.print("override.") if is_override
- v.print("overridable.") if is_overridable
- unless type_params.empty?
- v.print("type_parameters(")
- type_params.each_with_index do |param, index|
- v.print(":#{param}")
- v.print(", ") if index < type_params.length - 1
- end
- v.print(").")
- end
- unless params.empty?
- if inline_params?
- v.print("params(")
- params.each_with_index do |param, index|
- v.print(", ") if index > 0
- v.visit(param)
- end
- v.print(").")
- else
- v.printl("params(")
- v.indent
- params.each_with_index do |param, pindex|
- v.printt
- v.visit(param)
- v.print(",") if pindex < params.size - 1
- param.comments.each_with_index do |comment, cindex|
- if cindex == 0
- v.print(" ")
- else
- param.print_comment_leading_space(v, last: pindex == params.size - 1)
- end
- v.print("# #{comment.text.strip}")
- end
- v.printn
- end
- v.dedent
- v.printt(").")
- end
- end
- if return_type && return_type != "void"
- v.print("returns(#{return_type})")
- else
- v.print("void")
- end
- if checked
- v.print(".checked(:#{checked})")
- end
- if oneline?
- v.printn(" }")
- else
- v.printn
- v.dedent
- v.printl("end")
- end
- end
-
- sig { override.returns(T::Boolean) }
- def oneline?
- inline_params?
- end
-
- sig { returns(T::Boolean) }
- def inline_params?
- params.all? { |p| p.comments.empty? }
- end
- end
-
- class SigParam
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.print("#{name}: #{type}")
- end
-
- sig { params(v: Printer, last: T::Boolean).void }
- def print_comment_leading_space(v, last:)
- v.printn
- v.printt
- v.print(" " * (name.size + type.size + 3))
- v.print(" ") unless last
- end
- end
-
- class TStructField
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
- case self
- when TStructProp
- v.printt("prop")
- when TStructConst
- v.printt("const")
- end
- v.print(" :#{name}, #{type}")
- default = self.default
- v.print(", default: #{default}") if default
- v.printn
- end
- end
-
- class TEnumBlock
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
- v.printl("enums do")
- v.indent
- names.each do |name|
- v.printl("#{name} = new")
- end
- v.dedent
- v.printl("end")
- end
- end
-
- class TypeMember
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
- v.printl("#{name} = #{value}")
- end
- end
-
- class Helper
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
- v.printl("#{name}!")
- end
- end
-
- class Group
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.printn unless v.previous_node.nil?
- v.visit_all(nodes)
- end
- end
-
- class VisibilityGroup
- extend T::Sig
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.in_visibility_group = true
- if visibility.public?
- v.printn unless v.previous_node.nil?
- else
- v.visit(visibility)
- v.printn
- end
- v.visit_all(nodes)
- v.in_visibility_group = false
- end
-
- sig { override.returns(T::Boolean) }
- def oneline?
- false
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/rewriters/add_sig_templates.rb | @@ -1,71 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- module Rewriters
- class AddSigTemplates < Visitor
- extend T::Sig
-
- sig { params(with_todo_comment: T::Boolean).void }
- def initialize(with_todo_comment: true)
- super()
- @with_todo_comment = with_todo_comment
- end
-
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- case node
- when Tree
- visit_all(node.nodes)
- when Attr
- add_attr_sig(node)
- when Method
- add_method_sig(node)
- end
- end
-
- private
-
- sig { params(attr: Attr).void }
- def add_attr_sig(attr)
- return unless attr.sigs.empty?
- return if attr.names.size > 1
-
- params = []
- params << SigParam.new(attr.names.first.to_s, "T.untyped") if attr.is_a?(AttrWriter)
-
- attr.sigs << Sig.new(
- params: params,
- return_type: "T.untyped"
- )
- add_todo_comment(attr)
- end
-
- sig { params(method: Method).void }
- def add_method_sig(method)
- return unless method.sigs.empty?
-
- method.sigs << Sig.new(
- params: method.params.map { |param| SigParam.new(param.name, "T.untyped") },
- return_type: "T.untyped"
- )
- add_todo_comment(method)
- end
-
- sig { params(node: NodeWithComments).void }
- def add_todo_comment(node)
- node.comments << Comment.new("TODO: fill in signature with appropriate type information") if @with_todo_comment
- end
- end
- end
-
- class Tree
- extend T::Sig
-
- sig { params(with_todo_comment: T::Boolean).void }
- def add_sig_templates!(with_todo_comment: true)
- visitor = Rewriters::AddSigTemplates.new(with_todo_comment: with_todo_comment)
- visitor.visit(self)
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/rewriters/group_nodes.rb | @@ -1,104 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- module Rewriters
- class GroupNodes < Visitor
- extend T::Sig
-
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- return unless node
-
- case node
- when Tree
- kinds = node.nodes.map(&:group_kind)
- kinds.compact!
- kinds.uniq!
-
- groups = {}
- kinds.each { |kind| groups[kind] = Group.new(kind) }
-
- node.nodes.dup.each do |child|
- visit(child)
- child.detach
- groups[child.group_kind] << child
- end
-
- groups.each { |_, group| node << group }
- end
- end
- end
- end
-
- class Tree
- extend T::Sig
-
- sig { void }
- def group_nodes!
- visitor = Rewriters::GroupNodes.new
- visitor.visit(self)
- end
- end
-
- class Node
- extend T::Sig
-
- sig { returns(Group::Kind) }
- def group_kind
- case self
- when Include, Extend
- Group::Kind::Mixins
- when Helper
- Group::Kind::Helpers
- when TypeMember
- Group::Kind::TypeMembers
- when MixesInClassMethods
- Group::Kind::MixesInClassMethods
- when TStructField
- Group::Kind::TStructFields
- when TEnumBlock
- Group::Kind::TEnums
- when VisibilityGroup
- Group::Kind::Methods
- when Method
- if name == "initialize"
- Group::Kind::Inits
- else
- Group::Kind::Methods
- end
- when Scope, Const
- Group::Kind::Consts
- else
- raise "Unknown group for #{self}"
- end
- end
- end
-
- class Group < Tree
- extend T::Sig
-
- sig { returns(Kind) }
- attr_reader :kind
-
- sig { params(kind: Kind).void }
- def initialize(kind)
- super()
- @kind = kind
- end
-
- class Kind < T::Enum
- enums do
- Mixins = new
- Helpers = new
- TypeMembers = new
- MixesInClassMethods = new
- TStructFields = new
- TEnums = new
- Inits = new
- Methods = new
- Consts = new
- end
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/rewriters/merge_trees.rb | @@ -1,629 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- module Rewriters
- # Merge two RBI trees together
- #
- # Be this `Tree`:
- # ~~~rb
- # class Foo
- # attr_accessor :a
- # def m; end
- # C = 10
- # end
- # ~~~
- #
- # Merged with this one:
- # ~~~rb
- # class Foo
- # attr_reader :a
- # def m(x); end
- # C = 10
- # end
- # ~~~
- #
- # Compatible definitions are merged together while incompatible definitions are moved into a `ConflictTree`:
- # ~~~rb
- # class Foo
- # <<<<<<< left
- # attr_accessor :a
- # def m; end
- # =======
- # attr_reader :a
- # def m(x); end
- # >>>>>>> right
- # C = 10
- # end
- # ~~~
- class Merge
- extend T::Sig
-
- class Keep < ::T::Enum
- enums do
- NONE = new
- LEFT = new
- RIGHT = new
- end
- end
-
- sig { params(left: Tree, right: Tree, left_name: String, right_name: String, keep: Keep).returns(Tree) }
- def self.merge_trees(left, right, left_name: "left", right_name: "right", keep: Keep::NONE)
- left.nest_singleton_methods!
- right.nest_singleton_methods!
- rewriter = Rewriters::Merge.new(left_name: left_name, right_name: right_name, keep: keep)
- rewriter.merge(left)
- rewriter.merge(right)
- tree = rewriter.tree
- ConflictTreeMerger.new.visit(tree)
- tree
- end
-
- sig { returns(Tree) }
- attr_reader :tree
-
- sig { params(left_name: String, right_name: String, keep: Keep).void }
- def initialize(left_name: "left", right_name: "right", keep: Keep::NONE)
- @left_name = left_name
- @right_name = right_name
- @keep = keep
- @tree = T.let(Tree.new, Tree)
- @scope_stack = T.let([@tree], T::Array[Tree])
- end
-
- sig { params(tree: Tree).returns(T::Array[Conflict]) }
- def merge(tree)
- v = TreeMerger.new(@tree, left_name: @left_name, right_name: @right_name, keep: @keep)
- v.visit(tree)
- v.conflicts
- end
-
- # Used for logging / error displaying purpose
- class Conflict < T::Struct
- extend T::Sig
-
- const :left, Node
- const :right, Node
- const :left_name, String
- const :right_name, String
-
- sig { returns(String) }
- def to_s
- "Conflicting definitions for `#{left}`"
- end
- end
-
- class TreeMerger < Visitor
- extend T::Sig
-
- sig { returns(T::Array[Conflict]) }
- attr_reader :conflicts
-
- sig { params(output: Tree, left_name: String, right_name: String, keep: Keep).void }
- def initialize(output, left_name: "left", right_name: "right", keep: Keep::NONE)
- super()
- @tree = output
- @index = T.let(output.index, Index)
- @scope_stack = T.let([@tree], T::Array[Tree])
- @left_name = left_name
- @right_name = right_name
- @keep = keep
- @conflicts = T.let([], T::Array[Conflict])
- end
-
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- return unless node
-
- case node
- when Scope
- prev = previous_definition(node)
-
- if prev.is_a?(Scope)
- if node.compatible_with?(prev)
- prev.merge_with(node)
- elsif @keep == Keep::LEFT
- # do nothing it's already merged
- elsif @keep == Keep::RIGHT
- prev = replace_scope_header(prev, node)
- else
- make_conflict_scope(prev, node)
- end
- @scope_stack << prev
- else
- copy = node.dup_empty
- current_scope << copy
- @scope_stack << copy
- end
- visit_all(node.nodes)
- @scope_stack.pop
- when Tree
- current_scope.merge_with(node)
- visit_all(node.nodes)
- when Indexable
- prev = previous_definition(node)
- if prev
- if node.compatible_with?(prev)
- prev.merge_with(node)
- elsif @keep == Keep::LEFT
- # do nothing it's already merged
- elsif @keep == Keep::RIGHT
- prev.replace(node)
- else
- make_conflict_tree(prev, node)
- end
- else
- current_scope << node.dup
- end
- end
- end
-
- private
-
- sig { returns(Tree) }
- def current_scope
- T.must(@scope_stack.last)
- end
-
- sig { params(node: Node).returns(T.nilable(Node)) }
- def previous_definition(node)
- case node
- when Indexable
- node.index_ids.each do |id|
- others = @index[id]
- return others.last unless others.empty?
- end
- end
- nil
- end
-
- sig { params(left: Scope, right: Scope).void }
- def make_conflict_scope(left, right)
- @conflicts << Conflict.new(left: left, right: right, left_name: @left_name, right_name: @right_name)
- scope_conflict = ScopeConflict.new(left: left, right: right, left_name: @left_name, right_name: @right_name)
- left.replace(scope_conflict)
- end
-
- sig { params(left: Node, right: Node).void }
- def make_conflict_tree(left, right)
- @conflicts << Conflict.new(left: left, right: right, left_name: @left_name, right_name: @right_name)
- tree = left.parent_conflict_tree
- unless tree
- tree = ConflictTree.new(left_name: @left_name, right_name: @right_name)
- left.replace(tree)
- tree.left << left
- end
- tree.right << right
- end
-
- sig { params(left: Scope, right: Scope).returns(Scope) }
- def replace_scope_header(left, right)
- right_copy = right.dup_empty
- left.replace(right_copy)
- left.nodes.each do |node|
- right_copy << node
- end
- @index.index(right_copy)
- right_copy
- end
- end
-
- # Merge adjacent conflict trees
- #
- # Transform this:
- # ~~~rb
- # class Foo
- # <<<<<<< left
- # def m1; end
- # =======
- # def m1(a); end
- # >>>>>>> right
- # <<<<<<< left
- # def m2(a); end
- # =======
- # def m2; end
- # >>>>>>> right
- # end
- # ~~~
- #
- # Into this:
- # ~~~rb
- # class Foo
- # <<<<<<< left
- # def m1; end
- # def m2(a); end
- # =======
- # def m1(a); end
- # def m2; end
- # >>>>>>> right
- # end
- # ~~~
- class ConflictTreeMerger < Visitor
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- visit_all(node.nodes) if node.is_a?(Tree)
- end
-
- sig { override.params(nodes: T::Array[Node]).void }
- def visit_all(nodes)
- last_conflict_tree = T.let(nil, T.nilable(ConflictTree))
- nodes.dup.each do |node|
- if node.is_a?(ConflictTree)
- if last_conflict_tree
- merge_conflict_trees(last_conflict_tree.left, node.left)
- merge_conflict_trees(last_conflict_tree.right, node.right)
- node.detach
- next
- else
- last_conflict_tree = node
- end
- end
-
- visit(node)
- end
- end
-
- private
-
- sig { params(left: Tree, right: Tree).void }
- def merge_conflict_trees(left, right)
- right.nodes.dup.each do |node|
- left << node
- end
- end
- end
- end
- end
-
- class Node
- extend T::Sig
-
- # Can `self` and `_other` be merged into a single definition?
- sig { params(_other: Node).returns(T::Boolean) }
- def compatible_with?(_other)
- true
- end
-
- # Merge `self` and `other` into a single definition
- sig { params(other: Node).void }
- def merge_with(other); end
-
- sig { returns(T.nilable(ConflictTree)) }
- def parent_conflict_tree
- parent = T.let(parent_tree, T.nilable(Node))
- while parent
- return parent if parent.is_a?(ConflictTree)
- parent = parent.parent_tree
- end
- nil
- end
- end
-
- class NodeWithComments
- extend T::Sig
-
- sig { override.params(other: Node).void }
- def merge_with(other)
- return unless other.is_a?(NodeWithComments)
- other.comments.each do |comment|
- comments << comment unless comments.include?(comment)
- end
- end
- end
-
- class Tree
- extend T::Sig
-
- sig { params(other: Tree).returns(Tree) }
- def merge(other)
- Rewriters::Merge.merge_trees(self, other)
- end
- end
-
- class Scope
- extend T::Sig
-
- # Duplicate `self` scope without its body
- sig { returns(T.self_type) }
- def dup_empty
- case self
- when Module
- Module.new(name, loc: loc, comments: comments)
- when Class
- Class.new(name, superclass_name: superclass_name, loc: loc, comments: comments)
- when Struct
- Struct.new(name, members: members, keyword_init: keyword_init, loc: loc, comments: comments)
- when SingletonClass
- SingletonClass.new(loc: loc, comments: comments)
- else
- raise "Can't duplicate node #{self}"
- end
- end
- end
-
- class Class
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(Class) && superclass_name == other.superclass_name
- end
- end
-
- class Module
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(Module)
- end
- end
-
- class Struct
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(Struct) && members == other.members && keyword_init == other.keyword_init
- end
- end
-
- class Const
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(Const) && name == other.name && value == other.value
- end
- end
-
- class Attr
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- return false unless other.is_a?(Attr)
- return false unless names == other.names
- sigs.empty? || other.sigs.empty? || sigs == other.sigs
- end
-
- sig { override.params(other: Node).void }
- def merge_with(other)
- return unless other.is_a?(Attr)
- super
- other.sigs.each do |sig|
- sigs << sig unless sigs.include?(sig)
- end
- end
- end
-
- class AttrReader
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(AttrReader) && super
- end
- end
-
- class AttrWriter
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(AttrWriter) && super
- end
- end
-
- class AttrAccessor
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(AttrAccessor) && super
- end
- end
-
- class Method
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- return false unless other.is_a?(Method)
- return false unless name == other.name
- return false unless params == other.params
- sigs.empty? || other.sigs.empty? || sigs == other.sigs
- end
-
- sig { override.params(other: Node).void }
- def merge_with(other)
- return unless other.is_a?(Method)
- super
- other.sigs.each do |sig|
- sigs << sig unless sigs.include?(sig)
- end
- end
- end
-
- class Mixin
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(Mixin) && names == other.names
- end
- end
-
- class Include
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(Include) && super
- end
- end
-
- class Extend
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(Extend) && super
- end
- end
-
- class MixesInClassMethods
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(MixesInClassMethods) && super
- end
- end
-
- class Helper
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(Helper) && name == other.name
- end
- end
-
- class TStructField
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(TStructField) && name == other.name && type == other.type && default == other.default
- end
- end
-
- class TStructConst
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(TStructConst) && super
- end
- end
-
- class TEnumBlock
- extend T::Sig
-
- sig { override.params(other: Node).void }
- def merge_with(other)
- return unless other.is_a?(TEnumBlock)
- super
- other.names.each do |name|
- names << name unless names.include?(name)
- end
- end
- end
-
- class TStructProp
- extend T::Sig
-
- sig { override.params(other: Node).returns(T::Boolean) }
- def compatible_with?(other)
- other.is_a?(TStructProp) && super
- end
- end
-
- # A tree showing incompatibles nodes
- #
- # Is rendered as a merge conflict between `left` and` right`:
- # ~~~rb
- # class Foo
- # <<<<<<< left
- # def m1; end
- # def m2(a); end
- # =======
- # def m1(a); end
- # def m2; end
- # >>>>>>> right
- # end
- # ~~~
- class ConflictTree < Tree
- extend T::Sig
-
- sig { returns(Tree) }
- attr_reader :left, :right
-
- sig { params(left_name: String, right_name: String).void }
- def initialize(left_name: "left", right_name: "right")
- super()
- @left_name = left_name
- @right_name = right_name
- @left = T.let(Tree.new, Tree)
- @left.parent_tree = self
- @right = T.let(Tree.new, Tree)
- @right.parent_tree = self
- end
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- v.printl("<<<<<<< #{@left_name}")
- v.visit(left)
- v.printl("=======")
- v.visit(right)
- v.printl(">>>>>>> #{@right_name}")
- end
- end
-
- # A conflict between two scope headers
- #
- # Is rendered as a merge conflict between `left` and` right` for scope definitions:
- # ~~~rb
- # <<<<<<< left
- # class Foo
- # =======
- # module Foo
- # >>>>>>> right
- # def m1; end
- # end
- # ~~~
- class ScopeConflict < Tree
- extend T::Sig
-
- sig { returns(Scope) }
- attr_reader :left, :right
-
- sig do
- params(
- left: Scope,
- right: Scope,
- left_name: String,
- right_name: String
- ).void
- end
- def initialize(left:, right:, left_name: "left", right_name: "right")
- super()
- @left = left
- @right = right
- @left_name = left_name
- @right_name = right_name
- end
-
- sig { override.params(v: Printer).void }
- def accept_printer(v)
- previous_node = v.previous_node
- v.printn if previous_node && (!previous_node.oneline? || !oneline?)
-
- v.printl("# #{loc}") if loc && v.print_locs
- v.visit_all(comments)
-
- v.printl("<<<<<<< #{@left_name}")
- left.print_header(v)
- v.printl("=======")
- right.print_header(v)
- v.printl(">>>>>>> #{@right_name}")
- left.print_body(v)
- end
-
- sig { override.returns(T::Boolean) }
- def oneline?
- left.oneline?
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/rewriters/nest_non_public_methods.rb | @@ -1,63 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- module Rewriters
- class NestNonPublicMethods < Visitor
- extend T::Sig
-
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- return unless node
-
- case node
- when Tree
- public_group = VisibilityGroup.new(Public.new)
- protected_group = VisibilityGroup.new(Protected.new)
- private_group = VisibilityGroup.new(Private.new)
-
- node.nodes.dup.each do |child|
- visit(child)
- next unless child.is_a?(Method)
- child.detach
- case child.visibility
- when Protected
- protected_group << child
- when Private
- private_group << child
- else
- public_group << child
- end
- end
-
- node << public_group unless public_group.empty?
- node << protected_group unless protected_group.empty?
- node << private_group unless private_group.empty?
- end
- end
- end
- end
-
- class Tree
- extend T::Sig
-
- sig { void }
- def nest_non_public_methods!
- visitor = Rewriters::NestNonPublicMethods.new
- visitor.visit(self)
- end
- end
-
- class VisibilityGroup < Tree
- extend T::Sig
-
- sig { returns(Visibility) }
- attr_reader :visibility
-
- sig { params(visibility: Visibility).void }
- def initialize(visibility)
- super()
- @visibility = visibility
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/rewriters/nest_singleton_methods.rb | @@ -1,40 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- module Rewriters
- class NestSingletonMethods < Visitor
- extend T::Sig
-
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- return unless node
-
- case node
- when Tree
- singleton_class = SingletonClass.new
-
- node.nodes.dup.each do |child|
- visit(child)
- next unless child.is_a?(Method) && child.is_singleton
- child.detach
- child.is_singleton = false
- singleton_class << child
- end
-
- node << singleton_class unless singleton_class.empty?
- end
- end
- end
- end
-
- class Tree
- extend T::Sig
-
- sig { void }
- def nest_singleton_methods!
- visitor = Rewriters::NestSingletonMethods.new
- visitor.visit(self)
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/rewriters/sort_nodes.rb | @@ -1,84 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- module Rewriters
- class SortNodes < Visitor
- extend T::Sig
-
- sig { override.params(node: T.nilable(Node)).void }
- def visit(node)
- return unless node.is_a?(Tree)
- visit_all(node.nodes)
- original_order = node.nodes.map.with_index.to_h
- node.nodes.sort! do |a, b|
- res = node_rank(a) <=> node_rank(b)
- res = node_name(a) <=> node_name(b) if res == 0
- res = (original_order[a] || 0) <=> (original_order[b] || 0) if res == 0
- res || 0
- end
- end
-
- private
-
- sig { params(node: Node).returns(Integer) }
- def node_rank(node)
- case node
- when Group then group_rank(node.kind)
- when Include, Extend then 10
- when Helper then 20
- when TypeMember then 30
- when MixesInClassMethods then 40
- when TStructField then 50
- when TEnumBlock then 60
- when Method
- if node.name == "initialize"
- 71
- elsif !node.is_singleton
- 72
- else
- 73
- end
- when Scope, Const then 80
- else
- 100
- end
- end
-
- sig { params(kind: Group::Kind).returns(Integer) }
- def group_rank(kind)
- case kind
- when Group::Kind::Mixins then 0
- when Group::Kind::Helpers then 1
- when Group::Kind::TypeMembers then 2
- when Group::Kind::MixesInClassMethods then 3
- when Group::Kind::TStructFields then 4
- when Group::Kind::TEnums then 5
- when Group::Kind::Inits then 6
- when Group::Kind::Methods then 7
- when Group::Kind::Consts then 8
- else
- T.absurd(kind)
- end
- end
-
- sig { params(node: Node).returns(T.nilable(String)) }
- def node_name(node)
- case node
- when Module, Class, Struct, Const, Method, Helper, TStructField
- node.name
- end
- end
- end
- end
-
- class Tree
- extend T::Sig
-
- sig { void }
- def sort_nodes!
- visitor = Rewriters::SortNodes.new
- visitor.visit(self)
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/version.rb | @@ -1,7 +0,0 @@
-# typed: true
-# typed: false
-# frozen_string_literal: true
-
-module RBI
- VERSION = "0.0.4"
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rbi-0.0.4/lib/rbi/visitor.rb | @@ -1,19 +0,0 @@
-# typed: strict
-# frozen_string_literal: true
-
-module RBI
- class Visitor
- extend T::Helpers
- extend T::Sig
-
- abstract!
-
- sig { abstract.params(node: T.nilable(Node)).void }
- def visit(node); end
-
- sig { params(nodes: T::Array[Node]).void }
- def visit_all(nodes)
- nodes.each { |node| visit(node) }
- end
- end
-end | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser.rb | @@ -1,238 +0,0 @@
-# frozen_string_literal: true
-
-require 'diff/lcs'
-require 'diff/lcs/hunk'
-require 'optparse'
-require 'parser/current'
-require 'set'
-
-require 'unparser/equalizer'
-require 'unparser/adamantium'
-require 'unparser/adamantium/method_builder'
-require 'unparser/abstract_type'
-
-require 'unparser/concord'
-require 'unparser/either'
-require 'unparser/anima'
-require 'unparser/anima/attribute'
-require 'unparser/anima/error'
-
-# Library namespace
-module Unparser
- # Unparser specific AST builder defaulting to modern AST format
- class Builder < Parser::Builders::Default
- modernize
-
- def initialize
- super
-
- self.emit_file_line_as_literals = false
- end
- end
-
- EMPTY_STRING = ''.freeze
- EMPTY_ARRAY = [].freeze
-
- private_constant(*constants(false) - %i[Adamantium AbstractType Anima Concord Either Equalizer Memoizable])
-
- # Error raised when unparser encounters an invalid AST
- class InvalidNodeError < RuntimeError
- attr_reader :node
-
- def initialize(message, node)
- super(message)
- @node = node
- freeze
- end
- end
-
- # Unparse an AST (and, optionally, comments) into a string
- #
- # @param [Parser::AST::Node, nil] node
- # @param [Array] comment_array
- #
- # @return [String]
- #
- # @raise InvalidNodeError
- # if the node passed is invalid
- #
- # @api public
- def self.unparse(node, comment_array = [])
- return '' if node.nil?
-
- Buffer.new.tap do |buffer|
- Emitter::Root.new(
- buffer,
- node,
- Comments.new(comment_array)
- ).write_to_buffer
- end.content
- end
-
- # Unparse with validation
- #
- # @param [Parser::AST::Node, nil] node
- # @param [Array] comment_array
- #
- # @return [Either<Validation,String>]
- def self.unparse_validate(node, comment_array = [])
- generated = unparse(node, comment_array)
- validation = Validation.from_string(generated)
-
- if validation.success?
- Either::Right.new(generated)
- else
- Either::Left.new(validation)
- end
- end
-
- # Unparse capturing errors
- #
- # This is mostly useful for writing testing tools against unparser.
- #
- # @param [Parser::AST::Node, nil] node
- #
- # @return [Either<Exception, String>]
- def self.unparse_either(node)
- Either.wrap_error(Exception) { unparse(node) }
- end
-
- # Parse string into AST
- #
- # @param [String] source
- #
- # @return [Parser::AST::Node, nil]
- def self.parse(source)
- parser.parse(buffer(source))
- end
-
- # Parse string into either syntax error or AST
- #
- # @param [String] source
- #
- # @return [Either<Parser::SyntaxError, (Parser::ASTNode, nil)>]
- def self.parse_either(source)
- Either.wrap_error(Parser::SyntaxError) do
- parser.parse(buffer(source))
- end
- end
-
- # Parse string into AST, with comments
- #
- # @param [String] source
- #
- # @return [Parser::AST::Node]
- def self.parse_with_comments(source)
- parser.parse_with_comments(buffer(source))
- end
-
- # Parser instance that produces AST unparser understands
- #
- # @return [Parser::Base]
- #
- # @api private
- def self.parser
- Parser::CurrentRuby.new(Builder.new).tap do |parser|
- parser.diagnostics.tap do |diagnostics|
- diagnostics.all_errors_are_fatal = true
- end
- end
- end
-
- # Construct a parser buffer from string
- #
- # @param [String] source
- #
- # @return [Parser::Source::Buffer]
- def self.buffer(source, identification = '(string)')
- Parser::Source::Buffer.new(identification, source: source)
- end
-end # Unparser
-
-require 'unparser/node_helpers'
-require 'unparser/ast'
-require 'unparser/ast/local_variable_scope'
-require 'unparser/buffer'
-require 'unparser/generation'
-require 'unparser/color'
-require 'unparser/comments'
-require 'unparser/constants'
-require 'unparser/diff'
-require 'unparser/dsl'
-require 'unparser/emitter'
-require 'unparser/emitter/alias'
-require 'unparser/emitter/args'
-require 'unparser/emitter/argument'
-require 'unparser/emitter/array'
-require 'unparser/emitter/array_pattern'
-require 'unparser/emitter/assignment'
-require 'unparser/emitter/begin'
-require 'unparser/emitter/binary'
-require 'unparser/emitter/block'
-require 'unparser/emitter/case'
-require 'unparser/emitter/case_guard'
-require 'unparser/emitter/case_match'
-require 'unparser/emitter/cbase'
-require 'unparser/emitter/class'
-require 'unparser/emitter/const_pattern'
-require 'unparser/emitter/def'
-require 'unparser/emitter/defined'
-require 'unparser/emitter/dstr'
-require 'unparser/emitter/dsym'
-require 'unparser/emitter/flipflop'
-require 'unparser/emitter/float'
-require 'unparser/emitter/flow_modifier'
-require 'unparser/emitter/for'
-require 'unparser/emitter/hash'
-require 'unparser/emitter/hash_pattern'
-require 'unparser/emitter/hookexe'
-require 'unparser/emitter/if'
-require 'unparser/emitter/in_match'
-require 'unparser/emitter/in_pattern'
-require 'unparser/emitter/index'
-require 'unparser/emitter/kwbegin'
-require 'unparser/emitter/lambda'
-require 'unparser/emitter/masgn'
-require 'unparser/emitter/match'
-require 'unparser/emitter/match_alt'
-require 'unparser/emitter/match_as'
-require 'unparser/emitter/match_rest'
-require 'unparser/emitter/match_var'
-require 'unparser/emitter/mlhs'
-require 'unparser/emitter/module'
-require 'unparser/emitter/op_assign'
-require 'unparser/emitter/pin'
-require 'unparser/emitter/primitive'
-require 'unparser/emitter/range'
-require 'unparser/emitter/regexp'
-require 'unparser/emitter/repetition'
-require 'unparser/emitter/rescue'
-require 'unparser/emitter/root'
-require 'unparser/emitter/send'
-require 'unparser/emitter/simple'
-require 'unparser/emitter/splat'
-require 'unparser/emitter/super'
-require 'unparser/emitter/undef'
-require 'unparser/emitter/variable'
-require 'unparser/emitter/xstr'
-require 'unparser/emitter/yield'
-require 'unparser/emitter/kwargs'
-require 'unparser/emitter/pair'
-require 'unparser/emitter/match_pattern'
-require 'unparser/writer'
-require 'unparser/writer/binary'
-require 'unparser/writer/dynamic_string'
-require 'unparser/writer/resbody'
-require 'unparser/writer/rescue'
-require 'unparser/writer/send'
-require 'unparser/writer/send/attribute_assignment'
-require 'unparser/writer/send/binary'
-require 'unparser/writer/send/regular'
-require 'unparser/writer/send/unary'
-require 'unparser/node_details'
-require 'unparser/node_details/send'
-require 'unparser/cli'
-
-require 'unparser/validation'
-# make it easy for zombie
-require 'unparser/finalize' | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/abstract_type.rb | @@ -1,121 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # Module to allow class and methods to be abstract
- #
- # Original code before vendoring and reduction from: https://github.com/dkubb/abstract_type.
- module AbstractType
-
- # Hook called when module is included
- #
- # @param [Module] descendant
- # the module or class including AbstractType
- #
- # @return [undefined]
- #
- # @api private
- def self.included(descendant)
- super
- create_new_method(descendant)
- descendant.extend(AbstractMethodDeclarations)
- end
-
- private_class_method :included
-
- # Define the new method on the abstract type
- #
- # Ensures that the instance cannot be of the abstract type
- # and must be a descendant.
- #
- # @param [Class] abstract_class
- #
- # @return [undefined]
- #
- # @api private
- def self.create_new_method(abstract_class)
- abstract_class.define_singleton_method(:new) do |*args, &block|
- if equal?(abstract_class)
- fail NotImplementedError, "#{self} is an abstract type"
- else
- super(*args, &block)
- end
- end
- end
-
- private_class_method :create_new_method
-
- module AbstractMethodDeclarations
-
- # Create abstract instance methods
- #
- # @example
- # class Foo
- # include AbstractType
- #
- # # Create an abstract instance method
- # abstract_method :some_method
- # end
- #
- # @param [Array<#to_s>] names
- #
- # @return [self]
- #
- # @api public
- def abstract_method(*names)
- names.each(&method(:create_abstract_instance_method))
- self
- end
-
- # Create abstract singleton methods
- #
- # @example
- # class Foo
- # include AbstractType
- #
- # # Create an abstract instance method
- # abstract_singleton_method :some_method
- # end
- #
- # @param [Array<#to_s>] names
- #
- # @return [self]
- #
- # @api private
- def abstract_singleton_method(*names)
- names.each(&method(:create_abstract_singleton_method))
- self
- end
-
- private
-
- # Create abstract singleton method
- #
- # @param [#to_s] name
- # the name of the method to create
- #
- # @return [undefined]
- #
- # @api private
- def create_abstract_singleton_method(name)
- define_singleton_method(name) do |*|
- fail NotImplementedError, "#{self}.#{name} is not implemented"
- end
- end
-
- # Create abstract instance method
- #
- # @param [#to_s] name
- # the name of the method to create
- #
- # @return [undefined]
- #
- # @api private
- def create_abstract_instance_method(name)
- define_method(name) do |*|
- fail NotImplementedError, "#{self.class}##{name} is not implemented"
- end
- end
-
- end # AbstractMethodDeclarations
- end # AbstractType
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/adamantium.rb | @@ -1,150 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # Allows objects to be made immutable
- #
- # Original code before vendoring and reduction from: https://github.com/dkubb/adamantium.
- module Adamantium
- module InstanceMethods
- # A noop #dup for immutable objects
- #
- # @return [self]
- #
- # @api public
- def dup
- self
- end
-
- # Freeze the object
- #
- # @return [Object]
- #
- # @api public
- def freeze
- memoized_method_cache
- super()
- end
-
- private
-
- def memoized_method_cache
- @memoized_method_cache ||= Memory.new({})
- end
-
- end # InstanceMethods
-
- # Storage for memoized methods
- class Memory
-
- # Initialize the memory storage for memoized methods
- #
- # @return [undefined]
- #
- # @api private
- def initialize(values)
- @values = values
- @monitor = Monitor.new
- freeze
- end
-
- # Fetch the value from memory, or evaluate if it does not exist
- #
- # @param [Symbol] name
- #
- # @yieldreturn [Object]
- # the value to memoize
- #
- # @api public
- def fetch(name)
- @values.fetch(name) do # check for the key
- @monitor.synchronize do # acquire a lock if the key is not found
- @values.fetch(name) do # recheck under lock
- @values[name] = yield # set the value
- end
- end
- end
- end
- end # Memory
-
- # Methods mixed in to adamantium classes
- module ClassMethods
-
- # Instantiate a new frozen object
- #
- # @return [Object]
- #
- # @api public
- def new(*)
- super.freeze
- end
-
- end # ClassMethods
-
- # Methods mixed in to adamantium modules
- module ModuleMethods
-
- # Memoize a list of methods
- #
- # @param [Array<#to_s>] methods
- # a list of methods to memoize
- #
- # @return [self]
- #
- # @api public
- def memoize(*methods)
- methods.each(&method(:memoize_method))
- self
- end
-
- # Test if method is memoized
- #
- # @param [Symbol] name
- #
- # @return [Bool]
- def memoized?(method_name)
- memoized_methods.key?(method_name)
- end
-
- # Return unmemoized instance method
- #
- # @param [Symbol] name
- #
- # @return [UnboundMethod]
- # the memoized method
- #
- # @raise [NameError]
- # raised if the method is unknown
- #
- # @api public
- def unmemoized_instance_method(method_name)
- memoized_methods.fetch(method_name) do
- fail ArgumentError, "##{method_name} is not memoized"
- end
- end
-
- private
-
- def memoize_method(method_name)
- if memoized_methods.key?(method_name)
- fail ArgumentError, "##{method_name} is already memoized"
- end
-
- memoized_methods[method_name] = MethodBuilder.new(self, method_name).call
- end
-
- def memoized_methods
- @memoized_methods ||= {}
- end
-
- end # ModuleMethods
-
- def self.included(descendant)
- descendant.class_eval do
- include InstanceMethods
- extend ModuleMethods
- extend ClassMethods if instance_of?(Class)
- end
- end
- private_class_method :included
- end # Adamantium
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/adamantium/method_builder.rb | @@ -1,110 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- module Adamantium
- # Build the memoized method
- class MethodBuilder
-
- # Raised when the method arity is invalid
- class InvalidArityError < ArgumentError
-
- # Initialize an invalid arity exception
- #
- # @param [Module] descendant
- # @param [Symbol] method
- # @param [Integer] arity
- #
- # @api private
- def initialize(descendant, method, arity)
- super("Cannot memoize #{descendant}##{method}, its arity is #{arity}")
- end
-
- end # InvalidArityError
-
- # Raised when a block is passed to a memoized method
- class BlockNotAllowedError < ArgumentError
-
- # Initialize a block not allowed exception
- #
- # @param [Module] descendant
- # @param [Symbol] method
- #
- # @api private
- def initialize(descendant, method)
- super("Cannot pass a block to #{descendant}##{method}, it is memoized")
- end
-
- end # BlockNotAllowedError
-
- # Initialize an object to build a memoized method
- #
- # @param [Module] descendant
- # @param [Symbol] method_name
- #
- # @return [undefined]
- #
- # @api private
- def initialize(descendant, method_name)
- @descendant = descendant
- @method_name = method_name
- @original_visibility = visibility
- @original_method = @descendant.instance_method(@method_name)
- assert_arity(@original_method.arity)
- end
-
- # Build a new memoized method
- #
- # @example
- # method_builder.call # => creates new method
- #
- # @return [UnboundMethod]
- #
- # @api public
- def call
- remove_original_method
- create_memoized_method
- set_method_visibility
- @original_method
- end
-
- private
-
- def assert_arity(arity)
- if arity.nonzero?
- fail InvalidArityError.new(@descendant, @method_name, arity)
- end
- end
-
- def remove_original_method
- name = @method_name
- @descendant.module_eval { undef_method(name) }
- end
-
- def create_memoized_method
- name = @method_name
- method = @original_method
- @descendant.module_eval do
- define_method(name) do |&block|
- fail BlockNotAllowedError.new(self.class, name) if block
-
- memoized_method_cache.fetch(name) do
- method.bind(self).call.freeze
- end
- end
- end
- end
-
- def set_method_visibility
- @descendant.__send__(@original_visibility, @method_name)
- end
-
- def visibility
- if @descendant.private_method_defined?(@method_name) then :private
- elsif @descendant.protected_method_defined?(@method_name) then :protected
- else :public
- end
- end
-
- end # MethodBuilder
- end # Adamantium
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/anima.rb | @@ -1,184 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # Original code before vendoring and reduction from: https://github.com/mbj/anima.
- class Anima < Module
- include Adamantium, Equalizer.new(:attributes)
-
- # Return names
- #
- # @return [AttributeSet]
- attr_reader :attributes
-
- # Initialize object
- #
- # @return [undefined]
- #
- # rubocop:disable Lint/MissingSuper
- def initialize(*names)
- @attributes = names.uniq.map(&Attribute.public_method(:new)).freeze
- end
- # rubocop:enable Lint/MissingSuper
-
- # Return new anima with attributes added
- #
- # @return [Anima]
- #
- # @example
- # anima = Anima.new(:foo)
- # anima.add(:bar) # equals Anima.new(:foo, :bar)
- #
- def add(*names)
- new(attribute_names + names)
- end
-
- # Return new anima with attributes removed
- #
- # @return [Anima]
- #
- # @example
- # anima = Anima.new(:foo, :bar)
- # anima.remove(:bar) # equals Anima.new(:foo)
- #
- def remove(*names)
- new(attribute_names - names)
- end
-
- # Return attributes hash for instance
- #
- # @param [Object] object
- #
- # @return [Hash]
- def attributes_hash(object)
- attributes.each_with_object({}) do |attribute, attributes_hash|
- attributes_hash[attribute.name] = attribute.get(object)
- end
- end
-
- # Return attribute names
- #
- # @return [Enumerable<Symbol>]
- def attribute_names
- attributes.map(&:name)
- end
- memoize :attribute_names
-
- # Initialize instance
- #
- # @param [Object] object
- #
- # @param [Hash] attribute_hash
- #
- # @return [self]
- def initialize_instance(object, attribute_hash)
- assert_known_attributes(object.class, attribute_hash)
- attributes.each do |attribute|
- attribute.load(object, attribute_hash)
- end
- self
- end
-
- # Static instance methods for anima infected classes
- module InstanceMethods
- # Initialize an anima infected object
- #
- # @param [#to_h] attributes
- # a hash that matches anima defined attributes
- #
- # @return [undefined]
- #
- # rubocop:disable Lint/MissingSuper
- def initialize(attributes)
- self.class.anima.initialize_instance(self, attributes)
- end
- # rubocop:enable Lint/MissingSuper
-
- # Return a hash representation of an anima infected object
- #
- # @example
- # anima.to_h # => { :foo => : bar }
- #
- # @return [Hash]
- #
- # @api public
- def to_h
- self.class.anima.attributes_hash(self)
- end
-
- # Return updated instance
- #
- # @example
- # klass = Class.new do
- # include Anima.new(:foo, :bar)
- # end
- #
- # foo = klass.new(:foo => 1, :bar => 2)
- # updated = foo.with(:foo => 3)
- # updated.foo # => 3
- # updated.bar # => 2
- #
- # @param [Hash] attributes
- #
- # @return [Anima]
- #
- # @api public
- def with(attributes)
- self.class.new(to_h.update(attributes))
- end
- end # InstanceMethods
-
- private
-
- # Infect the instance with anima
- #
- # @param [Class, Module] scope
- #
- # @return [undefined]
- def included(descendant)
- descendant.instance_exec(self, attribute_names) do |anima, names|
- # Define anima method
- define_singleton_method(:anima) { anima }
-
- # Define instance methods
- include InstanceMethods
-
- # Define attribute readers
- attr_reader(*names)
-
- # Define equalizer
- include Equalizer.new(*names)
- end
- end
-
- # Fail unless keys in +attribute_hash+ matches #attribute_names
- #
- # @param [Class] klass
- # the class being initialized
- #
- # @param [Hash] attribute_hash
- # the attributes to initialize +object+ with
- #
- # @return [undefined]
- #
- # @raise [Error]
- def assert_known_attributes(klass, attribute_hash)
- keys = attribute_hash.keys
-
- unknown = keys - attribute_names
- missing = attribute_names - keys
-
- unless unknown.empty? && missing.empty?
- fail Error.new(klass, missing, unknown)
- end
- end
-
- # Return new instance
- #
- # @param [Enumerable<Symbol>] attributes
- #
- # @return [Anima]
- def new(attributes)
- self.class.new(*attributes)
- end
- end # Anima
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/anima/attribute.rb | @@ -1,59 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Anima
- # An attribute
- class Attribute
- include Adamantium, Equalizer.new(:name)
-
- # Initialize attribute
- #
- # @param [Symbol] name
- def initialize(name)
- @name = name
- @instance_variable_name = :"@#{name}"
- end
-
- # Return attribute name
- #
- # @return [Symbol]
- attr_reader :name
-
- # Return instance variable name
- #
- # @return [Symbol]
- attr_reader :instance_variable_name
-
- # Load attribute
- #
- # @param [Object] object
- # @param [Hash] attributes
- #
- # @return [self]
- def load(object, attributes)
- set(object, attributes.fetch(name))
- end
-
- # Get attribute value from object
- #
- # @param [Object] object
- #
- # @return [Object]
- def get(object)
- object.public_send(name)
- end
-
- # Set attribute value in object
- #
- # @param [Object] object
- # @param [Object] value
- #
- # @return [self]
- def set(object, value)
- object.instance_variable_set(instance_variable_name, value)
-
- self
- end
- end # Attribute
- end # Anima
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/anima/error.rb | @@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Anima
- # Abstract base class for anima errors
- class Error < RuntimeError
- FORMAT = '%s attributes missing: %s, unknown: %s'.freeze
- private_constant(*constants(false))
-
- # Initialize object
- #
- # @param [Class] klass
- # the class being initialized
- # @param [Enumerable<Symbol>] missing
- # @param [Enumerable<Symbol>] unknown
- #
- # @return [undefined]
- def initialize(klass, missing, unknown)
- super(format(FORMAT, klass, missing, unknown))
- end
- end # Error
- end # Anima
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/ast.rb | @@ -1,201 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # Namespace for AST processing tools
- module AST
- FIRST_CHILD = ->(node) { node.children.first }.freeze
- TAUTOLOGY = ->(_node) { true }.freeze
-
- RESET_NODES = %i[module class sclass def defs].freeze
- INHERIT_NODES = [:block].freeze
- CLOSE_NODES = (RESET_NODES + INHERIT_NODES).freeze
-
- # Nodes that assign a local variable
- ASSIGN_NODES =
- %i[
- arg
- kwarg
- kwoptarg
- lvasgn
- optarg
- procarg0
- restarg
- ].to_set.freeze
-
- # Test for local variable inherited scope reset
- #
- # @param [Parser::AST::Node] node
- #
- # @return [Boolean]
- #
- # @api private
- #
- def self.not_close_scope?(node)
- !CLOSE_NODES.include?(node.type)
- end
-
- # Test for local variable scope reset
- #
- # @param [Parser::AST::Node] node
- #
- # @return [Boolean]
- #
- # @api private
- #
- def self.not_reset_scope?(node)
- !RESET_NODES.include?(node.type)
- end
-
- # Return local variables that get assigned in scope
- #
- # @param [Parser::AST::Node] node
- #
- # @return [Set<Symbol>]
- #
- # @api private
- #
- def self.local_variable_assignments(node)
- Enumerator.new(
- node,
- method(:not_reset_scope?)
- ).types(ASSIGN_NODES)
- end
-
- # Return local variables read
- #
- # @param [Parser::AST::Node] node
- #
- # @return [Set<Symbol>]
- #
- # @api private
- #
- def self.local_variable_reads(node)
- Enumerator.new(
- node,
- method(:not_close_scope?)
- ).type(:lvar).map(&FIRST_CHILD).to_set
- end
-
- # AST enumerator
- class Enumerator
- include Adamantium, Concord.new(:node, :controller), Enumerable
-
- # Return new instance
- #
- # @param [Parser::AST::Node] node
- # @param [#call(node)] controller
- #
- # @return [Enumerator]
- #
- # @api private
- #
- def self.new(node, controller = TAUTOLOGY)
- super
- end
-
- # Return each node
- #
- # @return [Enumerator<Parser::AST::Node>]
- # if no block given
- #
- # @return [self]
- # otherwise
- #
- # @api private
- #
- def each(&block)
- Walker.call(node, controller, &block)
- end
-
- # Return nodes selected by types
- #
- # @param [Enumerable<Symbol>] types
- #
- # @return [Enumerable<Parser::AST::Node>]
- #
- # @api private
- #
- def types(types)
- select { |node| types.include?(node.type) }
- end
-
- # Return nodes selected by type
- #
- # @param [Symbol] type
- #
- # @return [Enumerable<Parser::AST::Node>]
- #
- # @api private
- #
- def type(type)
- select { |node| node.type.equal?(type) }
- end
-
- # Return frozne set of objects
- #
- # @param [Enumerable] enumerable
- #
- # @return [Set]
- #
- # @api private
- #
- def self.set(enumerable)
- enumerable.to_set.freeze
- end
- private_class_method :set
-
- # Return nodes of type
- #
- # @param [Parser::AST::Node] node
- # @param [Symbol] type
- #
- # @return [Enumerable<Parser::AST::Node]
- #
- # @api private
- #
- def self.type(node, type)
- new(node).type(type)
- end
- private_class_method :type
-
- end # Enumerator
-
- # Controlled AST walker walking the AST in deeth first search with pre order
- class Walker
- include Concord.new(:block, :controller)
-
- # Call ast walker
- #
- # @param [Parser::AST::Node] node
- #
- # @return [self]
- #
- # @api private
- #
- def self.call(node, controller = TAUTOLOGY, &block)
- new(block, controller).call(node)
- self
- end
-
- # Call walker with node
- #
- # @param [Parser::AST::Node] node
- #
- # @return [undefined]
- #
- # @api private
- #
- def call(node)
- return unless controller.call(node)
-
- block.call(node)
- node.children.each do |child|
- break unless child.instance_of?(Parser::AST::Node)
-
- call(child)
- end
- end
-
- end # Walker
- end # AST
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/ast/local_variable_scope.rb | @@ -1,174 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- module AST
-
- # Calculated local variable scope for a given node
- class LocalVariableScope
- include Enumerable, Adamantium, Concord.new(:node)
-
- # Initialize object
- #
- # @param [Parser::AST::Node] node
- #
- # @return [undefined]
- #
- # @api private
- #
- def initialize(node)
- items = []
- LocalVariableScopeEnumerator.each(node) do |*scope|
- items << scope
- end
- @items = items
- super(node)
- end
-
- # Test if local variable was first at given assignment
- #
- # @param [Parser::AST::Node] node
- #
- # @return [Boolean]
- #
- # @api private
- #
- def first_assignment?(node)
- name = node.children.first
- match(node) do |current, before|
- current.include?(name) && !before.include?(name)
- end
- end
-
- # Test if local variable is defined for given node
- #
- # @param [Parser::AST::Node] node
- # @param [Symbol] name
- #
- # @return [Boolean]
- #
- # @api private
- #
- def local_variable_defined_for_node?(node, name)
- match(node) do |current|
- current.include?(name)
- end
- end
-
- # Test if local variables where first assigned in body and read by conditional
- #
- # @param [Parser::AST::Node] body
- # @param [Parser::AST::Node] condition
- #
- # @api private
- #
- def first_assignment_in?(left, right)
- condition_reads = AST.local_variable_reads(right)
-
- candidates = AST.local_variable_assignments(left).select do |node|
- condition_reads.include?(node.children.first)
- end
-
- candidates.any?(&public_method(:first_assignment?))
- end
-
- private
-
- def match(needle)
- @items.each do |node, current, before|
- return yield(current, before) if node.equal?(needle)
- end
- end
-
- end # LocalVariableScope
-
- # Local variable scope enumerator
- class LocalVariableScopeEnumerator
- include Enumerable
-
- # Initialize object
- #
- # @return [undefined]
- #
- # @api private
- #
- def initialize
- @stack = [Set.new]
- end
-
- # Enumerate each node with its local variable scope
- #
- # @param [Parser::AST::Node] node
- #
- # @return [self]
- #
- # @api private
- #
- def self.each(node, &block)
- new.each(node, &block)
- self
- end
-
- # Enumerate local variable scope scope
- #
- # @return [self]
- # if block given
- #
- # @return [Enumerator<Array<Symbol>>>]
- # otherwise
- #
- # @api private
- #
- def each(node, &block)
- visit(node, &block)
- end
-
- private
-
- def current
- @stack.last
- end
-
- def visit(node, &block)
- before = current.dup
- enter(node)
- yield node, current.dup, before
- node.children.each do |child|
- visit(child, &block) if child.is_a?(Parser::AST::Node)
- end
- leave(node)
- end
-
- def enter(node)
- case node.type
- when *RESET_NODES
- push_reset
- when ASSIGN_NODES
- define(node.children.first)
- when *INHERIT_NODES
- push_inherit
- end
- end
-
- def leave(node)
- pop if CLOSE_NODES.include?(node.type)
- end
-
- def define(name)
- current << name
- end
-
- def push_reset
- @stack << Set.new
- end
-
- def push_inherit
- @stack << current.dup
- end
-
- def pop
- @stack.pop
- end
-
- end # LocalVariableScopeEnumerator
- end # AST
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/buffer.rb | @@ -1,143 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
-
- # Buffer used to emit into
- class Buffer
-
- NL = "\n".freeze
-
- # Initialize object
- #
- # @return [undefined]
- #
- # @api private
- #
- def initialize
- @content = +''
- @indent = 0
- end
-
- # Append string
- #
- # @param [String] string
- #
- # @return [self]
- #
- # @api private
- #
- def append(string)
- if @content[-1].eql?(NL)
- prefix
- end
- write(string)
- self
- end
-
- # Append a string without an indentation prefix
- #
- # @param [String] string
- #
- # @return [self]
- #
- # @api private
- #
- def append_without_prefix(string)
- write(string)
- self
- end
-
- # Increase indent
- #
- # @return [self]
- #
- # @api private
- #
- def indent
- @indent += 1
- self
- end
-
- # Decrease indent
- #
- # @return [self]
- #
- # @api private
- #
- def unindent
- @indent -= 1
- self
- end
-
- # Write newline
- #
- # @return [self]
- #
- # @api private
- #
- def nl
- write(NL)
- self
- end
-
- def root_indent
- before = @indent
- @indent = 0
- yield
- @indent = before
- end
-
- # Test for a fresh line
- #
- # @return [Boolean]
- #
- # @api private
- #
- def fresh_line?
- @content.empty? || @content[-1].eql?(NL)
- end
-
- # Return content of buffer
- #
- # @return [String]
- #
- # @api private
- #
- def content
- @content.dup.freeze
- end
-
- # Capture the content written to the buffer within the block
- #
- # @return [String]
- #
- # @api private
- #
- def capture_content
- size_before = @content.size
- yield
- @content[size_before..-1]
- end
-
- # Write raw fragment to buffer
- #
- # Does not do indentation logic.
- #
- # @param [String] fragment
- #
- # @return [self]
- def write(fragment)
- @content << fragment
- self
- end
-
- private
-
- INDENT_SPACE = ' '.freeze
-
- def prefix
- write(INDENT_SPACE * @indent)
- end
-
- end # Buffer
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/cli.rb | @@ -1,179 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # Unparser CLI implementation
- class CLI
-
- EXIT_SUCCESS = 0
- EXIT_FAILURE = 1
-
- class Target
- include AbstractType
-
- # Path target
- class Path < self
- include Concord.new(:path)
-
- # Validation for this target
- #
- # @return [Validation]
- def validation
- Validation.from_path(path)
- end
-
- # Literal for this target
- #
- # @return [Validation]
- def literal_validation
- Validation::Literal.from_path(path)
- end
- end
-
- # String target
- class String
- include Concord.new(:string)
-
- # Validation for this target
- #
- # @return [Validation]
- def validation
- Validation.from_string(string)
- end
-
- # Literal for this target
- #
- # @return [Validation]
- def literal_validation
- Validation::Literal.from_string(path)
- end
- end # String
- end # Target
-
- private_constant(*constants(false))
-
- # Run CLI
- #
- # @param [Array<String>] arguments
- #
- # @return [Integer]
- # the exit status
- #
- # @api private
- #
- def self.run(*arguments)
- new(*arguments).exit_status
- end
-
- # Initialize object
- #
- # @param [Array<String>] arguments
- #
- # @return [undefined]
- #
- # @api private
- def initialize(arguments)
- @ignore = Set.new
- @targets = []
-
- @fail_fast = false
- @success = true
- @validation = :validation
- @verbose = false
-
- opts = OptionParser.new do |builder|
- add_options(builder)
- end
-
- opts.parse!(arguments).each do |name|
- @targets.concat(targets(name))
- end
- end
-
- # Add options
- #
- # @param [OptionParser] builder
- #
- # @return [undefined]
- #
- # @api private
- #
- # rubocop:disable Metrics/MethodLength
- def add_options(builder)
- builder.banner = 'usage: unparse [options] FILE [FILE]'
- builder.separator('')
- builder.on('-e', '--evaluate SOURCE') do |source|
- @targets << Target::String.new(source)
- end
- builder.on('--start-with FILE') do |path|
- @start_with = targets(path).first
- end
- builder.on('-v', '--verbose') do
- @verbose = true
- end
- builder.on('-l', '--literal') do
- @validation = :literal_validation
- end
- builder.on('--ignore FILE') do |file|
- @ignore.merge(targets(file))
- end
- builder.on('--fail-fast') do
- @fail_fast = true
- end
- end
- # rubocop:enable Metrics/MethodLength
-
- # Return exit status
- #
- # @return [Integer]
- #
- # @api private
- #
- def exit_status
- effective_targets.each do |target|
- process_target(target)
- break if @fail_fast && !@success
- end
-
- @success ? EXIT_SUCCESS : EXIT_FAILURE
- end
-
- private
-
- def process_target(target)
- validation = target.public_send(@validation)
- if validation.success?
- puts validation.report if @verbose
- puts "Success: #{validation.identification}"
- else
- puts validation.report
- puts "Error: #{validation.identification}"
- @success = false
- end
- end
-
- def effective_targets
- if @start_with
- reject = true
- @targets.reject do |targets|
- if reject && targets.eql?(@start_with)
- reject = false
- end
-
- reject
- end
- else
- @targets
- end.reject(&@ignore.method(:include?))
- end
-
- def targets(file_name)
- if File.directory?(file_name)
- Dir.glob(File.join(file_name, '**/*.rb')).sort
- elsif File.file?(file_name)
- [file_name]
- else
- Dir.glob(file_name).sort
- end.map { |file| Target::Path.new(Pathname.new(file)) }
- end
- end # CLI
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/color.rb | @@ -1,39 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # Class to colorize strings
- class Color
- include Adamantium, Concord.new(:code)
-
- # Format text with color
- #
- # @param [String] text
- #
- # @return [String]
- def format(text)
- "\e[#{code}m#{text}\e[0m"
- end
-
- NONE = Class.new(self) do
-
- # Format null color
- #
- # @param [String] text
- #
- # @return [String]
- # the argument string
- def format(text)
- text
- end
-
- private
-
- def initialize; end
-
- end.new
-
- RED = Color.new(31)
- GREEN = Color.new(32)
-
- end # Color
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/comments.rb | @@ -1,130 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
-
- # Holds the comments that remain to be emitted
- class Comments
-
- # Proxy to singleton
- #
- # NOTICE:
- # Delegating to stateless helpers is a pattern I saw many times in our code.
- # Maybe we should make another helper module? include SingletonDelegator.new(:source_range) ?
- #
- # @return [undefined]
- #
- # @api private
- #
- def source_range(*arguments)
- self.class.source_range(*arguments)
- end
-
- # Initialize object
- #
- # @param [Array] comments
- #
- # @return [undefined]
- #
- # @api private
- #
- def initialize(comments)
- @comments = comments.dup
- @last_range_consumed = nil
- end
-
- # Consume part or all of the node
- #
- # @param [Parser::AST::Node] node
- # @param [Symbol] source_part
- #
- # @return [undefined]
- #
- # @api private
- #
- def consume(node, source_part = :expression)
- range = source_range(node, source_part)
- @last_range_consumed = range if range
- end
-
- # Take end-of-line comments
- #
- # @return [Array]
- #
- # @api private
- #
- def take_eol_comments
- return EMPTY_ARRAY unless @last_range_consumed
-
- comments = take_up_to_line(@last_range_consumed.end.line)
- unshift_documents(comments)
- end
-
- # Take all remaining comments
- #
- # @return [Array]
- #
- # @api private
- #
- def take_all
- take_while { true }
- end
-
- # Take comments appear in the source before the specified part of the node
- #
- # @param [Parser::AST::Node] node
- # @param [Symbol] source_part
- #
- # @return [Array]
- #
- # @api private
- #
- def take_before(node, source_part)
- range = source_range(node, source_part)
- if range
- take_while { |comment| comment.location.expression.end_pos <= range.begin_pos }
- else
- EMPTY_ARRAY
- end
- end
-
- # Return source location part
- #
- # FIXME: This method should not be needed. It does to much inline signalling.
- #
- # @param [Parser::AST::Node] node
- # @param [Symbol] part
- #
- # @return [Parser::Source::Range]
- # if present
- #
- # @return [nil]
- # otherwise
- #
- # @api private
- #
- # :reek:ManualDispatch
- #
- def self.source_range(node, part)
- location = node.location
- location.public_send(part) if location.respond_to?(part)
- end
-
- private
-
- def take_while
- number_to_take = @comments.index { |comment| !yield(comment) } || @comments.size
- @comments.shift(number_to_take)
- end
-
- def take_up_to_line(line)
- take_while { |comment| comment.location.expression.line <= line }
- end
-
- def unshift_documents(comments)
- doc_comments, other_comments = comments.partition(&:document?)
- doc_comments.reverse_each { |comment| @comments.unshift(comment) }
- other_comments
- end
-
- end # Comments
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/concord.rb | @@ -1,114 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # A mixin to define a composition
- #
- # Original code before vendoring and reduction from: https://github.com/mbj/concord.
- class Concord < Module
- include Adamantium, Equalizer.new(:names)
-
- # The maximum number of objects the hosting class is composed of
- MAX_NR_OF_OBJECTS = 3
-
- # Return names
- #
- # @return [Enumerable<Symbol>]
- #
- # @api private
- #
- attr_reader :names
-
- private
-
- # Initialize object
- #
- # @return [undefined]
- #
- # @api private
- #
- # rubocop:disable Lint/MissingSuper
- def initialize(*names)
- if names.length > MAX_NR_OF_OBJECTS
- fail "Composition of more than #{MAX_NR_OF_OBJECTS} objects is not allowed"
- end
-
- @names = names
- define_initialize
- define_readers
- define_equalizer
- end
- # rubocop:enable Lint/MissingSuper
-
- # Define equalizer
- #
- # @return [undefined]
- #
- # @api private
- #
- def define_equalizer
- include(Equalizer.new(*names))
- end
-
- # Define readers
- #
- # @return [undefined]
- #
- # @api private
- #
- def define_readers
- attribute_names = names
- attr_reader(*attribute_names)
-
- protected(*attribute_names) if attribute_names.any?
- end
-
- # Define initialize method
- #
- # @return [undefined]
- #
- # @api private
- #
- #
- def define_initialize
- ivars = instance_variable_names
- size = names.size
-
- define_method :initialize do |*args|
- args_size = args.size
- unless args_size.equal?(size)
- fail ArgumentError, "wrong number of arguments (#{args_size} for #{size})"
- end
-
- ivars.zip(args) { |ivar, arg| instance_variable_set(ivar, arg) }
- end
- end
-
- # Return instance variable names
- #
- # @return [String]
- #
- # @api private
- #
- def instance_variable_names
- names.map { |name| "@#{name}" }
- end
-
- # Mixin for public attribute readers
- class Public < self
-
- # Hook called when module is included
- #
- # @param [Class,Module] descendant
- #
- # @return [undefined]
- #
- # @api private
- #
- def included(descendant)
- names.each do |name|
- descendant.__send__(:public, name)
- end
- end
- end # Public
- end # Concord
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/constants.rb | @@ -1,71 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # All unparser constants maybe included in other libraries.
- module Constants
-
- # All unary operators of the ruby language
- UNARY_OPERATORS = %i[
- ! ~ -@ +@
- ].to_set.freeze
-
- # All binary operators of the ruby language
- BINARY_OPERATORS = %i[
- + - * / & | && || << >> ==
- === != <= < <=> > >= =~ !~ ^
- ** %
- ].to_set.freeze
-
- # Keywords
- K_DO = 'do'
- K_DEF = 'def'
- K_END = 'end'
- K_BEGIN = 'begin'
- K_CASE = 'case'
- K_CLASS = 'class'
- K_SELF = 'self'
- K_ENSURE = 'ensure'
- K_DEFINE = 'define'
- K_MODULE = 'module'
- K_RESCUE = 'rescue'
- K_RETURN = 'return'
- K_UNDEF = 'undef'
- K_DEFINED = 'defined?'
- K_PREEXE = 'BEGIN'
- K_POSTEXE = 'END'
- K_SUPER = 'super'
- K_BREAK = 'break'
- K_RETRY = 'retry'
- K_REDO = 'redo'
- K_NEXT = 'next'
- K_FALSE = 'false'
- K_TRUE = 'true'
- K_IF = 'if'
- K_AND = 'and'
- K_ALIAS = 'alias'
- K_ELSE = 'else'
- K_ELSIF = 'elsif'
- K_FOR = 'for'
- K_NIL = 'nil'
- K_NOT = 'not'
- K_IN = 'in'
- K_OR = 'or'
- K_UNLESS = 'unless'
- K_WHEN = 'when'
- K_WHILE = 'while'
- K_UNTIL = 'until'
- K_YIELD = 'yield'
- K_ENCODING = '__ENCODING__'
- K_EEND = '__END__'
- K_FILE = '__FILE__'
- K_THEN = 'then'
-
- KEYWORDS = constants.each_with_object([]) do |name, keywords|
- value = const_get(name).freeze
- next unless name.to_s.start_with?('K_')
-
- keywords << value.to_sym
- end.to_set.freeze
-
- end # Constants
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/diff.rb | @@ -1,98 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # Class to create diffs from source code
- class Diff
- include Adamantium, Concord.new(:old, :new)
-
- ADDITION = '+'
- DELETION = '-'
- NEWLINE = "\n"
-
- # Unified source diff between old and new
- #
- # @return [String]
- # if there is exactly one diff
- #
- # @return [nil]
- # otherwise
- def diff
- return if diffs.empty?
-
- minimized_hunk.diff(:unified) + NEWLINE
- end
- memoize :diff
-
- # Colorized unified source diff between old and new
- #
- # @return [String]
- # if there is a diff
- #
- # @return [nil]
- # otherwise
- def colorized_diff
- return unless diff
-
- diff.lines.map(&self.class.method(:colorize_line)).join
- end
- memoize :colorized_diff
-
- # Build new object from source strings
- #
- # @param [String] old
- # @param [String] new
- #
- # @return [Diff]
- def self.build(old, new)
- new(lines(old), lines(new))
- end
-
- # Break up source into lines
- #
- # @param [String] source
- #
- # @return [Array<String>]
- def self.lines(source)
- source.lines.map(&:chomp)
- end
- private_class_method :lines
-
- private
-
- def diffs
- ::Diff::LCS.diff(old, new)
- end
-
- def hunks
- diffs.map do |diff|
- ::Diff::LCS::Hunk.new(old.map(&:dup), new, diff, max_length, 0)
- end
- end
-
- def minimized_hunk
- head, *tail = hunks
-
- tail.reduce(head) do |left, right|
- right.merge(left)
- right
- end
- end
-
- def max_length
- [old, new].map(&:length).max
- end
-
- def self.colorize_line(line)
- case line[0]
- when ADDITION
- Color::GREEN
- when DELETION
- Color::RED
- else
- Color::NONE
- end.format(line)
- end
- private_class_method :colorize_line
-
- end # Diff
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/dsl.rb | @@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- # DSL to help defining emitters
- module DSL
-
- private
-
- def define_remaining_children(names)
- range = names.length..-1
- define_method(:remaining_children) do
- children[range]
- end
- private :remaining_children
- end
-
- def define_child(name, index)
- define_method(name) do
- children.at(index)
- end
- private name
- end
-
- def define_group(name, range)
- define_method(name) do
- children[range]
- end
- private(name)
- memoize(name)
- end
-
- def children(*names)
- define_remaining_children(names)
-
- names.each_with_index do |name, index|
- define_child(name, index)
- end
- end
-
- end # DSL
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/either.rb | @@ -1,153 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- module RequireBlock
-
- private
-
- # Raise error unless block is provided
- #
- # @raise [MissingBlockError]
- # if no block is given
- #
- # @return [self]
- def require_block
- fail LocalJumpError unless block_given?
-
- self
- end
- end # RequireBLock
-
- class Either
- include(
- Adamantium,
- Concord.new(:value),
- RequireBlock
- )
-
- # Execute block and wrap error in left
- #
- # @param [Class<Exception>] exception
- #
- # @return [Either<Exception, Object>]
- def self.wrap_error(*exceptions)
- Right.new(yield)
- rescue *exceptions => error
- Left.new(error)
- end
-
- # Test for left constructor
- #
- # @return [Boolean]
- def left?
- instance_of?(Left)
- end
-
- # Test for right constructor
- #
- # @return [Boolean]
- def right?
- instance_of?(Right)
- end
-
- class Left < self
- # Evaluate functor block
- #
- # @return [Either::Left<Object>]
- def fmap(&block)
- require_block(&block)
- end
-
- # Evaluate applicative block
- #
- # @return [Either::Left<Object>]
- def bind(&block)
- require_block(&block)
- end
-
- # Unwrap value from left
- #
- # @return [Object]
- def from_left
- value
- end
-
- # Unwrap value from right
- #
- # @return [Object]
- #
- def from_right
- if block_given?
- yield(value)
- else
- fail "Expected right value, got #{inspect}"
- end
- end
-
- # Map over left value
- #
- # @return [Either::Right<Object>]
- def lmap
- Left.new(yield(value))
- end
-
- # Evaluate left side of branch
- #
- # @param [#call] left
- # @param [#call] _right
- def either(left, _right)
- left.call(value)
- end
- end # Left
-
- class Right < self
- # Evaluate functor block
- #
- # @return [Either::Right<Object>]
- def fmap
- Right.new(yield(value))
- end
-
- # Evaluate applicative block
- #
- # @return [Either<Object>]
- def bind
- yield(value)
- end
-
- # Unwrap value from left
- #
- # @return [Object]
- #
- def from_left
- if block_given?
- yield(value)
- else
- fail "Expected left value, got #{inspect}"
- end
- end
-
- # Unwrap value from right
- #
- # @return [Object]
- def from_right
- value
- end
-
- # Map over left value
- #
- # @return [Either::Right<Object>]
- def lmap(&block)
- require_block(&block)
- end
-
- # Evaluate right side of branch
- #
- # @param [#call] _left
- # @param [#call] right
- def either(_left, right)
- right.call(value)
- end
- end # Right
- end # Either
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter.rb | @@ -1,95 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- UnknownNodeError = Class.new(ArgumentError)
-
- # Emitter base class
- class Emitter
- include Adamantium, AbstractType, Constants, Generation, NodeHelpers
- include Anima.new(:buffer, :comments, :node, :local_variable_scope)
-
- public :node
-
- extend DSL
-
- # Registry for node emitters
- REGISTRY = {} # rubocop:disable Style/MutableConstant
-
- NO_INDENT = %i[ensure rescue].freeze
-
- module LocalVariableRoot
- # Return local variable root
- #
- # @return [Parser::AST::Node]
- #
- # @api private
- #
- def local_variable_scope
- AST::LocalVariableScope.new(node)
- end
-
- def self.included(descendant)
- descendant.class_eval do
- memoize :local_variable_scope
- end
- end
- end # LocalVariableRoot
-
- def node_type
- node.type
- end
-
- # Register emitter for type
- #
- # @param [Symbol] types
- #
- # @return [undefined]
- #
- # @api private
- #
- def self.handle(*types)
- types.each do |type|
- fail "Handler for type: #{type} already registered" if REGISTRY.key?(type)
-
- REGISTRY[type] = self
- end
- end
- private_class_method :handle
-
- def emit_mlhs
- dispatch
- end
-
- # Return emitter
- #
- # @return [Emitter]
- #
- # @api private
- #
- # rubocop:disable Metrics/ParameterLists
- def self.emitter(buffer:, comments:, node:, local_variable_scope:)
- type = node.type
-
- klass = REGISTRY.fetch(type) do
- fail UnknownNodeError, "Unknown node type: #{type.inspect}"
- end
-
- klass.new(
- buffer: buffer,
- comments: comments,
- local_variable_scope: local_variable_scope,
- node: node
- )
- end
- # rubocop:enable Metrics/ParameterLists
-
- # Dispatch node write as statement
- #
- # @return [undefined]
- #
- # @api private
- #
- abstract_method :dispatch
-
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/alias.rb | @@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for alias nodes
- class Alias < self
-
- handle :alias
-
- children :target, :source
-
- private
-
- def dispatch
- write('alias ')
- visit(target)
- ws
- visit(source)
- end
-
- end # Alias
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/args.rb | @@ -1,45 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Arguments emitter
- class Args < self
- def emit_block_arguments
- delimited(normal_arguments)
-
- write(',') if normal_arguments.one? && n_arg?(normal_arguments.first)
-
- emit_shadowargs
- end
-
- def emit_def_arguments
- delimited(normal_arguments)
- end
-
- def emit_lambda_arguments
- delimited(normal_arguments)
- emit_shadowargs
- end
-
- private
-
- def emit_shadowargs
- return if shadowargs.empty?
-
- write('; ')
- delimited(shadowargs)
- end
-
- def normal_arguments
- children.reject(&method(:n_shadowarg?))
- end
- memoize :normal_arguments
-
- def shadowargs
- children.select(&method(:n_shadowarg?))
- end
- memoize :shadowargs
-
- end # Arguments
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/argument.rb | @@ -1,136 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for block and kwrestarg arguments
- class Morearg < self
- MAP = {
- blockarg: '&',
- kwrestarg: '**'
- }.freeze
-
- handle(*MAP.keys)
-
- children :name
-
- private
-
- def dispatch
- write(MAP.fetch(node_type), name.to_s)
- end
-
- end # Blockarg
-
- # Optional argument emitter
- class Optarg < self
- handle :optarg
-
- children :name, :value
-
- private
-
- def dispatch
- write(name.to_s, ' = ')
- visit(value)
- end
- end
-
- # Optional keyword argument emitter
- class KeywordOptional < self
- handle :kwoptarg
-
- children :name, :value
-
- private
-
- def dispatch
- write(name.to_s, ': ')
- visit(value)
- end
-
- end # KeywordOptional
-
- # Keyword argument emitter
- class Kwarg < self
- handle :kwarg
-
- children :name
-
- private
-
- def dispatch
- write(name.to_s, ':')
- end
-
- end # Restarg
-
- # Rest argument emitter
- class Restarg < self
- handle :restarg
-
- children :name
-
- private
-
- def dispatch
- write('*', name.to_s)
- end
-
- end # Restarg
-
- # Argument emitter
- class Argument < self
- handle :arg, :shadowarg
-
- children :name
-
- private
-
- def dispatch
- write(name.to_s)
- end
-
- end # Argument
-
- # Progarg emitter
- class Procarg < self
- handle :procarg0
-
- PARENS = %i[restarg mlhs].freeze
-
- private
-
- def dispatch
- if needs_parens?
- parentheses do
- delimited(children)
- end
- else
- delimited(children)
- end
- end
-
- def needs_parens?
- children.length > 1 || children.any? do |node|
- PARENS.include?(node.type)
- end
- end
- end
-
- # Block pass node emitter
- class BlockPass < self
- handle :block_pass
-
- children :name
-
- private
-
- def dispatch
- write('&')
- visit(name)
- end
-
- end # BlockPass
-
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/array.rb | @@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Array literal emitter
- class Array < self
- handle :array
-
- def emit_heredoc_reminders
- emitters.each(&:emit_heredoc_reminders)
- end
-
- private
-
- def dispatch
- parentheses('[', ']') do
- delimited(emitters, &:write_to_buffer)
- end
- end
-
- def emitters
- children.map(&method(:emitter))
- end
- memoize :emitters
- end # Array
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/array_pattern.rb | @@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for array patterns
- class ArrayPattern < self
-
- handle :array_pattern
- handle :array_pattern_with_tail
-
- private
-
- def dispatch
- write('[')
- delimited(children, &method(:emit_member))
- write(', ') if node_type.equal?(:array_pattern_with_tail)
- write(']')
- end
-
- def emit_member(node)
- if n_match_rest?(node)
- writer_with(MatchRest, node).emit_array_pattern
- else
- visit(node)
- end
- end
- end # Pin
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/assignment.rb | @@ -1,76 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
-
- # Base class for assignment emitters
- class Assignment < self
- BINARY_OPERATOR = %i[and or].freeze
-
- def symbol_name
- true
- end
-
- def emit_heredoc_reminders
- return unless right
-
- emitter(right).emit_heredoc_reminders
- end
-
- private
-
- def dispatch
- emit_left
- emit_right
- end
-
- def emit_right
- return unless right
-
- write(' = ')
-
- if BINARY_OPERATOR.include?(right.type)
- writer_with(Writer::Binary, right).emit_operator
- else
- visit(right)
- end
- end
-
- abstract_method :emit_left
-
- # Variable assignment emitter
- class Variable < self
-
- handle :lvasgn, :ivasgn, :cvasgn, :gvasgn
-
- children :name, :right
-
- private
-
- def emit_left
- write(name.to_s)
- end
-
- end # Variable
-
- # Constant assignment emitter
- class Constant < self
-
- handle :casgn
-
- children :base, :name, :right
-
- private
-
- def emit_left
- if base
- visit(base)
- write('::') unless n_cbase?(base)
- end
- write(name.to_s)
- end
-
- end # Constant
- end # Assignment
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/begin.rb | @@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
-
- # Emitter for begin nodes
- class Begin < self
- handle :begin
- children :body
-
- def emit_heredoc_reminders
- children.each do |child|
- emitter(child).emit_heredoc_reminders
- end
- end
-
- private
-
- def dispatch
- parentheses do
- delimited(children, '; ')
- end
- end
- end # Begin
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/binary.rb | @@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Non send binary operator / keyword emitter
- class Binary < self
- handle :and, :or
-
- private
-
- def dispatch
- writer.dispatch
- end
-
- def writer
- writer_with(Writer::Binary, node)
- end
- memoize :writer
- end # Binary
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/block.rb | @@ -1,87 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
-
- # Block emitter
- class Block < self
- handle :block, :numblock
-
- children :target, :arguments, :body
-
- private
-
- def dispatch
- emit_target
- ws
- write_open
- target_writer.emit_heredoc_reminders if n_send?(target)
- emit_block_arguments unless n_lambda?(target)
- emit_optional_body_ensure_rescue(body)
- write_close
- end
-
- def need_do?
- body && (n_rescue?(body) || n_ensure?(body))
- end
-
- def write_open
- if need_do?
- write('do')
- else
- write('{')
- end
- end
-
- def write_close
- if need_do?
- k_end
- else
- write('}')
- end
- end
-
- def target_writer
- writer_with(Writer::Send::Regular, target)
- end
- memoize :target_writer
-
- def emit_target
- case target.type
- when :send
- emit_send_target
- when :lambda
- visit(target)
- emit_lambda_arguments unless node.type.equal?(:numblock)
- else
- visit(target)
- end
- end
-
- def emit_send_target
- target_writer.emit_receiver
- target_writer.emit_selector
- target_writer.emit_arguments_without_heredoc_body
- end
-
- def emit_lambda_arguments
- parentheses { writer_with(Args, arguments).emit_lambda_arguments }
- end
-
- def numblock?
- node.type.equal?(:numblock)
- end
-
- def emit_block_arguments
- return if numblock? || arguments.children.empty?
-
- ws
-
- parentheses('|', '|') do
- writer_with(Args, arguments).emit_block_arguments
- end
- end
-
- end # Block
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/case.rb | @@ -1,63 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for case nodes
- class Case < self
- handle :case
-
- children :condition
- define_group :whens, 1..-2
-
- private
-
- def dispatch
- write('case')
- emit_condition
- emit_whens
- emit_else
- k_end
- end
-
- def emit_else
- else_branch = children.last
- return unless else_branch
-
- write('else')
- emit_body(else_branch)
- end
-
- def emit_whens
- nl
- whens.each(&method(:visit))
- end
-
- def emit_condition
- return unless condition
-
- ws
- visit(condition)
- end
- end # Case
-
- # Emitter for when nodes
- class When < self
- handle :when
-
- define_group :captures, 0..-2
-
- private
-
- def dispatch
- write('when ')
- emit_captures
- emit_optional_body(children.last)
- end
-
- def emit_captures
- delimited(captures)
- end
-
- end # When
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/case_guard.rb | @@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for case guards
- class CaseGuard < self
-
- handle :if_guard, :unless_guard
-
- MAP = {
- if_guard: 'if',
- unless_guard: 'unless'
- }.freeze
-
- children :condition
-
- private
-
- def dispatch
- write(MAP.fetch(node_type))
- ws
- visit(condition)
- end
-
- end # UnlessGuard
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/case_match.rb | @@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for case matches
- class CaseMatch < self
-
- handle :case_match
-
- children :target
-
- define_group :patterns, 1..-2
-
- private
-
- def else_branch
- children.last
- end
-
- def dispatch
- write('case ')
- visit(target)
- nl
- patterns.each(&method(:visit))
- nl unless buffer.fresh_line?
- emit_else_branch
- k_end
- end
-
- def emit_else_branch
- if else_branch
- write('else')
- emit_body(else_branch) unless n_empty_else?(else_branch)
- nl unless buffer.fresh_line?
- end
- end
-
- end # CaseMatch
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/cbase.rb | @@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for toplevel constant reference nodes
- class CBase < self
- handle :cbase
-
- private
-
- # Perform dispatch
- #
- # @return [undefined]
- #
- # @api private
- #
- def dispatch
- write('::')
- end
-
- end # CBase
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/class.rb | @@ -1,49 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for class nodes
- class Class < self
- include LocalVariableRoot
-
- handle :class
-
- children :name, :superclass, :body
-
- private
-
- def dispatch
- write('class ')
- visit(name)
- emit_superclass
- emit_optional_body(body)
- k_end
- end
-
- def emit_superclass
- return unless superclass
-
- write(' < ')
- visit(superclass)
- end
-
- end # Class
-
- # Emitter for sclass nodes
- class SClass < self
- handle :sclass
-
- children :object, :body
-
- private
-
- def dispatch
- write('class << ')
- visit(object)
- emit_optional_body(body)
- k_end
- end
-
- end # SClass
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/const_pattern.rb | @@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for const pattern node
- class ConstPattern < self
-
- handle :const_pattern
-
- children :const, :pattern
-
- private
-
- def dispatch
- visit(const)
- if n_hash_pattern?(pattern)
- emitter(pattern).emit_const_pattern
- else
- visit(pattern)
- end
- end
- end # ConstPattern
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/def.rb | @@ -1,78 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for def node
- class Def < self
- include LocalVariableRoot
-
- private
-
- abstract_method :emit_name
- private :emit_name
-
- abstract_method :body
- private :body
-
- def dispatch
- write('def ')
- emit_name
- emit_arguments
- emit_optional_body_ensure_rescue(body)
- k_end
- end
-
- def emit_arguments
- return if arguments.children.empty?
-
- parentheses do
- writer_with(Args, arguments).emit_def_arguments
- end
- end
-
- # Instance def emitter
- class Instance < self
- handle :def
-
- children :name, :arguments, :body
-
- private
-
- def emit_name
- write(name.to_s)
- end
-
- end # Instance
-
- # Emitter for defines on singleton
- class Singleton < self
-
- handle :defs
-
- children :subject, :name, :arguments, :body
-
- private
-
- def emit_name
- conditional_parentheses(!subject_without_parens?) do
- visit(subject)
- end
- write('.', name.to_s)
- end
-
- def subject_without_parens?
- case subject.type
- when :self
- true
- when :const
- !subject.children.first
- when :send
- receiver, _selector, *arguments = *subject
- !receiver && arguments.empty?
- end
- end
-
- end # Singleton
- end # Def
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/defined.rb | @@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for defined? nodes
- class Defined < self
- handle :defined?
-
- children :subject
-
- private
-
- def dispatch
- write('defined?')
- parentheses { visit(subject) }
- end
-
- end # Defined
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/dstr.rb | @@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Dynamic string emitter
- class DStr < self
-
- handle :dstr
-
- def emit_heredoc_reminders
- writer_with(Writer::DynamicString, node).emit_heredoc_reminder
- end
-
- private
-
- def dispatch
- writer_with(Writer::DynamicString, node).dispatch
- end
-
- end # DStr
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/dsym.rb | @@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Dynamic symbol literal emitter
- class DSym < self
- handle :dsym
-
- private
-
- def dispatch
- write(':"')
- children.each do |child|
- case child.type
- when :str
- emit_str_child(child)
- when :begin
- emit_begin_child(child)
- end
- end
- write('"')
- end
-
- def emit_str_child(value)
- string = value.children.first
- if string.end_with?("\n")
- write(string.inspect[1..-4])
- nl
- else
- write(string.inspect[1..-2])
- end
- end
-
- def emit_begin_child(component)
- write('#{')
- visit(unwrap_single_begin(component))
- write('}')
- end
- end # DSym
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/flipflop.rb | @@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for flip flops
- class FlipFlop < self
- MAP = {
- iflipflop: '..',
- eflipflop: '...'
- }.freeze
-
- SYMBOLS = {
- eflipflop: :tDOT3,
- iflipflop: :tDOT2
- }.freeze
-
- def symbol_name
- true
- end
-
- handle(*MAP.keys)
-
- children :left, :right
-
- private
-
- def dispatch
- visit(left)
- write(MAP.fetch(node.type))
- visit(right)
- end
- end # FlipFLop
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/float.rb | @@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emiter for float literals
- class Float < self
- handle :float
-
- children :value
-
- INFINITY = ::Float::INFINITY
- NEG_INFINITY = -::Float::INFINITY
-
- private
-
- def dispatch
- case value
- when INFINITY
- write('10e1000000000000000000')
- when NEG_INFINITY
- write('-10e1000000000000000000')
- else
- write(value.inspect)
- end
- end
-
- end # Float
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/flow_modifier.rb | @@ -1,42 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter control flow modifiers
- class FlowModifier < self
- MAP = {
- return: 'return',
- next: 'next',
- break: 'break'
- }.freeze
-
- private_constant(*constants(false))
-
- handle(*MAP.keys)
-
- def emit_heredoc_reminders
- children.each do |node|
- emitter(node).emit_heredoc_reminders
- end
- end
-
- private
-
- def dispatch
- write(MAP.fetch(node.type))
-
- if children.one? && n_if?(children.first)
- ws
- emitter(children.first).emit_ternary
- else
- emit_arguments unless children.empty?
- end
- end
-
- def emit_arguments
- ws
- delimited(children)
- end
- end # Return
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/for.rb | @@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for for nodes
- class For < self
- handle :for
-
- children :condition, :assignment, :body
-
- private
-
- def dispatch
- write('for ')
- emit_condition
- emit_optional_body(body)
- k_end
- end
-
- def emit_condition
- visit(condition)
- write(' in ')
- visit(assignment)
- write(' do')
- end
-
- end # For
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/hash.rb | @@ -1,44 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for Hash literals
- class Hash < self
- handle :hash
-
- def emit_last_argument_hash
- if children.empty?
- write('{}')
- else
- emit_hash_body
- end
- end
-
- def emit_heredoc_reminders
- children.each(&method(:emit_heredoc_reminder_member))
- end
-
- private
-
- def dispatch
- if children.empty?
- write('{}')
- else
- parentheses('{', '}') do
- write(' ')
- emit_hash_body
- write(' ')
- end
- end
- end
-
- def emit_heredoc_reminder_member(node)
- emitter(node.children.last).emit_heredoc_reminders
- end
-
- def emit_hash_body
- delimited(children)
- end
- end # Hash
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/hash_pattern.rb | @@ -1,67 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for hash patterns
- class HashPattern < self
-
- handle :hash_pattern
-
- def emit_const_pattern
- parentheses do
- emit_hash_body
- end
- end
-
- private
-
- def dispatch
- parentheses('{', '}') do
- emit_hash_body
- end
- end
-
- def emit_hash_body
- delimited(children, &method(:emit_member))
- end
-
- def emit_member(node)
- case node.type
- when :pair
- emit_pair(node)
- when :match_var
- emit_match_var(node)
- when :match_rest
- writer_with(MatchRest, node).emit_hash_pattern
- else
- visit(node)
- end
- end
-
- def emit_match_var(node)
- write_symbol_body(node.children.first)
- write(':')
- end
-
- def emit_pair(node)
- key, value = node.children
-
- if n_sym?(key)
- write_symbol_body(key.children.first)
- else
- visit(s(:dstr, *key))
- end
-
- write(':')
-
- ws
-
- visit(value)
- end
-
- def write_symbol_body(symbol)
- write(symbol.inspect[1..-1])
- end
- end # Pin
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/hookexe.rb | @@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Base class for pre and postexe emitters
- class Hookexe < self
-
- MAP = {
- preexe: 'BEGIN',
- postexe: 'END'
- }.freeze
-
- handle(*MAP.keys)
-
- children :body
-
- private
-
- def dispatch
- write(MAP.fetch(node.type), ' ')
- parentheses('{', '}') do
- emit_body(body)
- end
- end
-
- end # Hookexe
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/if.rb | @@ -1,80 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter if nodes
- class If < self
- handle :if
-
- children :condition, :if_branch, :else_branch
-
- def emit_ternary
- visit(condition)
- write(' ? ')
- visit(if_branch)
- write(' : ')
- visit(else_branch)
- end
-
- private
-
- def dispatch
- if postcondition?
- emit_postcondition
- else
- emit_normal
- end
- end
-
- def postcondition?
- return false unless if_branch.nil? ^ else_branch.nil?
-
- body = if_branch || else_branch
-
- local_variable_scope.first_assignment_in?(body, condition)
- end
-
- def emit_postcondition
- visit(if_branch || else_branch)
- write(' ', keyword, ' ')
- emit_condition
- end
-
- def emit_normal
- write(keyword, ' ')
- emit_condition
- emit_if_branch
- emit_else_branch
- k_end
- end
-
- def unless?
- !if_branch && else_branch
- end
-
- def keyword
- unless? ? 'unless' : 'if'
- end
-
- def emit_condition
- visit(condition)
- end
-
- def emit_if_branch
- if if_branch
- emit_body(if_branch)
- end
-
- nl if !if_branch && !else_branch
- end
-
- def emit_else_branch
- return unless else_branch
-
- write('else') unless unless?
- emit_body(else_branch)
- end
-
- end # If
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/in_match.rb | @@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for in pattern nodes
- class InMatch < self
-
- handle :in_match
-
- children :target, :pattern
-
- private
-
- def dispatch
- visit(target)
- write(' in ')
- visit(pattern)
- end
- end # InMatch
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/in_pattern.rb | @@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for in pattern nodes
- class InPattern < self
-
- handle :in_pattern
-
- children :target, :unless_guard, :branch, :else_branch
-
- private
-
- def dispatch
- write('in')
-
- ws
-
- visit(target)
-
- if unless_guard
- ws
- visit(unless_guard)
- end
-
- if branch
- ws
- write('then')
- emit_body(branch)
- else
- nl
- end
- end
- end # InPattern
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/index.rb | @@ -1,69 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for send to index references
- class Index < self
-
- private
-
- def dispatch
- emit_receiver
- emit_operation
- end
-
- def emit_receiver
- visit(first_child)
- end
-
- class Reference < self
- define_group(:indices, 1..-1)
-
- handle :index
-
- private
-
- def emit_operation
- parentheses('[', ']') do
- delimited(indices)
- end
- end
- end # Reference
-
- # Emitter for assign to index nodes
- class Assign < self
-
- handle :indexasgn
-
- VALUE_RANGE = (1..-2).freeze
- NO_VALUE_PARENT = %i[and_asgn op_asgn or_asgn].to_set.freeze
-
- private_constant(*constants(false))
-
- def emit_heredoc_reminders
- emitter(children.last).emit_heredoc_reminders
- end
-
- def dispatch
- emit_receiver
- emit_operation(children[VALUE_RANGE])
- write(' = ')
- visit(children.last)
- end
-
- def emit_mlhs
- emit_receiver
- emit_operation(children.drop(1))
- end
-
- private
-
- def emit_operation(indices)
- parentheses('[', ']') do
- delimited(indices)
- end
- end
- end # Assign
- end # Index
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/kwargs.rb | @@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- class Kwargs < self
- handle :kwargs
-
- def dispatch
- delimited(children)
- end
- end # Kwargs
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/kwbegin.rb | @@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for explicit begins
- class KWBegin < self
- handle :kwbegin
-
- private
-
- def dispatch
- write('begin')
-
- if children.one?
- emit_body_ensure_rescue(children.first)
- else
- indented do
- emit_multiple_body
- end
- end
-
- k_end
- end
-
- def emit_multiple_body
- emit_join(children, method(:emit_body_member), method(:nl))
- end
-
- end # KWBegin
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/lambda.rb | @@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for lambda nodes
- class Lambda < self
- handle :lambda
-
- private
-
- def dispatch
- write('->')
- end
-
- end # Lambda
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/masgn.rb | @@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for multiple assignment nodes
- class MASGN < self
- handle :masgn
-
- children :target, :source
-
- private
-
- def dispatch
- visit(target)
- write(' = ')
- visit(source)
- end
- end # MLHS
- end # Emitter
-end # Unaprser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/match.rb | @@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
-
- # Base class for special match node emitters
- class Match < self
- # Emitter for match with local variable assignment
- class Lvasgn < self
- handle :match_with_lvasgn
-
- children :regexp, :lvasgn
-
- private
-
- def dispatch
- visit(regexp)
- write(' =~ ')
- visit(lvasgn)
- end
-
- end # Lvasgn
-
- # Emitter for match current line
- class CurrentLine < self
- handle :match_current_line
-
- children :regexp
-
- private
-
- def dispatch
- visit(regexp)
- end
-
- end # CurrentLine
-
- end # Match
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/match_alt.rb | @@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for in pattern nodes
- class MatchAlt < self
-
- handle :match_alt
-
- children :left, :right
-
- private
-
- def dispatch
- visit(left)
- ws
- write('|')
- ws
- visit(right)
- end
- end # MatchAlt
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/match_as.rb | @@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for in pattern nodes
- class MatchAs < self
-
- handle :match_as
-
- children :left, :right
-
- private
-
- def dispatch
- visit(left)
- write(' => ')
- visit(right)
- end
- end # MatchAs
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/match_pattern.rb | @@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emitter for in pattern nodes
- class MatchPattern < self
-
- handle :match_pattern
- handle :match_pattern_p
-
- children :target, :pattern
-
- private
-
- def dispatch
- visit(target)
- write(' in ')
- visit(pattern)
- end
- end # InPattern
- end # Emitter
-end # Unparser | true |
Other | Homebrew | brew | 1537e2eccdede455de4c802da7510cc81d1bab52.json | Ignore new dependencies | Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/unparser-0.6.0/lib/unparser/emitter/match_rest.rb | @@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-module Unparser
- class Emitter
- # Emiter for match rest nodes
- class MatchRest < self
- children :match_var
-
- def emit_array_pattern
- write('*')
- emit_match_var
- end
-
- def emit_hash_pattern
- write('**')
- emit_match_var
- end
-
- private
-
- def emit_match_var
- visit(match_var) if match_var
- end
- end # MatchRest
- end # Emitter
-end # Unparser | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.