Class: SyntaxTree::RegexpLiteral
- Inherits:
-
Object
- Object
- SyntaxTree::RegexpLiteral
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#parts ⇒ Object
readonly
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the regular expression literal.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, ending:, parts:, location:, comments: []) ⇒ RegexpLiteral
constructor
A new instance of RegexpLiteral.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(beginning:, ending:, parts:, location:, comments: []) ⇒ RegexpLiteral
Returns a new instance of RegexpLiteral.
9532 9533 9534 9535 9536 9537 9538 |
# File 'lib/syntax_tree.rb', line 9532 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
9517 9518 9519 |
# File 'lib/syntax_tree.rb', line 9517 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9530 9531 9532 |
# File 'lib/syntax_tree.rb', line 9530 def comments @comments end |
#ending ⇒ Object (readonly)
- String
-
the ending of the regular expression literal
9520 9521 9522 |
# File 'lib/syntax_tree.rb', line 9520 def ending @ending end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9527 9528 9529 |
# File 'lib/syntax_tree.rb', line 9527 def location @location end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
regular expression literal
9524 9525 9526 |
# File 'lib/syntax_tree.rb', line 9524 def parts @parts end |
Instance Method Details
#child_nodes ⇒ Object
9540 9541 9542 |
# File 'lib/syntax_tree.rb', line 9540 def child_nodes parts end |
#format(q) ⇒ Object
9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 |
# File 'lib/syntax_tree.rb', line 9544 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 else q.group do q.text(braces ? "%r{" : "/") q.format_each(parts) q.text(braces ? "}" : "/") q.text(ending[1..-1]) end end end |
#pretty_print(q) ⇒ Object
9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 |
# File 'lib/syntax_tree.rb', line 9563 def pretty_print(q) q.group(2, "(", ")") do q.text("regexp_literal") q.breakable q.group(2, "(", ")") { q.seplist(parts) { |part| q.pp(part) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 |
# File 'lib/syntax_tree.rb', line 9574 def to_json(*opts) { type: :regexp_literal, beging: beginning, ending: ending, parts: parts, loc: location, cmts: comments }.to_json(*opts) end |