سؤال

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