Skip to content

Commit

Permalink
Update pattern-matching.md
Browse files Browse the repository at this point in the history
Explain why QuoteNode never matches
  • Loading branch information
jkroso committed May 8, 2024
1 parent c9f9e98 commit 86a0510
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/src/pattern-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ Another common use case is to catch symbol literals, e.g.

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

If you want to match quoted symbols and happen to know that Julia's parser parses
them as `QuoteNode` then you might try `@capture(ex, s_QuoteNode)` and discover that
it never matches. This is because expressions are normalized before being matched
against the pattern. And `QuoteNode` get normalized to `quote` so to match a quoted
symbol you will need `@capture(ex, s_quote) && s.args[1] isa Symbol`

### Unions

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

0 comments on commit 86a0510

Please sign in to comment.