Module: Wool::SexpAnalysis

Extended by:
ModuleExtensions
Included in:
Warning
Defined in:
lib/wool/analysis/sexp_analysis.rb,
lib/wool/analysis/scope.rb,
lib/wool/analysis/symbol.rb,
lib/wool/analysis/visitor.rb,
lib/wool/analysis/protocols.rb,
lib/wool/analysis/signature.rb,
lib/wool/analysis/wool_class.rb,
lib/wool/analysis/annotations.rb,
lib/wool/analysis/protocol_registry.rb,
lib/wool/analysis/annotations/next_annotation.rb,
lib/wool/analysis/annotations/scope_annotation.rb,
lib/wool/analysis/annotations/parent_annotation.rb

Overview

This is a set of methods that get provided to Warnings so they can perform parse-tree analysis of their bodies.

Defined Under Namespace

Modules: BasicAnnotation, NextPrevAnnotation, ParentAnnotation, ProtocolRegistry, Protocols, ScopeAnnotation, Visitor Classes: Scope, Sexp, Signature, Symbol, WoolClass, WoolMethod

Instance Method Summary collapse

Methods included from ModuleExtensions

attr_accessor_with_default, cattr_accessor, cattr_accessor_with_default, cattr_get_and_setter, cattr_reader, cattr_writer

Instance Method Details

#find_sexps(type, tree = self.parse(self.body)) ⇒ Array<Sexp>

Finds all sexps of the given type in the given Sexp tree.

Parameters:

  • type (Symbol)

    the type of sexp to search for

  • tree (Sexp) (defaults to: self.parse(self.body))

    (self.parse(self.body)) The tree to search in. Leave blank to search the entire body.

Returns:

  • (Array<Sexp>)

    all sexps in the input tree (or whole body) that are of the given type.



90
91
92
93
94
95
96
# File 'lib/wool/analysis/sexp_analysis.rb', line 90

def find_sexps(type, tree = self.parse(self.body))
  result = tree[0] == type ? [tree] : []
  tree.each do |node|
    result.concat find_sexps(type, node) if node.is_a?(Array)
  end
  result
end

#parse(body = self.body) ⇒ Sexp, NilClass

Parses the given text.

Parameters:

  • body (String) (defaults to: self.body)

    (self.body) The text to parse

Returns:

  • (Sexp, NilClass)

    the sexp representing the input text.



77
78
79
80
81
# File 'lib/wool/analysis/sexp_analysis.rb', line 77

def parse(body = self.body)
  result = Sexp.new Ripper.sexp(body)
  SexpAnalysis.global_annotations.each {|annotator| annotator.annotate!(result)}
  result
end