Skip to content

Commit 0daeb44

Browse files
authored
Merge pull request #202 from jkroso/patch-1
Update pattern-matching.md
2 parents c9f9e98 + 74d55fa commit 0daeb44

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/src/pattern-matching.md

+14
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ Another common use case is to catch symbol literals, e.g.
9191

9292
which will match e.g. `struct Foo ...` but not `struct Foo{V} ...`
9393

94+
If you want to match on quoted symbols like `:(:a)` you might look at the AST Julia
95+
produces and expect to be able to use the type `QuoteNode` in your pattern. Hence,
96+
you would expect the following to produce `1`:
97+
98+
```julia
99+
@match :(:a) begin
100+
s_QuoteNode => 1
101+
s_quote => 2
102+
end
103+
```
104+
However, it evaluates to `2` because MacroTools normalizes expressions before comparing
105+
them to your pattern. And `QuoteNode` gets normalized to `quote` so to match a quoted
106+
symbol you will need `@capture(ex, s_quote) && s.args[1] isa Symbol`
107+
94108
### Unions
95109

96110
`@capture` can also try to match the expression against one pattern or another,

0 commit comments

Comments
 (0)