Class: Pegarus::Unless

Inherits:
UnaryOp show all
Defined in:
lib/pegarus/ast/unless.rb,
lib/pegarus/rubinius/compiler.rb

Overview

Implements !patt in a PEG. The pattern succeeds if patt does not match. Does not consume any input.

Instance Attribute Summary

Attributes inherited from UnaryOp

#pattern

Instance Method Summary collapse

Methods inherited from UnaryOp

#initialize

Methods inherited from Pattern

#*, #+, #+@, #-, #-@, #/, engine, #graph, #match, select_engine

Constructor Details

This class inherits a constructor from Pegarus::UnaryOp

Instance Method Details

#bytecode(g) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/pegarus/rubinius/compiler.rb', line 203

def bytecode(g)
  g.push_index # store index, so that we can restart
  old_fail = g.fail

  pattern_fail = g.new_label
  g.fail = pattern_fail
  @pattern.bytecode(g)
  # success => failure
  g.set_index #  reset index to the stored index, this pops the value
  g.fail = old_fail # reset fail
  g.goto g.fail
  # failure => success
  pattern_fail.set!
  g.set_index # reset index to the stored index, this pops the value
  g.fail = old_fail
end

#visit(visitor) ⇒ Object



5
6
7
# File 'lib/pegarus/ast/unless.rb', line 5

def visit(visitor)
  visitor.unless self
end