Repository: incubator-systemml
Updated Branches:
  refs/heads/master 1b48ca0a9 -> 368e7711d


[SYSTEMML-260] Fixed a bug that prevents passing "\t" from command-line

Also, fixed a bug in ScriptUtils when an environment variable
SYSTEMML_HOME is not set.

Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/368e7711
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/368e7711
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/368e7711

Branch: refs/heads/master
Commit: 368e7711df4d1fdbc6b4bf381be35d27f7ded44e
Parents: 1b48ca0
Author: Niketan Pansare <[email protected]>
Authored: Mon Apr 25 14:47:28 2016 -0700
Committer: Niketan Pansare <[email protected]>
Committed: Mon Apr 25 14:47:28 2016 -0700

----------------------------------------------------------------------
 .../parser/common/CommonSyntacticValidator.java | 35 ++++++++++++--------
 .../org/apache/sysml/api/ml/ScriptsUtils.scala  |  2 +-
 2 files changed, 23 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/368e7711/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java 
b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
index d7fdc5e..8ff0ee3 100644
--- a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
@@ -282,24 +282,33 @@ public abstract class CommonSyntacticValidator {
                }
        }
 
-       protected String extractStringInQuotes(String text) {
+       protected String extractStringInQuotes(String text, boolean inQuotes) {
                String val = null;
-               if(     (text.startsWith("\"") && text.endsWith("\"")) ||
-                       (text.startsWith("\'") && text.endsWith("\'"))) {
-                       if(text.length() > 2) {
-                               val = text.substring(1, text.length()-1)
-                                       .replaceAll("\\\\b","\b")
+               if(inQuotes) {
+                       if(     (text.startsWith("\"") && text.endsWith("\"")) 
||
+                               (text.startsWith("\'") && text.endsWith("\'"))) 
{
+                               if(text.length() > 2) {
+                                       val = text.substring(1, text.length()-1)
+                                               .replaceAll("\\\\b","\b")
+                                               .replaceAll("\\\\t","\t")
+                                               .replaceAll("\\\\n","\n")
+                                               .replaceAll("\\\\f","\f")
+                                               .replaceAll("\\\\r","\r");
+                               }
+                       }
+               }
+               else {
+                       val = text.replaceAll("\\\\b","\b")
                                        .replaceAll("\\\\t","\t")
                                        .replaceAll("\\\\n","\n")
                                        .replaceAll("\\\\f","\f")
                                        .replaceAll("\\\\r","\r");
-                       }
                }
                return val;
        }
        
        protected void constStringIdExpressionHelper(ParserRuleContext ctx, 
ExpressionInfo me) {
-               String val = extractStringInQuotes(ctx.getText());
+               String val = extractStringInQuotes(ctx.getText(), true);
                if(val == null) {
                        notifyErrorListeners("incorrect string literal ", 
ctx.start);
                        return;
@@ -434,12 +443,12 @@ public abstract class CommonSyntacticValidator {
                String text = varValue;
                if(     (text.startsWith("\"") && text.endsWith("\"")) || 
(text.startsWith("\'") && text.endsWith("\'"))) {
                        if(text.length() > 2) {
-                               val = extractStringInQuotes(text);
+                               val = extractStringInQuotes(text, true);
                        }
                }
                else {
                        // the commandline parameters can be passed without any 
quotes
-                       val = varValue;
+                       val = extractStringInQuotes(text, false);
                }
                return new StringIdentifier(val, currentFile, linePosition, 
charPosition, linePosition, charPosition);
        }
@@ -454,13 +463,13 @@ public abstract class CommonSyntacticValidator {
 
                String varValue = null;
                for(Map.Entry<String, String> arg : this.argVals.entrySet()) {
-                       if(arg.getKey().trim().equals(varName)) {
+                       if(arg.getKey().equals(varName)) {
                                if(varValue != null) {
                                        notifyErrorListeners("multiple values 
passed for the parameter " + varName + " via commandline", start);
                                        return;
                                }
                                else {
-                                       varValue = arg.getValue().trim();
+                                       varValue = arg.getValue();
                                }
                        }
                }
@@ -471,7 +480,7 @@ public abstract class CommonSyntacticValidator {
 
                // Command line param cannot be empty string
                // If you want to pass space, please quote it
-               if(varValue.trim().equals(""))
+               if(varValue.equals(""))
                        return;
 
                dataInfo.expr = getConstIdFromString(varValue, start);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/368e7711/src/main/scala/org/apache/sysml/api/ml/ScriptsUtils.scala
----------------------------------------------------------------------
diff --git a/src/main/scala/org/apache/sysml/api/ml/ScriptsUtils.scala 
b/src/main/scala/org/apache/sysml/api/ml/ScriptsUtils.scala
index 59e2ee3..0512287 100644
--- a/src/main/scala/org/apache/sysml/api/ml/ScriptsUtils.scala
+++ b/src/main/scala/org/apache/sysml/api/ml/ScriptsUtils.scala
@@ -50,7 +50,7 @@ object ScriptsUtils {
     val out = new StringBuilder()
     try {
       val in = {
-        if (systemmlHome == "") {
+        if (systemmlHome == null || systemmlHome.equals("")) {
           
classOf[LogisticRegression].getClassLoader().getResourceAsStream(algorithmFileName)
         } else {
           new java.io.FileInputStream(resolvePath(algorithmFileName))

Reply via email to