citrus 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/citrus.rb +22 -15
  2. data/test/multibyte_test.rb +5 -7
  3. metadata +3 -3
@@ -8,7 +8,7 @@ require 'strscan'
8
8
  module Citrus
9
9
  autoload :File, 'citrus/file'
10
10
 
11
- VERSION = [2, 3, 0]
11
+ VERSION = [2, 3, 1]
12
12
 
13
13
  # Returns the current version of Citrus as a string.
14
14
  def self.version
@@ -161,17 +161,16 @@ module Citrus
161
161
  # position. Objects in this array may be one of three types: a Rule,
162
162
  # Citrus::CLOSE, or a length (integer).
163
163
  def exec(rule, events=[])
164
- start = pos
165
164
  index = events.size
165
+ position = pos
166
166
 
167
167
  if rule.exec(self, events).size > index
168
- pos = start + events[-1]
169
- @max_offset = pos if pos > @max_offset
170
- self.pos = pos
171
- else
172
- self.pos = start
168
+ position += events[-1]
169
+ @max_offset = position if position > @max_offset
173
170
  end
174
171
 
172
+ self.pos = position
173
+
175
174
  events
176
175
  end
177
176
 
@@ -216,16 +215,24 @@ module Citrus
216
215
  end
217
216
 
218
217
  def exec(rule, events=[]) # :nodoc:
219
- c = @cache[rule] ||= {}
218
+ position = pos
219
+ memo = @cache[rule] ||= {}
220
220
 
221
- e = if c[pos]
221
+ if memo[position]
222
222
  @cache_hits += 1
223
- c[pos]
224
223
  else
225
- c[pos] = super(rule)
224
+ memo[position] = rule.exec(self)
226
225
  end
227
226
 
228
- events.concat(e)
227
+ if memo[position].size > 0
228
+ events.concat(memo[position])
229
+ position += events[-1]
230
+ @max_offset = position if position > @max_offset
231
+ end
232
+
233
+ self.pos = position
234
+
235
+ events
229
236
  end
230
237
 
231
238
  # Returns +true+ when using memoization to cache match results.
@@ -1011,8 +1018,8 @@ module Citrus
1011
1018
  m = max
1012
1019
 
1013
1020
  while n < m && input.exec(rule, events).size > index
1014
- index = events.size
1015
1021
  length += events[-1]
1022
+ index = events.size
1016
1023
  n += 1
1017
1024
  end
1018
1025
 
@@ -1072,12 +1079,12 @@ module Citrus
1072
1079
  m = rules.length
1073
1080
 
1074
1081
  while n < m && input.exec(rules[n], events).size > index
1075
- index = events.size
1076
1082
  length += events[-1]
1083
+ index = events.size
1077
1084
  n += 1
1078
1085
  end
1079
1086
 
1080
- if n == rules.length
1087
+ if n == m
1081
1088
  events << CLOSE
1082
1089
  events << length
1083
1090
  else
@@ -1,21 +1,19 @@
1
1
  require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class MultibyteTest < Test::Unit::TestCase
4
- Citrus.eval(<<-'CODE')
5
- grammar MultibyteTest::Multibyte
6
- rule string
4
+ grammar :Multibyte do
5
+ rule :string do
7
6
  "\xFF"
8
7
  end
9
8
 
10
- rule regexp
9
+ rule :regexp do
11
10
  /\xFF/
12
11
  end
13
12
 
14
- rule character_class
15
- [\xFF]
13
+ rule :character_class do
14
+ /[\xFF]/
16
15
  end
17
16
  end
18
- CODE
19
17
 
20
18
  def test_multibyte_string
21
19
  m = Multibyte.parse("\xFF", :root => :string)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 3
8
- - 0
9
- version: 2.3.0
8
+ - 1
9
+ version: 2.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Jackson
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-28 00:00:00 -08:00
17
+ date: 2010-12-31 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency