I want to create a macro like this
var diffLength =
| index1 === 0 then xPos[index1]
| index1 === 2 then (xPos[index1] - xPos[index1 - 1]) * focusFactor
| otherwise xPos[index1] - xPos[index1 - 1]
which should expand like :
var diffLength =
index1 === 0 ? xPos[index1] :
index1 === 2 ? (xPos[index1] - xPos[index1 - 1]) * focusFactor :
xPos[index1] - xPos[index1 - 1];
SweetJS code :
macro |{
rule {
$cond:expr then $check:expr $($guard:(|) $restCond:expr then $restCheck:expr) ... $lastGuard:(|) otherwise $lastCheck:expr
} => {
( $cond ? $check : $($restCond ? $restCheck :) ... $lastCheck )
}
}
which works only if I change $guards:(h) and $lastGuard:(h) insteed of $guards:(|) and $lastGuard:(|) and actual code like
var diffLength =
| index1 === 0 then xPos[index1]
h index1 === 2 then (xPos[index1] - xPos[index1 - 1]) * focusFactor
h otherwise xPos[index1] - xPos[index1 - 1]
Reason is I am unable to stop sweetjs to parse the adjacent "|"(pipe) delimiters. Can anyone suggest how can I do it?