Module: Pegarus::Rubinius

Defined in:
lib/pegarus/rubinius/compiler.rb,
lib/pegarus/rubinius/generator.rb

Defined Under Namespace

Classes: Compiler, Generator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new_executor(pattern, subject) ⇒ Object



3
4
5
6
# File 'lib/pegarus/rubinius/compiler.rb', line 3

def self.new_executor(pattern, subject)
  Compiler.new.compile pattern
  pattern.match subject
end

Instance Method Details

#any(g, count) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/pegarus/rubinius/compiler.rb', line 95

def any(g, count)
  g.push_index
  g.push count
  g.send :+, 1, false

  g.push_subject
  g.send :size, 0, false
  g.send :<=, 1, false
  g.gif g.fail

  g.push count
  g.inc_index
end

#char(g, string) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/pegarus/rubinius/compiler.rb', line 109

def char(g, string)
  fail = g.new_label
  done = g.new_label

  g.push_literal string
  g.dup
  g.send :size, 0, false
  g.dup
  g.move_down 2

  g.push_subject
  g.swap
  g.push_index
  g.swap
  g.send :substring, 2, false
  g.send :==, 1, false
  g.gif fail

  g.inc_index
  g.goto done

  fail.set!
  g.pop
  g.goto g.fail

  done.set!
end