[dna-commits] DNA SVN: r1332 - in branches/ddl_sequencer/dna-graph/src: test/java/org/jboss/dna/graph/query/parse and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Nov 19 18:08:36 EST 2009


Author: blafond
Date: 2009-11-19 18:08:36 -0500 (Thu, 19 Nov 2009)
New Revision: 1332

Modified:
   branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/query/parse/SqlQueryParser.java
   branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/query/parse/SqlQueryParserTest.java
Log:
Fixed problem in token positions having the wrong column number.

Modified: branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/query/parse/SqlQueryParser.java
===================================================================
--- branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/query/parse/SqlQueryParser.java	2009-11-19 23:07:26 UTC (rev 1331)
+++ branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/query/parse/SqlQueryParser.java	2009-11-19 23:08:36 UTC (rev 1332)
@@ -398,15 +398,12 @@
     }
 
     protected Term parseFullTextSearchExpression( String expression,
-                                                  Position position ) {
+                                                  Position startOfExpression ) {
         try {
             return new FullTextSearchParser().parse(expression);
         } catch (ParsingException e) {
             // Convert the position in the exception into a position in the query.
-            Position exprPos = e.getPosition();
-            int line = position.getLine() + exprPos.getLine() - 1;
-            int column = exprPos.getLine() == 1 ? exprPos.getColumn() + position.getColumn() : exprPos.getColumn();
-            Position queryPos = new Position(line, column);
+            Position queryPos = startOfExpression.add(e.getPosition());
             throw new ParsingException(queryPos, e.getMessage());
         }
     }
@@ -864,14 +861,14 @@
                     case '|':
                     case '=':
                     case ':':
-                        tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+                        tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
                         break;
                     case '\'':
                     case '[':
                     case '\"':
                         int startIndex = input.index();
                         char closingChar = c == '[' ? ']' : c;
-                        Position pos = input.position();
+                        Position pos = input.position(startIndex);
                         boolean foundClosingQuote = false;
                         while (input.hasNext()) {
                             c = input.next();
@@ -896,7 +893,7 @@
                         break;
                     case '-':
                         startIndex = input.index();
-                        pos = input.position();
+                        pos = input.position(input.index());
                         if (input.isNext('-')) {
                             // End-of-line comment ...
                             boolean foundLineTerminator = false;
@@ -914,13 +911,13 @@
                                 tokens.addToken(pos, startIndex, endIndex, COMMENT);
                             }
                         } else {
-                            tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+                            tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
                             break;
                         }
                         break;
                     case '/':
                         startIndex = input.index();
-                        pos = input.position();
+                        pos = input.position(input.index());
                         if (input.isNext('*')) {
                             // Multi-line comment ...
                             while (input.hasNext() && !input.isNext('*', '/')) {
@@ -933,13 +930,13 @@
                                 tokens.addToken(pos, startIndex, endIndex, COMMENT);
                             }
                         } else {
-                            tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+                            tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
                             break;
                         }
                         break;
                     default:
                         startIndex = input.index();
-                        pos = input.position();
+                        pos = input.position(input.index());
                         // Read as long as there is a valid XML character ...
                         int tokenType = (Character.isLetterOrDigit(c) || c == '_') ? WORD : OTHER;
                         while (input.isNextLetterOrDigit() || input.isNext('_')) {

Modified: branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/query/parse/SqlQueryParserTest.java
===================================================================
--- branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/query/parse/SqlQueryParserTest.java	2009-11-19 23:07:26 UTC (rev 1331)
+++ branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/query/parse/SqlQueryParserTest.java	2009-11-19 23:08:36 UTC (rev 1332)
@@ -625,7 +625,7 @@
 
     @Test
     public void shouldParseFullTextSearchExpressionFromStringWithValidExpression() {
-        Position pos = new Position(100, 13);
+        Position pos = new Position(500, 100, 13);
         FullTextSearch.Term result = parser.parseFullTextSearchExpression("term1 term2 OR -term3 OR -term4 OR term5", pos);
         assertThat(result, is(notNullValue()));
         assertThat(result, is(instanceOf(Disjunction.class)));
@@ -644,11 +644,12 @@
     @Test
     public void shouldConvertPositionWhenUnableToParseFullTextSearchExpression() {
         try {
-            parser.parseFullTextSearchExpression("", new Position(100, 13));
+            parser.parseFullTextSearchExpression("", new Position(500, 100, 13));
             fail("Should have thrown an exception");
         } catch (ParsingException e) {
             assertThat(e.getPosition().getLine(), is(100));
             assertThat(e.getPosition().getColumn(), is(13));
+            assertThat(e.getPosition().getIndexInContent(), is(500));
         }
     }
 



More information about the dna-commits mailing list