Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from jtoman/master

Allow matching against the end of string
  • Loading branch information...
commit e75be0dfb9b704ea3f74df27b805799ae0849bad 2 parents 7335308 + 35864b4
@tenderlove authored
View
15 lib/rexical/generator.rb
@@ -69,6 +69,8 @@ def add_option( st )
@opt['--stub'] = true
when /independent/i
@opt['--independent'] = true
+ when /matcheos/i
+ @opt['--matcheos'] = true
end
end
end
@@ -395,11 +397,11 @@ def write_scanner f = scanner_io
f.print REX_UTIL
## scanner method
-
+ eos_check = @opt["--matcheos"] ? "" : "return if @ss.eos?"
f.print <<-REX_EOT
def next_token
- return if @ss.eos?
+ #{eos_check}
# skips empty actions
until token = _next_token or @ss.eos?; end
@@ -461,7 +463,16 @@ def _next_token
end
end
+ if @opt["--matcheos"]
+ eos_check = <<-REX_EOT
+ when @@ss.scan(/$/)
+ ;
+ REX_EOT
+ else
+ eos_check = ""
+ end
f.print <<-REX_EOT
+ #{eos_check}
else
text = @ss.string[@ss.pos .. -1]
raise ScanError, "can not match: '" + text + "'"
View
1  lib/rexical/rexcmd.rb
@@ -22,6 +22,7 @@ class Cmd
o -i --ignorecase - ignore char case
o -C --check-only - syntax check only
o - --independent - independent mode
+o - --matcheos - allow match against end of string
o -d --debug - print debug information
o -h --help - print this message and quit
o - --version - print version and quit
View
15 test/test_generator.rb
@@ -235,6 +235,21 @@ class Calculator
calc.state = nil
assert_equal [:A, 'a'], calc.next_token
end
+ def test_match_eos
+ lexer = build_lexer %q{
+class Calculator
+option
+matcheos
+rule
+ a { [:A, text] }
+ $ { [:EOF, ""] }
+:B b { [:B, text] }
+ }
+ calc = lexer::Calculator.new
+ calc.scan_setup("a")
+ assert_equal [:A, 'a'], calc.next_token
+ assert_equal [:EOF, ""], calc.next_token
+ end
def parse_lexer(str)
rex = Rexical::Generator.new("--independent" => true)

0 comments on commit e75be0d

Please sign in to comment.
Something went wrong with that request. Please try again.