Class: RuboCop::AST::RegexpNode
- Defined in:
- lib/rubocop/ast/node/regexp_node.rb
Overview
A node extension for ‘regexp` nodes. This will be used in place of a plain node when the builder constructs the AST, making its methods available to all `regexp` nodes within RuboCop.
Constant Summary
Constants inherited from Node
Node::ARGUMENT_TYPES, Node::ASSIGNMENTS, Node::BASIC_CONDITIONALS, Node::BASIC_LITERALS, Node::COMPARISON_OPERATORS, Node::COMPOSITE_LITERALS, Node::CONDITIONALS, Node::EQUALS_ASSIGNMENTS, Node::FALSEY_LITERALS, Node::IMMUTABLE_LITERALS, Node::KEYWORDS, Node::LITERALS, Node::LOOP_TYPES, Node::MUTABLE_LITERALS, Node::OPERATOR_KEYWORDS, Node::POST_CONDITION_LOOP_TYPES, Node::REFERENCES, Node::SHORTHAND_ASSIGNMENTS, Node::SPECIAL_KEYWORDS, Node::TRUTHY_LITERALS, Node::VARIABLES
Instance Method Summary collapse
-
#content ⇒ String
A string of regexp content.
-
#delimiter?(char) ⇒ Bool
If char is one of the delimiters.
-
#delimiters ⇒ String
The regexp delimiters (without %r).
-
#extended? ⇒ Bool
If regexp uses the extended regopt.
-
#ignore_case? ⇒ Bool
If regexp uses the ignore-case regopt.
-
#interpolation? ⇒ Bool
If regexp contains interpolation.
-
#multiline_mode? ⇒ Bool
If regexp uses the multiline regopt.
-
#no_encoding? ⇒ Bool
If regexp uses the no-encoding regopt.
-
#options ⇒ Integer
NOTE: The ‘o’ option is ignored.
-
#percent_r_literal? ⇒ Bool
If the regexp is a %r… literal (using any delimiters).
-
#regopt ⇒ RuboCop::AST::Node
A regopt node.
-
#single_interpolation? ⇒ Bool
If regexp uses the single-interpolation regopt.
-
#slash_literal? ⇒ Bool
If the regexp is a /…/ literal.
-
#to_regexp ⇒ Regexp
A regexp of this node.
Methods inherited from Node
#ancestors, #argument?, #argument_type?, #assignment?, #assignment_or_similar?, #basic_conditional?, #basic_literal?, #boolean_type?, #call_type?, #chained?, #class_constructor?, #class_definition?, #complete!, #complete?, #conditional?, #const_name, #defined_module, #defined_module_name, #each_ancestor, #empty_source?, #equals_asgn?, #falsey_literal?, #first_line, #global_const?, #guard_clause?, #immutable_literal?, #initialize, #keyword?, #lambda?, #lambda_or_proc?, #last_line, #left_sibling, #left_siblings, #line_count, #literal?, #loop_keyword?, #match_guard_clause?, #module_definition?, #multiline?, #mutable_literal?, #node_parts, #nonempty_line_count, #numeric_type?, #operator_keyword?, #parent, #parent?, #parent_module_name, #parenthesized_call?, #post_condition_loop?, #proc?, #pure?, #range_type?, #receiver, #reference?, #right_sibling, #right_siblings, #root?, #shorthand_asgn?, #sibling_index, #single_line?, #source, #source_length, #source_range, #special_keyword?, #str_content, #struct_constructor?, #truthy_literal?, #updated, #value_used?, #variable?
Methods included from NodePattern::Macros
#def_node_matcher, #def_node_search
Methods included from Descendence
#child_nodes, #descendants, #each_child_node, #each_descendant, #each_node
Methods included from Sexp
Constructor Details
This class inherits a constructor from RuboCop::AST::Node
Instance Method Details
#content ⇒ String
Returns a string of regexp content.
36 37 38 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 36 def content children.select(&:str_type?).map(&:str_content).join end |
#delimiter?(char) ⇒ Bool
Returns if char is one of the delimiters.
56 57 58 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 56 def delimiter?(char) delimiters.include?(char) end |
#delimiters ⇒ String
Returns the regexp delimiters (without %r).
51 52 53 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 51 def delimiters [loc.begin.source[-1], loc.end.source[0]] end |
#extended? ⇒ Bool
Returns if regexp uses the extended regopt.
71 72 73 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 71 def extended? regopt_include?(:x) end |
#ignore_case? ⇒ Bool
Returns if regexp uses the ignore-case regopt.
76 77 78 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 76 def ignore_case? regopt_include?(:i) end |
#interpolation? ⇒ Bool
Returns if regexp contains interpolation.
61 62 63 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 61 def interpolation? children.any?(&:begin_type?) end |
#multiline_mode? ⇒ Bool
Returns if regexp uses the multiline regopt.
66 67 68 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 66 def multiline_mode? regopt_include?(:m) end |
#no_encoding? ⇒ Bool
Returns if regexp uses the no-encoding regopt.
86 87 88 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 86 def no_encoding? regopt_include?(:n) end |
#options ⇒ Integer
NOTE: The ‘o’ option is ignored.
31 32 33 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 31 def regopt.children.map { |opt| OPTIONS.fetch(opt) }.inject(0, :|) end |
#percent_r_literal? ⇒ Bool
Returns if the regexp is a %r… literal (using any delimiters).
46 47 48 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 46 def percent_r_literal? !slash_literal? end |
#regopt ⇒ RuboCop::AST::Node
Returns a regopt node.
24 25 26 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 24 def regopt children.last end |
#single_interpolation? ⇒ Bool
Returns if regexp uses the single-interpolation regopt.
81 82 83 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 81 def single_interpolation? regopt_include?(:o) end |
#slash_literal? ⇒ Bool
Returns if the regexp is a /…/ literal.
41 42 43 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 41 def slash_literal? loc.begin.source == '/' end |
#to_regexp ⇒ Regexp
Returns a regexp of this node.
19 20 21 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 19 def to_regexp Regexp.new(content, ) end |