Skip to content

Commit

Permalink
fix off-by-one position problem of the goto codegen (#6) (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 authored Feb 26, 2017
1 parent 125dd72 commit deb2741
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ function generate_goto_code(machine::Machine, actions::Dict{Symbol,Expr}, check:
if p > p_eof 0 && cs $(machine.final_states)
$(eof_action_code)
cs = 0
elseif cs < 0
p -= 1
end
end
end
Expand Down
33 changes: 33 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,39 @@ module Test13
@test validate(b"abrad") == ([], :error)
end

module Test14
import Automa
import Automa.RegExp: @re_str
const re = Automa.RegExp
using Base.Test

a = re"a*"
machine = Automa.compile(a)
@eval function validate_table(data)
$(Automa.generate_init_code(machine))
p_end = p_eof = sizeof(data)
$(Automa.generate_exec_code(machine, code=:table))
return p, cs
end
@eval function validate_inline(data)
$(Automa.generate_init_code(machine))
p_end = p_eof = sizeof(data)
$(Automa.generate_exec_code(machine, code=:inline))
return p, cs
end
@eval function validate_goto(data)
$(Automa.generate_init_code(machine))
p_end = p_eof = sizeof(data)
$(Automa.generate_exec_code(machine, code=:goto))
return p, cs
end

@test validate_table(b"") == validate_inline(b"") == validate_goto(b"")
@test validate_table(b"a") == validate_inline(b"a") == validate_goto(b"a")
@test validate_table(b"b") == validate_inline(b"b") == validate_goto(b"b")
@test validate_table(b"ab") == validate_inline(b"ab") == validate_goto(b"ab")
end

module TestDOT
import Automa
import Automa.RegExp: @re_str
Expand Down

0 comments on commit deb2741

Please sign in to comment.