BioJulia / Automa.jl

A julia code generator for regular expressions
Other
188 stars 15 forks source link

Allow no actions in generate exec code #55

Closed jakobnissen closed 3 years ago

jakobnissen commented 3 years ago

Allows you do nearly effortlessly generate code from a Machine while disregarding its actions by passing nothing as the actions. This is useful to create validating parsers, e.g. here is a validating FASTA parser which uses the existing FASTX.FASTA.machine and its context.

import Automa
import FASTX

@eval function validate_fasta(data::Vector{UInt8})
    $(Automa.generate_init_code(FASTA.context, FASTA.machine))
    p_end = p_eof = lastindex(data)
    $(Automa.generate_exec_code(FASTA.context, FASTA.machine, nothing))
    return iszero(cs)
end

It's much easier to do than building a new machine, the code is smaller, and the machine is faster (the above validator validates a 150 MB FASTA file in 57 ms on my laptop). Remarkably, Automa already had an option to pass nothing as the actions, but it didn't actually work.