Skip to content

Commit

Permalink
Rename generate_validator_function
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobnissen committed Mar 7, 2023
1 parent 2e60d1d commit 8f8a2b7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Automa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export RE,
compile,

# user-facing generator functions
generate_validator_function,
generate_buffer_validator,
generate_init_code,
generate_exec_code,
generate_code,
Expand Down
4 changes: 2 additions & 2 deletions src/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ end
const DefaultCodeGenContext = CodeGenContext()

"""
generate_validator_function(name::Symbol, regexp::RE, goto=false)
generate_buffer_validator(name::Symbol, regexp::RE, goto=false)
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.
"""
function generate_validator_function(name::Symbol, regex::RegExp.RE, goto::Bool=false; docstring::Bool=true)
function generate_buffer_validator(name::Symbol, regex::RegExp.RE, goto::Bool=false; docstring::Bool=true)
ctx = goto ? CodeGenContext(generator=:goto) : DefaultCodeGenContext
machine = compile(RegExp.strip_actions(regex))
code = quote
Expand Down
2 changes: 1 addition & 1 deletion test/simd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using Automa

context = CodeGenContext(generator=:goto)

eval(generate_validator_function(:is_valid_fasta, regex, true))
eval(generate_buffer_validator(:is_valid_fasta, regex, true))

s1 = ">seq\nTAGGCTA\n>hello\nAJKGMP"
s2 = ">seq1\nTAGGC"
Expand Down
2 changes: 1 addition & 1 deletion test/test13.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using Test
(!re"A[BC]D?E", ["ABCDE", "ABCE"], ["ABDE", "ACE", "ABE"])
]
for goto in (false, true)
@eval $(Automa.generate_validator_function(:validate, regex, goto; docstring=false))
@eval $(Automa.generate_buffer_validator(:validate, regex, goto; docstring=false))
for string in good_strings
@test validate(string) === nothing
end
Expand Down
2 changes: 1 addition & 1 deletion test/test18.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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_validator_function(:validate, regex, goto; docstring=false))
@eval $(Automa.generate_buffer_validator(:validate, regex, goto; docstring=false))

# Bad input types
@test_throws Exception validate(18)
Expand Down
4 changes: 2 additions & 2 deletions test/validator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ using Test

@testset "Validator" begin
regex = re"a(bc)*|(def)|x+" | re"def" | re"x+"
eval(Automa.generate_validator_function(:foobar, regex, false))
eval(Automa.generate_validator_function(:barfoo, regex, true))
eval(Automa.generate_buffer_validator(:foobar, regex, false))
eval(Automa.generate_buffer_validator(:barfoo, regex, true))

eval(Automa.generate_io_validator(:io_bar, regex; goto=false))
eval(Automa.generate_io_validator(:io_foo, regex; goto=true))
Expand Down

0 comments on commit 8f8a2b7

Please sign in to comment.