简体   繁体   中英

What is the allowed syntax for elixir macros?

I am trying to write some macros at the moment want to know what are the rules around syntax. Why is it I can create the macro ~>> , but |>> gives me a syntax error?

defmacro lhs ~>> rhs
# Works fine
defmacro lhs |>> rhs
# syntax error before: '>'

There is only a limited set of operators that elixir's parser recognizes.

I'm not sure those are explicitly documented somewhere, but you can look at the parser itself to get the idea of what's possible: https://github.com/elixir-lang/elixir/blob/master/lib/elixir/src/elixir_parser.yrl#L51-L74

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM