Class: SyntaxTree::RegexpLiteral
Overview
RegexpLiteral represents a regular expression literal.
/.+/
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- String
-
the beginning of the regular expression literal.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#ending ⇒ Object
readonly
- String
-
the ending of the regular expression literal.
-
#parts ⇒ Object
readonly
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the regular expression literal.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, ending:, parts:, location:, comments: []) ⇒ RegexpLiteral
constructor
A new instance of RegexpLiteral.
- #options ⇒ Object
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, ending:, parts:, location:, comments: []) ⇒ RegexpLiteral
Returns a new instance of RegexpLiteral.
7735 7736 7737 7738 7739 7740 7741 |
# File 'lib/syntax_tree/node.rb', line 7735 def initialize(beginning:, ending:, parts:, location:, comments: []) @beginning = beginning @ending = ending @parts = parts @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- String
-
the beginning of the regular expression literal
7723 7724 7725 |
# File 'lib/syntax_tree/node.rb', line 7723 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7733 7734 7735 |
# File 'lib/syntax_tree/node.rb', line 7733 def comments @comments end |
#ending ⇒ Object (readonly)
- String
-
the ending of the regular expression literal
7726 7727 7728 |
# File 'lib/syntax_tree/node.rb', line 7726 def ending @ending end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
regular expression literal
7730 7731 7732 |
# File 'lib/syntax_tree/node.rb', line 7730 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
7743 7744 7745 |
# File 'lib/syntax_tree/node.rb', line 7743 def accept(visitor) visitor.visit_regexp_literal(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7747 7748 7749 |
# File 'lib/syntax_tree/node.rb', line 7747 def child_nodes parts end |
#deconstruct_keys(_keys) ⇒ Object
7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 |
# File 'lib/syntax_tree/node.rb', line 7753 def deconstruct_keys(_keys) { beginning: beginning, ending: ending, options: , parts: parts, location: location, comments: comments } end |
#format(q) ⇒ Object
7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 |
# File 'lib/syntax_tree/node.rb', line 7764 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() end else q.group do q.text("/") q.format_each(parts) q.text("/") q.text() end end end |
#options ⇒ Object
7804 7805 7806 |
# File 'lib/syntax_tree/node.rb', line 7804 def ending[1..] end |