in nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala [472:521]
def parseCallExpr(fun: String)(implicit ctx: PRC): SI = (ent: NCIDLEntity, stack: S, idlCtx) =>
implicit val evidence: S = stack
def popMarker(argNum: Int): Unit = if pop1() != stack.PLIST_MARKER then throw rtTooManyParamsError(argNum, fun)
def arg[X](argNum: Int, f: () => X): X =
// +1 for stack frame marker.
if stack.size < argNum + 1 then throw rtMissingParamError(argNum, fun)
val x = f()
x match
case p: Product =>
for (e <- p.productIterator)
if e == stack.PLIST_MARKER then rtMissingParamError(argNum, fun)
case _ => if x.asInstanceOf[ST] == stack.PLIST_MARKER then rtMissingParamError(argNum, fun)
// Make sure to pop up the parameter list stack frame marker.
popMarker(argNum)
x
def arg1(): ST = arg(1, pop1)
def arg2(): (ST, ST) = arg(2, pop2)
def arg3(): (ST, ST, ST) = arg(3, pop3)
def arg1Tok(): ST =
if stack.nonEmpty && stack.top == stack.PLIST_MARKER then
popMarker(1)
() => Z(ent, 1)
else
arg1()
def toX[T](typ: String, v: Object, is: Object => Boolean, as: Object => T): T =
if v == null then throw rtParamNullError(fun)
else if !is(v) then throw rtParamTypeError(fun, v, typ)
as(v)
def toStr(v: Object): String = toX("string", v, isStr, asStr)
def toInt(v: Object): JInt = toX("int", v, isInt, asInt).toInt
def toList(v: Object): JList[_] = toX("list", v, isList, asList)
def toMap(v: Object): JMap[_, _] = toX("map", v, isMap, asMap)
def toEntity(v: Object): NCIDLEntity = toX("entity", v, isEntity, asEntity)
def toBool(v: Object): Boolean = toX("boolean", v, isBool, asBool)
def toDouble(v: Object): JDouble = toX("double or int", v, x => isInt(x) || isReal(x), asReal)
def doSplit(): Unit =
val (x1, x2) = arg2()
stack.push(
() => {
val (v1, v2, n) = extract2(x1, x2)
Z(util.Arrays.asList(toStr(v1).split(toStr(v2)):_*), n)
}