class SlimLint::Sexp
location for defining convenience helpers when operating on Sexps.
The main use of this particular implementation is to provide a single
Symbolic expression which represents tree-structured data.
def display(depth = 1) # rubocop:disable Metrics/AbcSize
-
(String)
-
Parameters:
-
depth
(Integer
) -- indentation level to display Sexp at
def display(depth = 1) # rubocop:disable Metrics/AbcSize indentation = ' ' * 2 * depth output = '['.dup each_with_index do |nested_sexp, index| output << "\n" output += indentation output += if nested_sexp.is_a?(SlimLint::Sexp) nested_sexp.display(depth + 1) else nested_sexp.inspect end # Add trailing comma unless this is the last item output += ',' if index < length - 1 end output << "\n" << ' ' * 2 * (depth - 1) unless empty? output << ']' output end
def initialize(array_sexp)
-
array_sexp
(Array
) --
def initialize(array_sexp) array_sexp.each do |atom_or_sexp| case atom_or_sexp when Array push Sexp.new(atom_or_sexp) else push SlimLint::Atom.new(atom_or_sexp) end end end
def inspect
-
(String)
-
def inspect display end
def match?(sexp_pattern)
-
(Boolean)
-
Parameters:
-
sexp_pattern
(Object, Array
) --
def match?(sexp_pattern) # Delegate matching logic if we're comparing against a matcher if sexp_pattern.is_a?(SlimLint::Matcher::Base) return sexp_pattern.match?(self) end # If there aren't enough items to compare then this obviously won't match return false unless sexp_pattern.is_a?(Array) && length >= sexp_pattern.length sexp_pattern.each_with_index do |sub_pattern, index| return false unless self[index].match?(sub_pattern) end true end