class SyntaxTree::RegexpLiteral
RegexpLiteral
represents a regular expression literal.
/.+/
Attributes
- String
-
the beginning of the regular expression literal
- String
-
the ending of the regular expression literal
- Array[
StringEmbExpr
|StringDVar
|TStringContent
] -
the parts of the
regular expression literal
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 9229 def initialize(beginning:, ending:, parts:, location:) @beginning = beginning @ending = ending @parts = parts @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 9311 def ===(other) other.is_a?(RegexpLiteral) && beginning === other.beginning && ending === other.ending && options === other.options && ArrayMatch.call(parts, other.parts) end
Source
# File lib/syntax_tree/node.rb, line 9237 def accept(visitor) visitor.visit_regexp_literal(self) end
Source
# File lib/syntax_tree/node.rb, line 9241 def child_nodes parts end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 9245 def copy(beginning: nil, ending: nil, parts: nil, location: nil) node = RegexpLiteral.new( beginning: beginning || self.beginning, ending: ending || self.ending, parts: parts || self.parts, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
Source
# File lib/syntax_tree/node.rb, line 9260 def deconstruct_keys(_keys) { beginning: beginning, ending: ending, options: options, parts: parts, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 9271 def format(q) braces = ambiguous?(q) || include?(%r{/}) if braces && include?(/[{}]/) q.group do q.text(beginning) q.format_each(parts) q.text(ending) end elsif braces q.group do q.text("%r{") if beginning == "/" # If we're changing from a forward slash to a %r{, then we can # replace any escaped forward slashes with regular forward slashes. parts.each do |part| if part.is_a?(TStringContent) q.text(part.value.gsub("\\/", "/")) else q.format(part) end end else q.format_each(parts) end q.text("}") q.text(options) end else q.group do q.text("/") q.format_each(parts) q.text("/") q.text(options) end end end