简体   繁体   English

lix剂宏允许使用的语法是什么?

[英]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. elixir的解析器只能识别有限的一组运算符。

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 我不确定这些内容是否在某个地方有明确记录,但是您可以查看解析器本身,以了解可能的结果: https : //github.com/elixir-lang/elixir/blob/master/lib/elixir/src /elixir_parser.yrl#L51-L74

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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