felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From db...@apache.org
Subject svn commit: r956567 - in /felix/trunk/gogo/runtime/src: main/java/org/apache/felix/gogo/runtime/Tokenizer.java test/java/org/apache/felix/gogo/runtime/TestParser2.java
Date Mon, 21 Jun 2010 13:11:05 GMT
Author: dbaum
Date: Mon Jun 21 13:11:05 2010
New Revision: 956567

URL: http://svn.apache.org/viewvc?rev=956567&view=rev
Log:
FELIX-2433 allow "$(...)" expansion

Modified:
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java
    felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java?rev=956567&r1=956566&r2=956567&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Tokenizer.java Mon
Jun 21 13:11:05 2010
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.gogo.runtime;
 
-
 /**
  * Bash-like tokenizer.
  * 
@@ -469,14 +468,14 @@ public class Tokenizer
      * expand variables, quotes and escapes in word.
      * @param vars
      * @return
+     * @throws Exception 
      */
-    public static Object expand(CharSequence word, Evaluate eval)
+    public static Object expand(CharSequence word, Evaluate eval) throws Exception
     {
         return expand(word, eval, false);
     }
 
-    private static Object expand(CharSequence word, Evaluate eval,
-        boolean inQuote)
+    private static Object expand(CharSequence word, Evaluate eval, boolean inQuote) throws
Exception
     {
         final String special = "$\\\"'";
         int i = word.length();
@@ -492,7 +491,7 @@ public class Tokenizer
         return new Tokenizer(word, eval, inQuote).expand();
     }
 
-    public Object expand(CharSequence word, short line, short column)
+    public Object expand(CharSequence word, short line, short column) throws Exception
     {
         return expand(new Token(Type.WORD, word, line, column), evaluate, inQuote);
     }
@@ -502,7 +501,7 @@ public class Tokenizer
         return new Token(Type.WORD, value, line, column);
     }
 
-    private Object expand()
+    private Object expand() throws Exception
     {
         StringBuilder buf = new StringBuilder();
 
@@ -581,27 +580,37 @@ public class Tokenizer
         return buf.toString();
     }
 
-    private Object expandVar()
+    private Object expandVar() throws Exception
     {
         assert '$' == ch;
         Object val;
 
         if (getch() != '{')
         {
-            int start = index - 1;
-            while (isName(ch))
-            {
+            if ('(' == ch)
+            { // support $(...) FELIX-2433
+                short sLine = line;
+                short sCol = column;
+                val = evaluate.eval(new Token(Type.EXECUTION, group(), sLine, sCol));
                 getch();
             }
-
-            if (index - 1 == start)
-            {
-                val = "$";
-            }
             else
             {
-                String name = text.subSequence(start, index - 1).toString();
-                val = evaluate.get(name);
+                int start = index - 1;
+                while (isName(ch))
+                {
+                    getch();
+                }
+
+                if (index - 1 == start)
+                {
+                    val = "$";
+                }
+                else
+                {
+                    String name = text.subSequence(start, index - 1).toString();
+                    val = evaluate.get(name);
+                }
             }
         }
         else

Modified: felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java?rev=956567&r1=956566&r2=956567&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java
(original)
+++ felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/TestParser2.java
Mon Jun 21 13:11:05 2010
@@ -59,11 +59,18 @@ public class TestParser2 extends TestCas
     {
         Context c = new Context();
         c.addCommand("echo", this);
-
         // FELIX-2432
         assertEquals("null x", c.execute("echo $expandsToNull x"));
     }
 
+    public void testStringExecution() throws Exception
+    {
+        Context c = new Context();
+        c.addCommand("echo", this);
+        // FELIX-2433
+        assertEquals("helloworld", c.execute("echo \"$(echo hello)world\""));
+    }
+
     public CharSequence echo(Object args[])
     {
         if (args == null)



Mime
View raw message