You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/03/23 03:00:25 UTC
[incubator-nlpcraft] 04/08: WIP.
This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 4d38bd0130912f537f943e764a7e1e1ffb191cc0
Author: Aaron Radzinski <ar...@apache.org>
AuthorDate: Mon Mar 22 18:53:58 2021 -0700
WIP.
---
.../model/intent/compiler/NCIdlCompiler.scala | 4 +--
.../intent/idl/compiler/NCIdlCompilerSpec.scala | 30 ++++++++++++++++++++--
.../nlpcraft/model/intent/idl/compiler/test_ok.idl | 11 ++++++--
3 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompiler.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompiler.scala
index a03ea3d..1dfc42b 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompiler.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompiler.scala
@@ -132,7 +132,7 @@ object NCIdlCompiler extends LazyLogging {
val varName = ctx.id().getText
if (!vars.contains(varName))
- throw newSyntaxError(s"Unknown variable: $varName")(ctx)
+ throw newSyntaxError(s"Unknown variable: @$varName")(ctx)
val instr: SI = (tok: NCToken, stack: S, idlCtx: NCIdlContext) ⇒
stack.push(() ⇒ idlCtx.vars(varName)(tok, idlCtx))
@@ -144,7 +144,7 @@ object NCIdlCompiler extends LazyLogging {
val varName = ctx.id().getText
if (vars.contains(varName))
- throw newSyntaxError(s"Duplicate variable: $varName")(ctx)
+ throw newSyntaxError(s"Duplicate variable: @$varName")(ctx)
vars += varName → exprToFunction("Variable declaration", _ ⇒ true)(ctx)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
index b627609..fd6e8e5 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
@@ -32,6 +32,7 @@ class NCIdlCompilerSpec {
override val getId: String = MODEL_ID
override val getName: String = MODEL_ID
override val getVersion: String = "1.0.0"
+ override def getOrigin: String = "test"
}
/**
@@ -145,8 +146,10 @@ class NCIdlCompilerSpec {
checkCompileError(
"""
|intent=i1
- | meta={'a': true1, 'b': {'arr': [1, 2, 3]}}
- | term(t1)={2 == 2 && size(id()) != -25}
+ | meta={'a': true, 'b': {'arr': [1, 2, 3]}}
+ | term(t1)={
+ | @x == 2 && size(id()) != -25
+ | }
|""".stripMargin
)
checkCompileError(
@@ -159,6 +162,29 @@ class NCIdlCompilerSpec {
checkCompileError(
"""
|intent=i1
+ | flow="a[^0-9b]"
+ | term(t1)={
+ | @x = 2
+ | @x = 2
+ |
+ | true
+ | }
+ |""".stripMargin
+ )
+ checkCompileError(
+ """
+ |intent=i1
+ | flow="a[^0-9b]"
+ | term(t1)={
+ | true
+ |
+ | @x = 2
+ | }
+ |""".stripMargin
+ )
+ checkCompileError(
+ """
+ |intent=i1
| term(t1)={true}[2,1]
|""".stripMargin
)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/test_ok.idl b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/test_ok.idl
index 890cf8c..8f06881 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/test_ok.idl
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/test_ok.idl
@@ -38,12 +38,19 @@ intent=i2
flow="a[^0-9]b"
meta={'a': 42, 'b': {'Москва': [1, 2, 3]}}
term(t1)={2 == 2 && !(id()) != -25 && meta_model('a') == 42}
- term(t2)={meta_model('a') == 42}
+ term(t2)={
+ @a = meta_model('a')
+
+ @a == 42
+ }
intent=i3
flow="a[^0-9]b"
term(t1)={
- has(
+ @x = 2
+ @xx = @x * 2
+
+ @xx == 4 && has(
json(meta_req('user_json_payload')),
list("موسكو\"", 'v1\'v1', "k2", "v2")
)