You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by de...@apache.org on 2016/02/19 23:56:19 UTC

[6/7] incubator-systemml git commit: Replace SyntacticErrorListener with CustomErrorListener, step 1

Replace SyntacticErrorListener with CustomErrorListener, step 1

Stage 1 of the replacement of SyntacticErrorListener with its inner
class CustomErrorListener.  In order to retain history, we do this
in two commits: one commit to change the name of the
SyntacticErrorListener class to CustomErrorListener while changing
the inner CustomErrorListener class to a dummy name; a second commit
to move the inner class methods out to the outer class.


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

Branch: refs/heads/master
Commit: 45d56a58300cee5ddd7625db7ef28905de944f36
Parents: 6017f06
Author: Mike Dusenberry <mw...@us.ibm.com>
Authored: Thu Feb 18 11:22:22 2016 -0800
Committer: Deron Eriksson <de...@us.ibm.com>
Committed: Fri Feb 19 12:00:34 2016 -0800

----------------------------------------------------------------------
 .../parser/common/CommonSyntacticValidator.java |   6 +-
 .../parser/common/CustomErrorListener.java      | 111 +++++++++++++++++++
 .../parser/common/SyntacticErrorListener.java   | 111 -------------------
 .../sysml/parser/dml/DMLParserWrapper.java      |  10 +-
 .../sysml/parser/dml/DmlSyntacticValidator.java |   4 +-
 .../sysml/parser/pydml/PyDMLParserWrapper.java  |   4 +-
 .../parser/pydml/PydmlSyntacticValidator.java   |   4 +-
 7 files changed, 125 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/45d56a58/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 27beb0d..4e5d01f 100644
--- a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
@@ -51,7 +51,7 @@ import org.apache.sysml.parser.PrintStatement;
 import org.apache.sysml.parser.RelationalExpression;
 import org.apache.sysml.parser.Statement;
 import org.apache.sysml.parser.StringIdentifier;
-import org.apache.sysml.parser.common.SyntacticErrorListener.CustomErrorListener;
+import org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
 import org.apache.sysml.parser.dml.DmlParser.BuiltinFunctionExpressionContext;
 import org.apache.sysml.parser.dml.DmlSyntacticValidator;
 import org.apache.sysml.parser.pydml.PydmlSyntacticValidator;
@@ -64,12 +64,12 @@ import com.google.common.primitives.Longs;
  */
 public abstract class CommonSyntacticValidator {
 
-	protected final CustomErrorListener errorListener;
+	protected final CustomErrorListenerInner errorListener;
 	protected final String currentFile;
 	protected String _workingDir = ".";   //current working directory
 	protected HashMap<String,String> argVals = null;
 
-	public CommonSyntacticValidator(CustomErrorListener errorListener, HashMap<String,String> argVals) {
+	public CommonSyntacticValidator(CustomErrorListenerInner errorListener, HashMap<String,String> argVals) {
 		this.errorListener = errorListener;
 		currentFile = errorListener.getCurrentFileName();
 		this.argVals = argVals;

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/45d56a58/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java b/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
new file mode 100644
index 0000000..74c82c0
--- /dev/null
+++ b/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysml.parser.common;
+
+import org.antlr.v4.runtime.BaseErrorListener;
+import org.antlr.v4.runtime.RecognitionException;
+import org.antlr.v4.runtime.Recognizer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysml.api.DMLScript;
+
+public class CustomErrorListener {
+	
+	private static final Log LOG = LogFactory.getLog(DMLScript.class.getName());
+	
+	public static class CustomErrorListenerInner extends BaseErrorListener {
+		
+		private boolean atleastOneError = false;
+		private String currentFileName = null;
+		
+		public void setCurrentFileName(String currentFilePath) {
+			currentFileName = currentFilePath;
+		}
+		
+		public String getCurrentFileName() {
+			return currentFileName;
+		}
+		
+		public void unsetCurrentFileName() {
+			currentFileName = null;
+		}
+
+		public void validationError(int line, int charPositionInLine, String msg) {
+			try {
+				setAtleastOneError(true);
+				// Print error messages with file name
+				if(currentFileName == null) {
+					LOG.error("line "+line+":"+charPositionInLine+" "+msg);
+				}
+				else {
+					String fileName = currentFileName;
+					LOG.error(fileName + " line "+line+":"+charPositionInLine+" "+msg);
+				}
+			}
+			catch(Exception e1) {
+				LOG.error("ERROR: while customizing error message:" + e1);
+			}
+		}
+		
+		public void validationWarning(int line, int charPositionInLine, String msg) {
+			try {
+				//atleastOneError = true; ---> not an error, just warning
+				// Print error messages with file name
+				if(currentFileName == null)
+					LOG.warn("line "+line+":"+charPositionInLine+" "+msg);
+				else {
+					String fileName = currentFileName;
+					LOG.warn(fileName + " line "+line+":"+charPositionInLine+" "+msg);
+				}
+			}
+			catch(Exception e1) {
+				LOG.warn("ERROR: while customizing error message:" + e1);
+			}
+		}
+		
+		@Override
+		public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
+				int line, int charPositionInLine,
+				String msg, RecognitionException e)
+		{	
+			try {
+				setAtleastOneError(true);
+				// Print error messages with file name
+				if(currentFileName == null)
+					LOG.error("line "+line+":"+charPositionInLine+" "+msg);
+				else {
+					String fileName = currentFileName;
+					LOG.error(fileName + " line "+line+":"+charPositionInLine+" "+msg);
+				}
+			}
+			catch(Exception e1) {
+				LOG.error("ERROR: while customizing error message:" + e1);
+			}
+		}
+
+		public boolean isAtleastOneError() {
+			return atleastOneError;
+		}
+
+		public void setAtleastOneError(boolean atleastOneError) {
+			this.atleastOneError = atleastOneError;
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/45d56a58/src/main/java/org/apache/sysml/parser/common/SyntacticErrorListener.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/common/SyntacticErrorListener.java b/src/main/java/org/apache/sysml/parser/common/SyntacticErrorListener.java
deleted file mode 100644
index 2a669d8..0000000
--- a/src/main/java/org/apache/sysml/parser/common/SyntacticErrorListener.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sysml.parser.common;
-
-import org.antlr.v4.runtime.BaseErrorListener;
-import org.antlr.v4.runtime.RecognitionException;
-import org.antlr.v4.runtime.Recognizer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.sysml.api.DMLScript;
-
-public class SyntacticErrorListener {
-	
-	private static final Log LOG = LogFactory.getLog(DMLScript.class.getName());
-	
-	public static class CustomErrorListener extends BaseErrorListener {
-		
-		private boolean atleastOneError = false;
-		private String currentFileName = null;
-		
-		public void setCurrentFileName(String currentFilePath) {
-			currentFileName = currentFilePath;
-		}
-		
-		public String getCurrentFileName() {
-			return currentFileName;
-		}
-		
-		public void unsetCurrentFileName() {
-			currentFileName = null;
-		}
-
-		public void validationError(int line, int charPositionInLine, String msg) {
-			try {
-				setAtleastOneError(true);
-				// Print error messages with file name
-				if(currentFileName == null) {
-					LOG.error("line "+line+":"+charPositionInLine+" "+msg);
-				}
-				else {
-					String fileName = currentFileName;
-					LOG.error(fileName + " line "+line+":"+charPositionInLine+" "+msg);
-				}
-			}
-			catch(Exception e1) {
-				LOG.error("ERROR: while customizing error message:" + e1);
-			}
-		}
-		
-		public void validationWarning(int line, int charPositionInLine, String msg) {
-			try {
-				//atleastOneError = true; ---> not an error, just warning
-				// Print error messages with file name
-				if(currentFileName == null)
-					LOG.warn("line "+line+":"+charPositionInLine+" "+msg);
-				else {
-					String fileName = currentFileName;
-					LOG.warn(fileName + " line "+line+":"+charPositionInLine+" "+msg);
-				}
-			}
-			catch(Exception e1) {
-				LOG.warn("ERROR: while customizing error message:" + e1);
-			}
-		}
-		
-		@Override
-		public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
-				int line, int charPositionInLine,
-				String msg, RecognitionException e)
-		{	
-			try {
-				setAtleastOneError(true);
-				// Print error messages with file name
-				if(currentFileName == null)
-					LOG.error("line "+line+":"+charPositionInLine+" "+msg);
-				else {
-					String fileName = currentFileName;
-					LOG.error(fileName + " line "+line+":"+charPositionInLine+" "+msg);
-				}
-			}
-			catch(Exception e1) {
-				LOG.error("ERROR: while customizing error message:" + e1);
-			}
-		}
-
-		public boolean isAtleastOneError() {
-			return atleastOneError;
-		}
-
-		public void setAtleastOneError(boolean atleastOneError) {
-			this.atleastOneError = atleastOneError;
-		}
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/45d56a58/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java b/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
index 7af95dd..6b9a238 100644
--- a/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
+++ b/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
@@ -43,7 +43,7 @@ import org.apache.sysml.parser.FunctionStatementBlock;
 import org.apache.sysml.parser.ImportStatement;
 import org.apache.sysml.parser.LanguageException;
 import org.apache.sysml.parser.ParseException;
-import org.apache.sysml.parser.common.SyntacticErrorListener.CustomErrorListener;
+import org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
 import org.apache.sysml.parser.dml.DmlParser.FunctionStatementContext;
 import org.apache.sysml.parser.dml.DmlParser.ProgramrootContext;
 import org.apache.sysml.parser.dml.DmlParser.StatementContext;
@@ -62,7 +62,7 @@ import org.apache.sysml.parser.dml.DmlParser.StatementContext;
  * 
  * To separate logic of semantic validation, DmlSyntaticValidatorHelper contains functions that do semantic validation. Currently, there is no semantic validation as most of it is delegated to subsequent validation phase. 
  * 
- * Whenever there is a parse error, it goes through SyntacticErrorListener. This allows us to pipe the error messages to any future pipeline as well as control the format in an elegant manner. 
+ * Whenever there is a parse error, it goes through CustomErrorListener. This allows us to pipe the error messages to any future pipeline as well as control the format in an elegant manner.
  * There are three types of messages passed:
  * - Syntactic errors: When passed DML script doesnot conform to syntatic structure enforced by Dml.g4
  * - Validation errors: Errors due to translation of AST to  DMLProgram
@@ -125,7 +125,7 @@ public class DMLParserWrapper extends AParserWrapper
 		}
 
 		ProgramrootContext ast = null;
-		CustomErrorListener errorListener = new CustomErrorListener();
+		CustomErrorListenerInner errorListener = new CustomErrorListenerInner();
 		
 		try {
 			DmlLexer lexer = new DmlLexer(in);
@@ -149,11 +149,11 @@ public class DMLParserWrapper extends AParserWrapper
 					antlr4Parser.reset();
 					if(fileName != null) {
 						errorListener.setCurrentFileName(fileName);
-						// SyntacticErrorListener.currentFileName.push(fileName);
+						// CustomErrorListener.currentFileName.push(fileName);
 					}
 					else {
 						errorListener.setCurrentFileName("MAIN_SCRIPT");
-						// SyntacticErrorListener.currentFileName.push("MAIN_SCRIPT");
+						// CustomErrorListener.currentFileName.push("MAIN_SCRIPT");
 					}
 					// Set our custom error listener
 					antlr4Parser.addErrorListener(errorListener);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/45d56a58/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
index 4def772..f3a297f 100644
--- a/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
@@ -55,7 +55,7 @@ import org.apache.sysml.parser.Statement;
 import org.apache.sysml.parser.StatementBlock;
 import org.apache.sysml.parser.WhileStatement;
 import org.apache.sysml.parser.common.CommonSyntacticValidator;
-import org.apache.sysml.parser.common.SyntacticErrorListener.CustomErrorListener;
+import org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
 import org.apache.sysml.parser.common.ExpressionInfo;
 import org.apache.sysml.parser.common.StatementInfo;
 import org.apache.sysml.parser.dml.DmlParser.AddSubExpressionContext;
@@ -110,7 +110,7 @@ import org.apache.sysml.parser.dml.DmlParser.WhileStatementContext;
 
 public class DmlSyntacticValidator extends CommonSyntacticValidator implements DmlListener {
 
-	public DmlSyntacticValidator(CustomErrorListener errorListener, HashMap<String,String> argVals) {
+	public DmlSyntacticValidator(CustomErrorListenerInner errorListener, HashMap<String,String> argVals) {
 		super(errorListener, argVals);
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/45d56a58/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java b/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java
index 3d816d3..ad49b44 100644
--- a/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java
+++ b/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java
@@ -44,7 +44,7 @@ import org.apache.sysml.parser.ImportStatement;
 import org.apache.sysml.parser.LanguageException;
 import org.apache.sysml.parser.ParseException;
 import org.apache.sysml.parser.Statement;
-import org.apache.sysml.parser.common.SyntacticErrorListener.CustomErrorListener;
+import org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
 import org.apache.sysml.parser.dml.DMLParserWrapper;
 import org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext;
 import org.apache.sysml.parser.pydml.PydmlParser.ProgramrootContext;
@@ -112,7 +112,7 @@ public class PyDMLParserWrapper extends AParserWrapper
 		}
 
 		ProgramrootContext ast = null;
-		CustomErrorListener errorListener = new CustomErrorListener();
+		CustomErrorListenerInner errorListener = new CustomErrorListenerInner();
 		
 		try {
 			PydmlLexer lexer = new PydmlLexer(in);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/45d56a58/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
index 7baae7a..a2a0995 100644
--- a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
@@ -58,7 +58,7 @@ import org.apache.sysml.parser.StatementBlock;
 import org.apache.sysml.parser.StringIdentifier;
 import org.apache.sysml.parser.WhileStatement;
 import org.apache.sysml.parser.common.CommonSyntacticValidator;
-import org.apache.sysml.parser.common.SyntacticErrorListener.CustomErrorListener;
+import org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
 import org.apache.sysml.parser.common.ExpressionInfo;
 import org.apache.sysml.parser.common.StatementInfo;
 import org.apache.sysml.parser.dml.DmlParser.MatrixMulExpressionContext;
@@ -118,7 +118,7 @@ import org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext;
  */
 public class PydmlSyntacticValidator extends CommonSyntacticValidator implements PydmlListener {
 
-	public PydmlSyntacticValidator(CustomErrorListener errorListener, HashMap<String,String> argVals) {
+	public PydmlSyntacticValidator(CustomErrorListenerInner errorListener, HashMap<String,String> argVals) {
 		super(errorListener, argVals);
 	}