Class: RuboCop::AST::NodePattern::Node
- Inherits:
-
Parser::AST::Node
- Object
- Parser::AST::Node
- RuboCop::AST::NodePattern::Node
- Extended by:
- Forwardable
- Includes:
- Descendence
- Defined in:
- lib/rubocop/ast/node_pattern/node.rb
Overview
Base class for AST Nodes of a ‘NodePattern`
Direct Known Subclasses
AnyOrder, Capture, Predicate, Repetition, Rest, Sequence, Subsequence, Union
Defined Under Namespace
Modules: ForbidInSeqHead Classes: AnyOrder, Capture, Predicate, Repetition, Rest, Sequence, Subsequence, Union
Constant Summary collapse
- FunctionCall =
Predicate
- MAP =
Registry
Hash.new(Node).merge!( sequence: Sequence, repetition: Repetition, rest: Rest, capture: Capture, predicate: Predicate, any_order: AnyOrder, function_call: FunctionCall, subsequence: Subsequence, union: Union ).freeze
Instance Method Summary collapse
-
#arity ⇒ Integer, Range
Note: ‘arity.end` may be `Float::INFINITY`.
-
#arity_range ⇒ Range
Arity as a Range.
- #capture? ⇒ Boolean
-
#child ⇒ Node
Most nodes have only one child.
- #children_nodes ⇒ Array<Node>
-
#in_sequence_head ⇒ Array<Node>?
Replace node with result, or ‘nil` if no change requested.
-
#matches_within_set? ⇒ Boolean
that matches within a Set (e.g. ‘42`, `:sym` but not `/regexp/`).
-
#nb_captures ⇒ Integer
Nb of captures of that node and its descendants.
-
#rest? ⇒ Boolean
To be overridden by subclasses.
-
#variadic? ⇒ Boolean
Returns whether it matches a variable number of elements.
- #with(type: @type, children: @children, location: @location) ⇒ Object
Methods included from Descendence
#child_nodes, #descendants, #each_child_node, #each_descendant, #each_node
Instance Method Details
#arity ⇒ Integer, Range
Note: ‘arity.end` may be `Float::INFINITY`
29 30 31 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 29 def arity 1 end |
#arity_range ⇒ Range
Returns arity as a Range.
69 70 71 72 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 69 def arity_range a = arity a.is_a?(Range) ? a : INT_TO_RANGE[a] end |
#capture? ⇒ Boolean
23 24 25 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 23 def capture? false end |
#child ⇒ Node
Returns most nodes have only one child.
48 49 50 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 48 def child children[0] end |
#children_nodes ⇒ Array<Node>
43 44 45 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 43 def children_nodes children.grep(Node) end |
#in_sequence_head ⇒ Array<Node>?
Returns replace node with result, or ‘nil` if no change requested.
34 35 36 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 34 def in_sequence_head nil end |
#matches_within_set? ⇒ Boolean
that matches within a Set (e.g. ‘42`, `:sym` but not `/regexp/`)
64 65 66 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 64 def matches_within_set? MATCHES_WITHIN_SET.include?(type) end |
#nb_captures ⇒ Integer
Returns nb of captures of that node and its descendants.
53 54 55 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 53 def nb_captures children_nodes.sum(&:nb_captures) end |
#rest? ⇒ Boolean
To be overridden by subclasses
19 20 21 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 19 def rest? false end |
#variadic? ⇒ Boolean
Returns whether it matches a variable number of elements
58 59 60 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 58 def variadic? arity.is_a?(Range) end |
#with(type: @type, children: @children, location: @location) ⇒ Object
74 75 76 |
# File 'lib/rubocop/ast/node_pattern/node.rb', line 74 def with(type: @type, children: @children, location: @location) self.class.new(type, children, { location: location }) end |