expr_spec Pub

Simple expressions

$when:: expr.oper.sumnum (a:Number, b:Number)
   . (res=(a + b))
$when:: expr.oper.sumnum2 (a:Number)
   . (res=(a + 2))
$when:: expr.oper.sumnum3 (a:Number)
   . (res=(2 + a))
$when:: expr.oper.sumstr (first, last)
   . (res=((first + " ") + last))

JS - java script expressions

$when:: expr.js.sum1 (a, b)
   . (res39=js{{ a+b }})

Notice here how the parameter email is available inside the javascript expression:

$when:: expr.js.name1 (email)
   . (res40=js{{ email.replace(/(\w+)@(\w+).com/, "$1") }})

$when:: expr.js.sum2 (a, b)
   ctx.echo (a, b:Number<-66)
   . (res42=js{{ a+b }})

/$when shipping.package /=> cart/items $map item => inv.get (item.sku,item.quantity})

exclusive:: expr.js.validateEmail (email ~= "[^@]+@[^@]+.[^@]+")
   . (ok25=true)

Sourcing

$when:: expr.source.erase
   . (erased="123")
   . (erased=null)

Booleans

$when:: expr.bool.test1
   $ifc::b1 . (b2=true)
   $ifc::(b1 is true) . (b3=true)
   $ifc::(b1 not false) . (b4=true)
   $ifc::false . (b5=true)

$when:: expr.bool.test1nos
   $ifc::b1 . (b2n=true)
   $ifc::(b1 is true) . (b3n=true)
   $ifc::(b1 not false) . (b4n=true)
   $ifc::false . (b5n=true)

$when:: expr.bool.testAndUndef (a46?)
   $ifc::(a46 and (1 < 2)) . (b47=true)
   $ifc::((a46 is empty) and (1 < 2)) . (b48=true)
   $ifc::((a46 not empty) and (1 < 2)) . (b49=true)
   $ifc::(notFound and (1 < 2)) . (b50=true)
   $ifc::NOT ((notFound and (1 < 2))) . (b51=true)

$when:: expr.bool.test2 (a, b)
   $ifc::(a > b) . (b22=true)
   $ifc::(a < b) . (b23=true)
   $ifc::(a == b) . (b24=true)
   $ifc::(a >= b) . (b25=true)
   $ifc::(a <= b) . (b26=true)

$when:: expr.bool.testAllExpr (a, bb)
   . (b=0)
   $ifc::true . (b=(b + 1), a01=a01)
   $ifc::NOT (false) . (b=(b + 1), a02=a02)
   $ifc::NOT ((a == b)) . (b=(b + 1), a03=a03)
   $ifc::NOT ((a is b)) . (b=(b + 1), a04=a04)
   $ifc::(a != b) . (b=(b + 1), a05=a05)
   $ifc::(a not b) . (b=(b + 1), a06=a06)
   $ifc::NOT ((a ~= b)) . (b=(b + 1), a07=a07)
   $ifc::(a <= b) . (b=(b + 1), a08=a08)
   $ifc::NOT ((a >= b)) . (b=(b + 1), a09=a09)
   $ifc::NOT ((a > b)) . (b=(b + 1), a10=a10)
   $ifc::(a < b) . (b=(b + 1), a11=a11)
   $ifc::((a < b) or (a > b)) . (b=(b + 1), a12=a12)
   $ifc::((a < b) and (((a > b) or (a < b)))) . (b=(b + 1), a13=a13)
   $ifc::((a < b) and NOT ((a > b))) . (b=(b + 1), a14=a14)
   $ifc::NOT (((a > b) and (a < b))) . (b=(b + 1), a15=a15)
   $ifc::((a < b) and NOT (((a > b)))) . (b=(b + 1), a16=a16)
   $ifc::(1 == 1) . (b=(b + 1), a17=a17)
   $ifc::(1 == a) . (b=(b + 1), a18=a18)
   $ifc::("a" == "a") . (b=(b + 1), a19=a19)
   $ifc::NOT (("a" != "a")) . (b=(b + 1), a20=a20)
   $ifc::((1 + 2) > 2) . (b=(b + 1), a21=a21)
   $ifc::NOT (((1 + 2) < 2)) . (b=(b + 1), a22=a22)
   $ifc::NOT ((( (1 + 2) ) < 2)) . (b=(b + 1), a23=a23)
   . (xbool=true)
   $ifc::xbool . (b=(b + 1), a24=a24)
// => (ybool = b >= 0) // => $ifc (ybool) (b=b+1, a25)

// .todo thi si sactually a match, not a cond...

$when:: expr.bool.testContains (a)
   $ifc::(a contains "3") . (b94=true)
   $ifc::(a containsNot "4") . (b95=true)

$when:: expr.int.lt
   . (len=2)
   . (total=10)
   $ifc::(len < total) . (lt=true)
   $ifc::(len >= total) . (lt=false)

$when:: expr.bool.testBra1
   $ifc::(true and ((false or true))) . (bb105=true)

Match parsing capture groups

$when:: expr.captureGroups (path ~= "/getAccount1/(?<acctId>\d+)")
   . (payload={status:"ok",someStats:"67",accountId:acctId})

Setters and accessors

$when:: test.ctxAccessor
   . (ctx[="asdf"]=90)
   . (temp="decb")
   . (ctx[=temp]=87)

json in context, set values in json , concat arrays

$when:: test.jsonAccessorSet (source, dest, aux)
   . (x=state294[=source][=0])
   . (state294[=source]=state294[=source][:Range=1..None])
   . (state294[=dest]=(x + state294[=dest]))

js binding

fcall | jplay | splay
def: test.util.addMonths (mths)
  m = parseInt(mths);
  d = new Date();
  d.setMonth(d.getMonth() + m);
  return d.toISOString().replace(/T.*/g, '');
fcall | jplay | splay
def: test.util.today
  return new Date().toISOString().replace(/T.*/g, '');

Sizeof and parsing function in conditions

$when:: test.diesel.condif
   $ifc::(sizeOf(a358) > 0) . (b138=true)

Special cases

Had some parsing issues wiht this:

$when:: dieseltest.expr151 (env, deviceId?, deviceType?, event?, index?)
   . (res151=1)
   $ifc::((deviceId is empty) and (event is empty)) . (res151=(res151 + 1))
   $ifc::(((deviceId not empty) and (deviceId != "")) and (event is empty)) . (res151=(res151 + 1))
   $ifc::(((((deviceId is empty) or (deviceId is "
"))) and (deviceType not empty)) and (event is empty)) elk.query (index, search<-(("env:"${env}"" + " AND deviceType:") + deviceType))
   $ifc::(((deviceId not empty) and (deviceId != "*")) and (event not empty)) elk.query (index, search<-("env:"${env}"" + " AND deviceId:"${deviceId}" AND event:"${event}""))
   . (payload={hits:{hits:[]}})
   . (deviceEvents=(payload[="hits"][="hits"] map ( x->(x[="_source"] + {_id:x[="_id"]})() )))
   . (payload=deviceEvents)


Was this useful?    

By: Razie | 2017-09-02 .. 2020-10-03 | Tags: spec , dsl


Viewed 102 times ( | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2020, all rights reserved.