Revision: 1890
          http://svn.sourceforge.net/vexi/?rev=1890&view=rev
Author:   mkpg2
Date:     2007-06-28 10:36:20 -0700 (Thu, 28 Jun 2007)

Log Message:
-----------
Fix. Linenumbering was off sometimes. 
       - Particularly if statements finished without a terminating ';' this 
messed up the
         line of the following statement.
       - Root cause was that pushbacked tokens were not setting parserLine when
         fetched for the second time.

Modified Paths:
--------------
    core/trunk/org.ibex.js/src/org/ibex/js/Lexer.jpp
    core/trunk/org.ibex.js/src/org/ibex/js/Parser.java
    core/trunk/org.ibex.js/src_junit/test/js/TestJS.java
    core/trunk/org.ibex.js/src_junit/test/parse/TestParse.java

Added Paths:
-----------
    core/trunk/org.ibex.js/src_junit/test/parse/unterminated.js

Modified: core/trunk/org.ibex.js/src/org/ibex/js/Lexer.jpp
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/Lexer.jpp    2007-06-28 17:25:18 UTC 
(rev 1889)
+++ core/trunk/org.ibex.js/src/org/ibex/js/Lexer.jpp    2007-06-28 17:36:20 UTC 
(rev 1890)
@@ -354,7 +354,8 @@
     private int pushBackDepth = 0;
     private int[] pushBackInts = new int[10];
     private Object[] pushBackObjects = new Object[10];
-
+    private int[] pushBackLines = new int[10];
+    
     /** push back a token */
     public final void pushBackToken(int op, Object obj) {
         if (pushBackDepth >= pushBackInts.length - 1) {
@@ -364,9 +365,16 @@
             Object[] newObjects = new Object[pushBackObjects.length * 2];
             System.arraycopy(pushBackObjects, 0, newObjects, 0, 
pushBackObjects.length);
             pushBackObjects = newObjects;
+            int[] newLines = new int[pushBackLines.length * 2];
+            System.arraycopy(pushBackLines, 0, newInts, 0, 
pushBackLines.length);
+            pushBackLines = newLines;
         }
         pushBackInts[pushBackDepth] = op;
         pushBackObjects[pushBackDepth] = obj;
+        // REMARK - do we really need to remember every line number? We have
+        // pushBackLines[0] == line. This would be enough to fix the line
+        // numbering of statements that aren't properly terminated with a ;
+        pushBackLines[pushBackDepth] = parserLine;
         pushBackDepth++;
     }
 
@@ -394,6 +402,11 @@
             number = pushBackObjects[pushBackDepth] instanceof Number ? 
(Number)pushBackObjects[pushBackDepth] : null;
             string = pushBackObjects[pushBackDepth] instanceof String ? 
(String)pushBackObjects[pushBackDepth] : null;
         }
+        // REMARK - pushBackLines[0]==line. This would be enough to have 
correct
+        // line numbers for unterminated statements (no ;). Possibly we don't 
need to
+        // remember the ln of every pushedBack token (??). Not inviting edge 
cases
+        // and doing it anyway.
+        parserLine = pushBackLines[pushBackDepth];
         return op;
     }
 

Modified: core/trunk/org.ibex.js/src/org/ibex/js/Parser.java
===================================================================
--- core/trunk/org.ibex.js/src/org/ibex/js/Parser.java  2007-06-28 17:25:18 UTC 
(rev 1889)
+++ core/trunk/org.ibex.js/src/org/ibex/js/Parser.java  2007-06-28 17:36:20 UTC 
(rev 1890)
@@ -266,7 +266,7 @@
 
     /** gets a token and throws an exception if it is not <tt>code</tt> */
     private void consume(int code) throws IOException {
-        if (getToken() != code) {
+       if (getToken() != code) {
             if(code == NAME) switch(op) {
                 case RETURN: case TYPEOF: case KEYSOF: case BREAK: case 
CONTINUE: case TRY: case THROW:
                 case ASSERT: case NULL: case TRUE: case FALSE: case IN: case 
IF: case ELSE:
@@ -1085,7 +1085,8 @@
                 pushBackToken(NAME, possiblyTheLabel);  
                 startExpr(b, -1);
                 b.add(parserLine, POP);
-                if ((mostRecentlyReadToken != RC || peekToken() == SEMI) && 
peekToken() != -1 && mostRecentlyReadToken != SEMI) consume(SEMI);
+                if ((mostRecentlyReadToken != RC || peekToken() == SEMI) && 
peekToken() != -1 && mostRecentlyReadToken != SEMI) 
+                       consume(SEMI);
                 break;
             }
         }

Modified: core/trunk/org.ibex.js/src_junit/test/js/TestJS.java
===================================================================
--- core/trunk/org.ibex.js/src_junit/test/js/TestJS.java        2007-06-28 
17:25:18 UTC (rev 1889)
+++ core/trunk/org.ibex.js/src_junit/test/js/TestJS.java        2007-06-28 
17:36:20 UTC (rev 1890)
@@ -9,6 +9,7 @@
 import test.js.string.TestString;
 import test.js.traps.TestTraps;
 import test.js.traps_pause_on_put.TestPauseOnPut;
+import test.parse.TestParse;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -20,7 +21,8 @@
        ///
        
        public static Test suite() {
-       TestSuite suite = new 
TestSuite(JSTestSuite.nameFromClass(TestJS.class));
+       TestSuite rootsuite = new 
TestSuite(JSTestSuite.nameFromClass(TestJS.class));
+       TestSuite suite = new TestSuite("execution");
        suite.addTest(TestArray.suite());
        suite.addTest(TestExceptions.suite());
        suite.addTest(TestGeneral.suite());
@@ -29,6 +31,8 @@
        suite.addTest(TestTraps.suite());
        suite.addTest(TestPauseOnPut.suite());
        suite.addTest(TestXmlRpc.suite());
-       return suite;
+       rootsuite.addTest(suite);
+       rootsuite.addTestSuite(TestParse.class);
+       return rootsuite;
     }
 }

Modified: core/trunk/org.ibex.js/src_junit/test/parse/TestParse.java
===================================================================
--- core/trunk/org.ibex.js/src_junit/test/parse/TestParse.java  2007-06-28 
17:25:18 UTC (rev 1889)
+++ core/trunk/org.ibex.js/src_junit/test/parse/TestParse.java  2007-06-28 
17:36:20 UTC (rev 1890)
@@ -18,6 +18,12 @@
 
 public class TestParse extends TestCase {
 
+       /** These are really Line number tests.
+        * 
+        * TODO - Preprocessing to have accurate line numbers embedded
+        * in the tokens is the way forward (core tests have something 
similar). 
+        */
+       
        String resourceDir;
        
        public TestParse(){
@@ -42,8 +48,24 @@
                }
        }
        
+       public void testUnterminated() throws Throwable{
+               JS f = parseFile("unterminated.js");
+               String[] lines = DevUtil.dump(f).split("\n");
+               for(int i=0; i<lines.length; i++){
+                       if(lines[i].contains(" y")){
+                               Pattern p = Pattern.compile("\\(.*\\)");
+                               Matcher m = p.matcher(lines[i]);
+                               if(!m.find()){
+                                       fail("Expected " + p.pattern());
+                               }
+                               String ln = m.group();
+                               ln = ln.substring(1, ln.length()-1);
+                               assertEquals("7", ln);
+                       }
+                               
+               }
+       }
        
-       
        InputStream getInputStreamForFile(String fileName) throws 
FileNotFoundException{
                File f = new File(resourceDir, fileName);
                if(f.exists())

Added: core/trunk/org.ibex.js/src_junit/test/parse/unterminated.js
===================================================================
--- core/trunk/org.ibex.js/src_junit/test/parse/unterminated.js                 
        (rev 0)
+++ core/trunk/org.ibex.js/src_junit/test/parse/unterminated.js 2007-06-28 
17:36:20 UTC (rev 1890)
@@ -0,0 +1,9 @@
+
+
+o.x = function(){
+
+}
+
+o.y = function(){
+
+}
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to