diff --git a/src/Automa.jl b/src/Automa.jl index 6d9158ab..95b02334 100644 --- a/src/Automa.jl +++ b/src/Automa.jl @@ -43,8 +43,7 @@ if !isdefined(Base, :get_extension) include("../ext/AutomaStream.jl") end -const RE = Automa.RegExp -using .RegExp: @re_str, opt, rep, rep1, onenter!, onexit!, onall!, onfinal!, precond! +using .RegExp: RE, @re_str, opt, rep, rep1, onenter!, onexit!, onall!, onfinal!, precond! # This list of exports lists the API export RE, diff --git a/src/re.jl b/src/re.jl index 9ac89d50..7f267e2f 100644 --- a/src/re.jl +++ b/src/re.jl @@ -22,6 +22,8 @@ function RE(head::Symbol, args::Vector) return RE(head, args, nothing, nothing) end +RE(s::AbstractString) = parse(s) + function actions!(re::RE) if isnothing(re.actions) re.actions = Dict{Symbol, Vector{Symbol}}() @@ -129,7 +131,8 @@ end const METACHAR = raw".*+?()[]\|-^" # Parse a regular expression string using the shunting-yard algorithm. -function parse(str::String) +function parse(str_::AbstractString) + str = String(str_) # stacks operands = RE[] operators = Symbol[] diff --git a/test/runtests.jl b/test/runtests.jl index 3dbc4479..bed2fb00 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -286,7 +286,7 @@ end @test Automa.generate_exec_code(ctx, machine, :debug) isa Any end -@testset "Invalid RE.actions keys" begin +@testset "Invalid actions keys" begin @test_throws Exception let a = re"abc" Automa.RegExp.actions!(a)[:badkey] = [:foo]