Class: Pegarus::If

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

Overview

Implements &patt in a PEG. The pattern succeeds if patt matches. 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



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/pegarus/rubinius/compiler.rb', line 180

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

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

  done.set!
end

#visit(visitor) ⇒ Object



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

def visit(visitor)
  visitor.if self
end