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.
-
#fixed_encoding? ⇒ Bool
If regexp uses the fixed-encoding 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?, #nonempty_line_count, #numeric_type?, #operator_keyword?, #parent, #parent?, #parent_module_name, #parenthesized_call?, #post_condition_loop?, #proc?, #pure?, #range_type?, #receiver, #recursive_basic_literal?, #recursive_literal?, #reference?, #right_sibling, #right_siblings, #root?, #send_type?, #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.
37 38 39 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 37 def content children.select(&:str_type?).map(&:str_content).join end |
#delimiter?(char) ⇒ Bool
Returns if char is one of the delimiters.
57 58 59 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 57 def delimiter?(char) delimiters.include?(char) end |
#delimiters ⇒ String
Returns the regexp delimiters (without %r).
52 53 54 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 52 def delimiters [loc.begin.source[-1], loc.end.source[0]] end |
#extended? ⇒ Bool
Returns if regexp uses the extended regopt.
72 73 74 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 72 def extended? regopt_include?(:x) end |
#fixed_encoding? ⇒ Bool
Returns if regexp uses the fixed-encoding regopt.
92 93 94 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 92 def fixed_encoding? regopt_include?(:u) end |
#ignore_case? ⇒ Bool
Returns if regexp uses the ignore-case regopt.
77 78 79 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 77 def ignore_case? regopt_include?(:i) end |
#interpolation? ⇒ Bool
Returns if regexp contains interpolation.
62 63 64 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 62 def interpolation? children.any?(&:begin_type?) end |
#multiline_mode? ⇒ Bool
Returns if regexp uses the multiline regopt.
67 68 69 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 67 def multiline_mode? regopt_include?(:m) end |
#no_encoding? ⇒ Bool
Returns if regexp uses the no-encoding regopt.
87 88 89 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 87 def no_encoding? regopt_include?(:n) end |
#options ⇒ Integer
NOTE: The ‘o’ option is ignored.
32 33 34 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 32 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).
47 48 49 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 47 def percent_r_literal? !slash_literal? end |
#regopt ⇒ RuboCop::AST::Node
Returns a regopt node.
25 26 27 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 25 def regopt children.last end |
#single_interpolation? ⇒ Bool
Returns if regexp uses the single-interpolation regopt.
82 83 84 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 82 def single_interpolation? regopt_include?(:o) end |
#slash_literal? ⇒ Bool
Returns if the regexp is a /…/ literal.
42 43 44 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 42 def slash_literal? loc.begin.source == '/' end |
#to_regexp ⇒ Regexp
Returns a regexp of this node.
20 21 22 |
# File 'lib/rubocop/ast/node/regexp_node.rb', line 20 def to_regexp Regexp.new(content, ) end |