diff --git a/src/codegen.jl b/src/codegen.jl index c93964ab..c7c36f7c 100644 --- a/src/codegen.jl +++ b/src/codegen.jl @@ -114,15 +114,21 @@ end const DefaultCodeGenContext = CodeGenContext() """ - generate_buffer_validator(name::Symbol, regexp::RE, goto=false) + generate_buffer_validator(name::Symbol, regexp::RE; goto=true; docstring=true) Generate code that, when evaluated, defines a function named `name`, which takes a single argument `data`, interpreted as a sequence of bytes. The function returns `nothing` if `data` matches `Machine`, else the index of the first invalid byte. If the machine reached unexpected EOF, returns `0`. If `goto`, the function uses the faster but more complicated `:goto` code. +If `docstring`, automatically create a docstring for the generated function. """ -function generate_buffer_validator(name::Symbol, regex::RegExp.RE, goto::Bool=false; docstring::Bool=true) +function generate_buffer_validator( + name::Symbol, + regex::RegExp.RE; + goto::Bool=true, + docstring::Bool=true +) ctx = goto ? CodeGenContext(generator=:goto) : DefaultCodeGenContext machine = compile(RegExp.strip_actions(regex)) code = quote diff --git a/test/simd.jl b/test/simd.jl index b8958df0..4f13140d 100644 --- a/test/simd.jl +++ b/test/simd.jl @@ -16,7 +16,7 @@ using Automa context = CodeGenContext(generator=:goto) - eval(generate_buffer_validator(:is_valid_fasta, regex, true)) + eval(generate_buffer_validator(:is_valid_fasta, regex; goto=true)) s1 = ">seq\nTAGGCTA\n>hello\nAJKGMP" s2 = ">seq1\nTAGGC" diff --git a/test/test13.jl b/test/test13.jl index 38b1c418..92918560 100644 --- a/test/test13.jl +++ b/test/test13.jl @@ -11,7 +11,7 @@ using Test (!re"A[BC]D?E", ["ABCDE", "ABCE"], ["ABDE", "ACE", "ABE"]) ] for goto in (false, true) - @eval $(Automa.generate_buffer_validator(:validate, regex, goto; docstring=false)) + @eval $(Automa.generate_buffer_validator(:validate, regex; goto=goto, docstring=false)) for string in good_strings @test validate(string) === nothing end diff --git a/test/test18.jl b/test/test18.jl index 3bc8076b..775985f3 100644 --- a/test/test18.jl +++ b/test/test18.jl @@ -7,7 +7,7 @@ using Test @testset "Test18" begin regex = re"\0\a\b\t\n\v\r\x00\xff\xFF[\\][^\\]" for goto in (false, true) - @eval $(Automa.generate_buffer_validator(:validate, regex, goto; docstring=false)) + @eval $(Automa.generate_buffer_validator(:validate, regex; goto=goto, docstring=false)) # Bad input types @test_throws Exception validate(18) diff --git a/test/validator.jl b/test/validator.jl index 3fd0edf0..f4f47f7e 100644 --- a/test/validator.jl +++ b/test/validator.jl @@ -6,8 +6,8 @@ using Test @testset "Validator" begin regex = re"a(bc)*|(def)|x+" | re"def" | re"x+" - eval(Automa.generate_buffer_validator(:foobar, regex, false)) - eval(Automa.generate_buffer_validator(:barfoo, regex, true)) + eval(Automa.generate_buffer_validator(:foobar, regex; goto=false)) + eval(Automa.generate_buffer_validator(:barfoo, regex; goto=true)) eval(Automa.generate_io_validator(:io_bar, regex; goto=false)) eval(Automa.generate_io_validator(:io_foo, regex; goto=true))