This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-206
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-206 by this push:
     new 260ce1b  WIP.
260ce1b is described below

commit 260ce1b35f108b6aa70f95c57b3cd9049e7cef6b
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Wed Mar 10 16:29:28 2021 -0800

    WIP.
---
 .../org/apache/nlpcraft/examples/alarm/alarm_model.json   |  3 ++-
 .../model/intent/compiler/NCDslSyntaxHighlighter.scala    | 15 ++++++---------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/alarm_model.json 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/alarm_model.json
index 050e96f..1ff9bf1 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/alarm_model.json
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/alarm_model.json
@@ -34,6 +34,7 @@
         }
     ],
     "intents": [
-        "intent=alarm term~{id() == 'x:alarm'} term(nums)~{id() == 
'nlpcraft:num' && meta_token('nlpcraft:num:unittype') == 'datetime' && 
meta_token('nlpcraft:num:isequalcondition') == true}[0,7]"
+        "fragment=f1 term(t1)~{id() == 'x:alarm'}",
+        "intent=alarm fragment(f1) term(nums)~{id() == 'nlpcraft:num' && 
meta_token('nlpcraft:num:unittype') == 'datetime' && 
meta_token('nlpcraft:num:isequalcondition') == true}[0,7]"
     ]
 }
\ No newline at end of file
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslSyntaxHighlighter.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslSyntaxHighlighter.scala
index d1fe9cf..a54b8f9 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslSyntaxHighlighter.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslSyntaxHighlighter.scala
@@ -27,12 +27,11 @@ import java.util.regex.Pattern
   */
 object NCDslSyntaxHighlighter {
     private final val NUM_REGEX = Pattern.compile("-?[0-9]+")
-    private final val STR1_REGEX = Pattern.compile("'[^']*'")
-    private final val STR2_REGEX = Pattern.compile(""""[^"]*"""")
+    private final val STR_REGEX = Pattern.compile("""(["'])[^"]*\1""")
 
     private val KEYWORDS = Seq("flow", "fragment", "intent", "meta", "term", 
"ordered")
     private val LITERALS = Seq("true", "false", "null")
-    private val FUNS = Seq(
+    private val FUNCTIONS = Seq(
         "meta_token",
         "meta_part",
         "meta_model",
@@ -178,14 +177,12 @@ object NCDslSyntaxHighlighter {
             val tok = toks.nextToken()
             
             if (KEYWORDS.contains(tok))
-                res ++= (if (tok == "intent") bold(cyan(tok)) else blue(tok))
-            else if (LITERALS.contains(tok))
+                res ++= (if (tok == "intent" || tok == "fragment") 
bold(cyan(tok)) else blue(tok))
+            else if (LITERALS.contains(tok) || 
NUM_REGEX.matcher(tok).matches())
                 res ++= green(tok)
-            else if (FUNS.contains(tok))
+            else if (FUNCTIONS.contains(tok))
                 res ++= yellow(tok)
-            else if (NUM_REGEX.matcher(tok).matches())
-                res ++= green(tok)
-            else if (STR1_REGEX.matcher(tok).matches() || 
STR2_REGEX.matcher(tok).matches())
+            else if (STR_REGEX.matcher(tok).matches())
                 res ++= magenta(tok)
             else
                 res ++= tok

Reply via email to