module SyntaxTree::Quotes
Responsible for providing information about quotes to be used for strings and dynamic symbols.
Constants
- PAIRS
-
The matching pairs of quotes that can be used with % literals.
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 4639 def self.locked?(node, quote) node.parts.any? do |part| !part.is_a?(TStringContent) || part.value.match?(/\\|#[@${]|#{quote}/) end end
If there is some part of this string that matches an escape sequence or that contains the interpolation pattern (“#{”), then we are locked into whichever quote the user chose. (If they chose single quotes, then double quoting would activate the escape sequence, and if they chose double quotes, then single quotes would deactivate it.)
Source
# File lib/syntax_tree/node.rb, line 4646 def self.matching(quote) PAIRS.fetch(quote) { quote } end
Find the matching closing quote for the given opening quote.
Source
# File lib/syntax_tree/node.rb, line 4652 def self.normalize(content, enclosing) return content if enclosing != "\"" && enclosing != "'" content.gsub(/\\([\s\S])|(['"])/) do _match, escaped, quote = Regexp.last_match.to_a if quote == enclosing "\\#{quote}" elsif quote quote else "\\#{escaped}" end end end
Escape and unescape single and double quotes as needed to be able to enclose content
with enclosing
.