문제

I want to use parenthesis in macros body to group expressions. For example:

macro m {
  rule { ($x, $y) } => {
    $x >>> ($y * 5)
  }
}

Sweet.js remove all parenthesis:

m(6, 7) => 6 >>> 7 * 5

I expect next output:

m(6, 7) => 6 >>> (7 * 5)

How can I escape parenthesis inside macros body?

도움이 되었습니까?

해결책

Sweet.js (technically escodegen which sweet.js uses for codegen) only removes redundant parens (ie precedence rules mean that 6 >>> 7 * 5 === 6 >>> (7 * 5) so the parens aren't needed) so you shouldn't need to do anything to escape parens in macros.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top