Class: SyntaxTree::YARV::ToRegExp

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

toregexp pops a number of values off the stack, combines them into a new regular expression, and pushes the new regular expression onto the stack.

### Usage

~~~ruby /foo #bar/ ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, length) ⇒ ToRegExp

Returns a new instance of ToRegExp.



6133
6134
6135
6136
# File 'lib/syntax_tree/yarv/instructions.rb', line 6133

def initialize(options, length)
  @options = options
  @length = length
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



6131
6132
6133
# File 'lib/syntax_tree/yarv/instructions.rb', line 6131

def length
  @length
end

#optionsObject (readonly)

Returns the value of attribute options.



6131
6132
6133
# File 'lib/syntax_tree/yarv/instructions.rb', line 6131

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



6150
6151
6152
6153
# File 'lib/syntax_tree/yarv/instructions.rb', line 6150

def ==(other)
  other.is_a?(ToRegExp) && other.options == options &&
    other.length == length
end

#call(vm) ⇒ Object



6167
6168
6169
# File 'lib/syntax_tree/yarv/instructions.rb', line 6167

def call(vm)
  vm.push(Regexp.new(vm.pop(length).join, options))
end

#canonicalObject



6163
6164
6165
# File 'lib/syntax_tree/yarv/instructions.rb', line 6163

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



6146
6147
6148
# File 'lib/syntax_tree/yarv/instructions.rb', line 6146

def deconstruct_keys(_keys)
  { options: options, length: length }
end

#disasm(fmt) ⇒ Object



6138
6139
6140
# File 'lib/syntax_tree/yarv/instructions.rb', line 6138

def disasm(fmt)
  fmt.instruction("toregexp", [fmt.object(options), fmt.object(length)])
end

#popsObject



6155
6156
6157
# File 'lib/syntax_tree/yarv/instructions.rb', line 6155

def pops
  length
end

#pushesObject



6159
6160
6161
# File 'lib/syntax_tree/yarv/instructions.rb', line 6159

def pushes
  1
end

#to_a(_iseq) ⇒ Object



6142
6143
6144
# File 'lib/syntax_tree/yarv/instructions.rb', line 6142

def to_a(_iseq)
  [:toregexp, options, length]
end