Class: SyntaxTree::FndPtn
- Inherits:
-
Object
- Object
- SyntaxTree::FndPtn
- Defined in:
- lib/syntax_tree.rb
Overview
FndPtn represents matching against a pattern where you find a pattern in an array using the Ruby 3.0+ pattern matching syntax.
case value
in [*, 7, *]
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#constant ⇒ Object
readonly
- nil | untyped
-
the optional constant wrapper.
-
#left ⇒ Object
readonly
- VarField
-
the splat on the left-hand side.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#right ⇒ Object
readonly
- VarField
-
the splat on the right-hand side.
-
#values ⇒ Object
readonly
- Array[ untyped ]
-
the list of positional expressions in the pattern that are being matched.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(constant:, left:, values:, right:, location:, comments: []) ⇒ FndPtn
constructor
A new instance of FndPtn.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(constant:, left:, values:, right:, location:, comments: []) ⇒ FndPtn
Returns a new instance of FndPtn.
6009 6010 6011 6012 6013 6014 6015 6016 |
# File 'lib/syntax_tree.rb', line 6009 def initialize(constant:, left:, values:, right:, location:, comments: []) @constant = constant @left = left @values = values @right = right @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6007 6008 6009 |
# File 'lib/syntax_tree.rb', line 6007 def comments @comments end |
#constant ⇒ Object (readonly)
- nil | untyped
-
the optional constant wrapper
5991 5992 5993 |
# File 'lib/syntax_tree.rb', line 5991 def constant @constant end |
#left ⇒ Object (readonly)
- VarField
-
the splat on the left-hand side
5994 5995 5996 |
# File 'lib/syntax_tree.rb', line 5994 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
6004 6005 6006 |
# File 'lib/syntax_tree.rb', line 6004 def location @location end |
#right ⇒ Object (readonly)
- VarField
-
the splat on the right-hand side
6001 6002 6003 |
# File 'lib/syntax_tree.rb', line 6001 def right @right end |
#values ⇒ Object (readonly)
- Array[ untyped ]
-
the list of positional expressions in the pattern that
are being matched
5998 5999 6000 |
# File 'lib/syntax_tree.rb', line 5998 def values @values end |
Instance Method Details
#child_nodes ⇒ Object
6018 6019 6020 |
# File 'lib/syntax_tree.rb', line 6018 def child_nodes [constant, left, *values, right] end |
#format(q) ⇒ Object
6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 |
# File 'lib/syntax_tree.rb', line 6022 def format(q) q.format(constant) if constant q.group(0, "[", "]") do q.text("*") q.format(left) q.comma_breakable q.seplist(values) { |value| q.format(value) } q.comma_breakable q.text("*") q.format(right) end end |
#pretty_print(q) ⇒ Object
6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 |
# File 'lib/syntax_tree.rb', line 6037 def pretty_print(q) q.group(2, "(", ")") do q.text("fndptn") if constant q.breakable q.pp(constant) end q.breakable q.pp(left) q.breakable q.group(2, "(", ")") { q.seplist(values) { |value| q.pp(value) } } q.breakable q.pp(right) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 |
# File 'lib/syntax_tree.rb', line 6059 def to_json(*opts) { type: :fndptn, constant: constant, left: left, values: values, right: right, loc: location, cmts: comments }.to_json(*opts) end |