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.
7437 7438 7439 7440 7441 7442 7443 |
# File 'lib/syntax_tree/node.rb', line 7437 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
7425 7426 7427 |
# File 'lib/syntax_tree/node.rb', line 7425 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7435 7436 7437 |
# File 'lib/syntax_tree/node.rb', line 7435 def comments @comments end |
#ending ⇒ Object (readonly)
- String
-
the ending of the regular expression literal
7428 7429 7430 |
# File 'lib/syntax_tree/node.rb', line 7428 def ending @ending end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
regular expression literal
7432 7433 7434 |
# File 'lib/syntax_tree/node.rb', line 7432 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
7445 7446 7447 |
# File 'lib/syntax_tree/node.rb', line 7445 def accept(visitor) visitor.visit_regexp_literal(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7449 7450 7451 |
# File 'lib/syntax_tree/node.rb', line 7449 def child_nodes parts end |
#deconstruct_keys(_keys) ⇒ Object
7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 |
# File 'lib/syntax_tree/node.rb', line 7455 def deconstruct_keys(_keys) { beginning: beginning, ending: ending, options: , parts: parts, location: location, comments: comments } end |
#format(q) ⇒ Object
7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 |
# File 'lib/syntax_tree/node.rb', line 7466 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
7506 7507 7508 |
# File 'lib/syntax_tree/node.rb', line 7506 def ending[1..] end |