Permalink
Browse files

Minor style tweaks

  • Loading branch information...
mjackson committed Jan 18, 2011
1 parent 28604ab commit 6a2c51a0b1e06366be1b243be2acc7b03e0f2618
Showing with 9 additions and 12 deletions.
  1. +8 −11 lib/citrus.rb
  2. +1 −1 lib/citrus/file.rb
View
@@ -71,7 +71,7 @@ def self.rule(expr, options={})
# # => [MyGrammar]
#
def self.load(file, options={})
- file += '.citrus' unless file =~ /\.citrus$/
+ file += '.citrus' unless /\.citrus$/ === file
force = options.delete(:force)
if force || !@cache[file]
@@ -99,7 +99,7 @@ def self.load(file, options={})
# # => [MyGrammar]
#
def self.require(file, options={})
- file += '.citrus' unless file =~ /\.citrus$/
+ file += '.citrus' unless /\.citrus$/ === file
found = nil
(Pathname.new(file).absolute? ? [''] : $LOAD_PATH).each do |dir|
@@ -1296,7 +1296,7 @@ def to_s
# Returns this match plus all sub #matches in an array.
def to_a
- [captures[0]] + matches
+ [self] + matches
end
alias_method :to_ary, :to_a
@@ -1382,6 +1382,7 @@ def process_events!
@matches = []
capture!(@events[0], self)
+ @captures[0] = self
stack = []
offset = 0
@@ -1404,7 +1405,10 @@ def process_events!
match = Match.new(@string.slice(os, event), @events[start..index])
capture!(rule, match)
- @matches << match if stack.size == 1
+ if stack.size == 1
+ @matches << match
+ @captures[@matches.size] = match
+ end
capture = true
end
@@ -1437,13 +1441,6 @@ def process_events!
index += 1
end
-
- # Add numeric indices to @captures.
- @captures[0] = self
-
- @matches.each_with_index do |match, index|
- @captures[index + 1] = match
- end
end
def capture!(rule, match)
View
@@ -336,7 +336,7 @@ def value
rule :space, zero_or_more(any(:white, :comment))
end
- def File.parse(*args) # :nodoc:
+ def File.parse(*) # :nodoc:
super
rescue ParseError => e
# Raise SyntaxError when a parse fails.

0 comments on commit 6a2c51a

Please sign in to comment.