module SyntaxTree
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/syntax_tree.rbs module SyntaxTree def self.parse: (String source) -> untyped end
def self.format(
def self.format( source, maxwidth = DEFAULT_PRINT_WIDTH, base_indentation = DEFAULT_INDENTATION, options: Formatter::Options.new ) format_node( source, parse(source), maxwidth, base_indentation, options: options ) end
def self.format_file(
def self.format_file( filepath, maxwidth = DEFAULT_PRINT_WIDTH, base_indentation = DEFAULT_INDENTATION, options: Formatter::Options.new ) format(read(filepath), maxwidth, base_indentation, options: options) end
def self.format_node(
def self.format_node( source, node, maxwidth = DEFAULT_PRINT_WIDTH, base_indentation = DEFAULT_INDENTATION, options: Formatter::Options.new ) formatter = Formatter.new(source, [], maxwidth, options: options) node.format(formatter) formatter.flush(base_indentation) formatter.output.join end
def self.index(source)
method definitions. Used to quickly provide indexing capability for IDEs or
Indexes the given source code to return a list of all class, module, and
def self.index(source) Index.index(source) end
def self.index_file(filepath)
definitions. Used to quickly provide indexing capability for IDEs or
Indexes the given file to return a list of all class, module, and method
def self.index_file(filepath) Index.index_file(filepath) end
def self.mutation
def self.mutation visitor = MutationVisitor.new yield visitor visitor end
def self.parse(source)
Experimental RBS support (using type sampling data from the type_fusion
project).
def self.parse: (String source) -> untyped
This signature was generated using 1 sample from 1 application.
def self.parse(source) parser = Parser.new(source) response = parser.parse response unless parser.error? end
def self.parse_file(filepath)
def self.parse_file(filepath) parse(read(filepath)) end
def self.read(filepath)
Returns the source from the given filepath taking into account any potential
def self.read(filepath) encoding = File.open(filepath, "r") do |file| break Encoding.default_external if file.eof? header = file.readline header += file.readline if !file.eof? && header.start_with?("#!") Ripper.new(header).tap(&:parse).encoding end File.read(filepath, encoding: encoding) end
def self.register_handler(extension, handler)
This is a hook provided so that plugins can register themselves as the
def self.register_handler(extension, handler) HANDLERS[extension] = handler end
def self.search(source, query, &block)
Searches through the given source using the given pattern and yields each
def self.search(source, query, &block) pattern = Pattern.new(query).compile program = parse(source) Search.new(pattern).scan(program, &block) end
def self.search_file(filepath, query, &block)
Searches through the given file using the given pattern and yields each
def self.search_file(filepath, query, &block) search(read(filepath), query, &block) end