drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdunn...@apache.org
Subject [3/3] git commit: Improved error messages slightly.
Date Tue, 16 Oct 2012 06:19:05 GMT
Improved error messages slightly.


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

Branch: refs/heads/master
Commit: a38aa97779826c2d33d6a25656fbbc7205509777
Parents: b4e471a
Author: tdunning <tdunning@apache.org>
Authored: Mon Oct 15 15:48:35 2012 -0700
Committer: tdunning <tdunning@apache.org>
Committed: Mon Oct 15 15:48:35 2012 -0700

----------------------------------------------------------------------
 sandbox/plan-parser/pom.xml                        |    2 +-
 .../main/antlr3/org/apache/drill/plan/ast/Plan.g   |   66 ++++++++++++---
 .../java/org/apache/drill/plan/ParsePlanTest.java  |   26 ++++++
 .../src/test/resources/bad-plan1.drillx            |    3 +
 .../src/test/resources/bad-plan2.drillx            |    1 +
 5 files changed, 86 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a38aa977/sandbox/plan-parser/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/plan-parser/pom.xml b/sandbox/plan-parser/pom.xml
index f5ccb00..2bea908 100644
--- a/sandbox/plan-parser/pom.xml
+++ b/sandbox/plan-parser/pom.xml
@@ -6,7 +6,7 @@
 
     <groupId>plan-parser</groupId>
     <artifactId>plan-parser</artifactId>
-    <version>0.1</version>
+    <version>0.1-SNAPSHOT</version>
   <dependencies>
     <dependency>
       <groupId>com.google.guava</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a38aa977/sandbox/plan-parser/src/main/antlr3/org/apache/drill/plan/ast/Plan.g
----------------------------------------------------------------------
diff --git a/sandbox/plan-parser/src/main/antlr3/org/apache/drill/plan/ast/Plan.g b/sandbox/plan-parser/src/main/antlr3/org/apache/drill/plan/ast/Plan.g
index 69a9ffb..65c7172 100644
--- a/sandbox/plan-parser/src/main/antlr3/org/apache/drill/plan/ast/Plan.g
+++ b/sandbox/plan-parser/src/main/antlr3/org/apache/drill/plan/ast/Plan.g
@@ -13,10 +13,18 @@ import com.google.common.collect.Lists;
 package org.apache.drill.plan.ast;
 }
 
+@lexer::members {
+  Stack<String> paraphrase = new Stack<String>();
+}
+
 @members {
+  Stack<String> paraphrase = new Stack<String>();
   public void reportError(RecognitionException e) {
-    throw new LogicalPlanParseException("Syntax error in schema: ", e);
+      throw new LogicalPlanParseException(
+           String.format("Syntax error in schema line \%d:\%d ", e.line, e.charPositionInLine),
+           e);
   }
+
 }
 
 plan returns [Plan r]: s=statements EOF {$r = $s.r;};
@@ -46,14 +54,50 @@ arg returns [Arg r]:
     ;
 
 
-STRING: ('"'|'�') ( ~('"' | '\\') | '\\' .)* ('"'|'�') ;
-GETS: ':=' ;
-BOOLEAN: 'true'|'false';
-SYMBOL: '%' ('0'..'9')+;
-OP: ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'-')*
+STRING
+@init { paraphrase.push("a string"); }
+@after { paraphrase.pop(); }
+  : ('"'|'\u201c') ( ~('"' | '\\') | '\\' .)* ('"'|'\u201d') ;
+
+GETS
+@init { paraphrase.push(":="); }
+@after { paraphrase.pop(); }
+  : ':=' ;
+
+BOOLEAN
+@init { paraphrase.push("a boolean value"); }
+@after { paraphrase.pop(); }
+  : 'true'|'false';
+
+SYMBOL
+@init { paraphrase.push("a percent-symbol"); }
+@after { paraphrase.pop(); }
+  : '%' ('0'..'9')+;
+
+OP
+@init { paraphrase.push("an operator"); }
+@after { paraphrase.pop(); }
+  : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'-')*
     | '>' | '<' | '>=' | '<=' | '+' | '-' | '*' | '/';
-COMMA: ',' ;
-NUMBER: ('0'..'9')+ ;
-LINE_ENDING: '\r'? '\n';
-COMMENT: '#' (~'\n')* {$channel=HIDDEN;} ;
-WHITESPACE : ( '\t' | ' ' )+ { $channel = HIDDEN; } ;
+
+COMMA
+@init { paraphrase.push("a comma"); }
+@after { paraphrase.pop(); }
+  : ',' ;
+
+NUMBER
+@init { paraphrase.push("a number"); }
+@after { paraphrase.pop(); }
+  : ('0'..'9')+ ;
+
+LINE_ENDING
+@init { paraphrase.push("an end of line"); }
+@after { paraphrase.pop(); }
+  : '\r'? '\n';
+
+COMMENT
+@init { paraphrase.push("a comment"); }
+@after { paraphrase.pop(); }
+  : '#' (~'\n')* {$channel=HIDDEN;} ;
+
+WHITESPACE: ( '\t' | ' ' )+ { $channel = HIDDEN; } ;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a38aa977/sandbox/plan-parser/src/test/java/org/apache/drill/plan/ParsePlanTest.java
----------------------------------------------------------------------
diff --git a/sandbox/plan-parser/src/test/java/org/apache/drill/plan/ParsePlanTest.java b/sandbox/plan-parser/src/test/java/org/apache/drill/plan/ParsePlanTest.java
index e90e8e4..32f64df 100644
--- a/sandbox/plan-parser/src/test/java/org/apache/drill/plan/ParsePlanTest.java
+++ b/sandbox/plan-parser/src/test/java/org/apache/drill/plan/ParsePlanTest.java
@@ -33,6 +33,8 @@ import java.util.Iterator;
 import java.util.List;
 
 import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
 
 public class ParsePlanTest {
     @Test
@@ -54,6 +56,30 @@ public class ParsePlanTest {
     }
 
     @Test
+    public void testParseError1() throws IOException, RecognitionException, ParsePlan.ValidationException
{
+        try {
+            ParsePlan.parseResource("bad-plan1.drillx");
+            fail("Should have thrown exception");
+        } catch (ParsePlan.ValidationException e) {
+            assertTrue(e.getMessage().contains("%2 used more than once"));
+            assertTrue(e.getMessage().contains("Undefined reference to %3"));
+        }
+    }
+
+    @Test
+    public void testParseError2() throws IOException, RecognitionException, ParsePlan.ValidationException
{
+        try {
+            ParsePlan.parseResource("bad-plan2.drillx");
+            fail("Should have thrown exception");
+        } catch (ParsePlan.ValidationException e) {
+            assertTrue(e.getMessage().contains("%2 used more than once"));
+            assertTrue(e.getMessage().contains("Undefined reference to %3"));
+        }
+    }
+
+
+
+    @Test
     public void testLexer() throws IOException {
         List<String> ref = Lists.newArrayList(
                 "%3", ",", "%4", ":=", "explode", "\"data\"", ",", "\"var-to-explode\"",
"\n",

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a38aa977/sandbox/plan-parser/src/test/resources/bad-plan1.drillx
----------------------------------------------------------------------
diff --git a/sandbox/plan-parser/src/test/resources/bad-plan1.drillx b/sandbox/plan-parser/src/test/resources/bad-plan1.drillx
new file mode 100644
index 0000000..efa98e2
--- /dev/null
+++ b/sandbox/plan-parser/src/test/resources/bad-plan1.drillx
@@ -0,0 +1,3 @@
+%1 := scan-json "table-1"	# normal
+%2 := bind "x", %3		    # undefined reference
+%2 := bind "y", %2		    # duplicate def

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/a38aa977/sandbox/plan-parser/src/test/resources/bad-plan2.drillx
----------------------------------------------------------------------
diff --git a/sandbox/plan-parser/src/test/resources/bad-plan2.drillx b/sandbox/plan-parser/src/test/resources/bad-plan2.drillx
new file mode 100644
index 0000000..db49ad7
--- /dev/null
+++ b/sandbox/plan-parser/src/test/resources/bad-plan2.drillx
@@ -0,0 +1 @@
+%3 := "bind" "y", %2		# Op in quotes


Mime
View raw message