JuliaServices / Match.jl

Advanced Pattern Matching for Julia
https://juliaservices.github.io/Match.jl/latest/
Other
240 stars 22 forks source link

Typo in regex matching? #67

Closed McSaks closed 1 year ago

McSaks commented 3 years ago

In matchmacro.jl:190: symbol("@r_str") seems to be a typo: should this mean Symbol("@r_str")? I’m not that expert in Julia to be sure but it doesn’t seem to make sense in that lowercase form. Upon this correction regexes appear to work.

Before correction:

julia> @match "abcd2" begin
           r"b.d\d" => 1
       end
ERROR: LoadError: UndefVarError: symbol not defined
Stacktrace:
 [1] unapply(::String, ::Expr, ::Array{Symbol,1}, ::Array{Symbol,1}, ::Array{Symbol,1}, ::Match.MatchExprInfo, ::Bool) at /home/mcsaks/.julia/packages/Match/qiTCM/src/matchmacro.jl:190
 [2] unapply(::String, ::Expr, ::Array{Symbol,1}, ::Array{Symbol,1}, ::Array{Symbol,1}, ::Match.MatchExprInfo) at /home/mcsaks/.julia/packages/Match/qiTCM/src/matchmacro.jl:56
 [3] gen_match_expr(::String, ::Expr, ::Symbol, ::Bool) at /home/mcsaks/.julia/packages/Match/qiTCM/src/matchmacro.jl:367
 [4] gen_match_expr(::String, ::Expr, ::Symbol) at /home/mcsaks/.julia/packages/Match/qiTCM/src/matchmacro.jl:348
 [5] @match(::LineNumberNode, ::Module, ::Any, ::Any) at /home/mcsaks/.julia/packages/Match/qiTCM/src/matchmacro.jl:434
in expression starting at REPL[23]:1

After correction:

julia> @match "abcd2" begin
           r"b.d\d" => 1
       end
1
gafter commented 1 year ago
(@v1.6) pkg> status
      Status `~/.julia/environments/v1.6/Project.toml`
  [7eb4fadd] Match v2.0.0

julia> using Match: @match

julia> @match (0xabcd & 0x1f) begin
                  0x0d => :foo
              end
:foo

julia> @match "abcd2" begin
                  r"b.d\d" => 1
              end
1