expr-spec Pub Share

Simple expressions

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

msg expr.oper.sumnump  (a:Number, b:Number)

$when:: expr.oper.sumnump (aNumber, bNumber)
   . (payload=(a + b))

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=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)
   $ifc:: (xbool == true) . (b=(b + 1), a25=a25)
   $ifc:: (xbool == "true") . (b=(b + 1), a26=a26)

$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"="asdf"]=90)
   . (temp="decb")
   . (ctx[=temp]=87)
   . (payload=(asdf + decb))

json in context, set values in json , concat arrays

$when:: test.jsonAccessorSet (source, dest, aux)
   . (x=state294[=source][="0"=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.todayjs
  return new Date().toISOString().replace(/T.*/g, '');
fcall | jplay | splay
def: test.util.todayscala
  new java.util.Date();

Sizeof and parsing function in conditions

$when:: test.diesel.condif
   . (b138=0)
   $ifc:: (sizeOf(a358) > 0) . (b138=(b138 + 1))
   diesel.todo (desc =""todo for the following see Ex"...="todo for ...)
   step => $if (sizeOf([1,2,3]+[4,5]) is 5) (b138 = b138+1)
   step => (z153=[{a:1,b:{b:"123"}}])
   step => (aa=z153[0].b['b'])
   step => $if (sizeOf(aa=z153[0].b['b']) > 0) (b138 = b138+1)
   diesel.todo (desc =""todo => $if (sizeOf(z153[0].b"...="todo => $...)
   diesel.todo (desc =""todo => $if (sizeOf(a358[0..1"...="todo => $...)

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:"${...)
   $ifc:: (((deviceId not empty) and (deviceId != "*")) and (event not empty)) elk.query (index, search=("env:"${e...)
   . (payload={hits:{hits:[]}})
   . (deviceEvents=(payload[="hits"][="hits"] map ( x=>(x[="_source"] + {_id:x[="_id"]})() )))
   . (payload=deviceEvents)

Various bugs

bug: if the target had (x=y) and produced value x then newctx would overwrite the newer x, so

$when:: testdiesel.bug.overwritectxname (a)
   . (payload="z")

REGEX

msg test.diesel.parse.item  (x)

$when:: test.diesel.parse.item (x)
   . (payload=x)
   ctx.regex (regex ="(?<server>[^:]+):(?<pass>[^:]+"...="(?<server...)
   . (payload={server:server,pass:pass,perms:perms})

Functions and messages

0 $mock:: testdiesel.gt2 (wfr)
   . (payload=(wfr > 1))

Boolean funcs

$when:: test.diesel.boolexpr1
   . (res=1)
   . (cmp="<=")
   $ifc:: (1 ${cmp} 2) . (res=2)
   . (cmp=">")
   $ifc:: (1 ${cmp} 2) . (res=3)


Was this useful?    

By: Razie | 2017-09-02 .. 2022-06-17 | Tags: spec , dsl , private


Viewed 894 times ( | History | Print ) this page.

You need to log in to post a comment!

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