You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2009/07/08 08:16:57 UTC
svn commit: r792047 - in /felix/trunk/gogo/runtime/src:
main/java/org/apache/felix/gogo/runtime/shell/Closure.java
main/java/org/apache/felix/gogo/runtime/shell/Parser.java
test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
Author: gnodet
Date: Wed Jul 8 06:16:57 2009
New Revision: 792047
URL: http://svn.apache.org/viewvc?rev=792047&view=rev
Log:
Better formatting, fix special values (true, false, null), fix -bash, ... parsing
Modified:
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Parser.java
felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java?rev=792047&r1=792046&r2=792047&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java Wed Jul 8 06:16:57 2009
@@ -212,25 +212,33 @@
StringBuilder sb = null;
Parser p = new Parser(seq);
int start = p.current;
- while (!p.eof()) {
+ while (!p.eof())
+ {
char c = p.peek();
- if (!p.escaped) {
- if (c == '$' || c == '<' || c == '\'' || c == '"' || c == '[' || c == '{') {
- if (start != p.current || res != null) {
- if (sb == null) {
+ if (!p.escaped)
+ {
+ if (c == '$' || c == '<' || c == '\'' || c == '"' || c == '[' || c == '{')
+ {
+ if (start != p.current || res != null)
+ {
+ if (sb == null)
+ {
sb = new StringBuilder();
- if (res != null) {
+ if (res != null)
+ {
sb.append(res);
res = null;
}
}
- if (start != p.current) {
+ if (start != p.current)
+ {
sb.append(new Parser(p.text.subSequence(start, p.current)).unescape());
start = p.current;
continue;
}
}
- switch (c) {
+ switch (c)
+ {
case '\'':
p.next();
p.quote(c);
@@ -269,25 +277,45 @@
}
p.next();
}
- if (start != p.current) {
- if (sb == null) {
+ if (start != p.current)
+ {
+ if (sb == null)
+ {
sb = new StringBuilder();
- if (res != null) {
+ if (res != null)
+ {
sb.append(res);
res = null;
}
}
sb.append(new Parser(p.text.subSequence(start, p.current)).unescape());
}
- if (sb != null) {
- if (res != null) {
+ if (sb != null)
+ {
+ if (res != null)
+ {
sb.append(res);
}
- return sb.toString();
+ res = sb;
}
- if (res instanceof CharSequence) {
- return res.toString();
+ if (res instanceof CharSequence)
+ {
+ String r = res.toString();
+ if ("null".equals(r))
+ {
+ return null;
+ }
+ else if ("false".equals(r))
+ {
+ return false;
+ }
+ else if ("true".equals(r))
+ {
+ return true;
+ }
+ return r;
}
+
return res;
}
Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Parser.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Parser.java?rev=792047&r1=792046&r2=792047&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Parser.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Parser.java Wed Jul 8 06:16:57 2009
@@ -372,7 +372,7 @@
return text.subSequence(start, end);
}
- if (Character.isJavaIdentifierStart(c))
+ if (Character.isJavaIdentifierPart(c))
{
while (c == '$') {
c = next();
Modified: felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java?rev=792047&r1=792046&r2=792047&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java (original)
+++ felix/trunk/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java Wed Jul 8 06:16:57 2009
@@ -35,6 +35,13 @@
{
int beentheredonethat = 0;
+ public void testSpecialValues() throws Exception {
+ Context c = new Context();
+ assertEquals(false, c.execute("false"));
+ assertEquals(true, c.execute("true"));
+ assertEquals(null, c.execute("null"));
+ }
+
public void testQuotes() throws Exception {
Context c = new Context();
c.addCommand("echo", this);
@@ -107,12 +114,16 @@
{
Context c = new Context();
c.addCommand("echo", this);
+ c.addCommand("capture", this);
+
assertEquals("http://www.aqute.biz?com=2&biz=1", c.execute("['http://www.aqute.biz?com=2&biz=1'] get 0").toString());
assertEquals("{a=2, b=3}", c.execute("[a=2 b=3]").toString());
assertEquals("3", c.execute("[a=2 <b>=<3>] get b").toString());
assertEquals("[3, 4]", c.execute("[1 2 [3 4] 5 6] get 2").toString());
assertEquals(5, c.execute("[1 2 [3 4] 5 6] size"));
-
+ assertEquals("a", c.execute("e = { echo $0 } ; <e a b | capture>"));
+ assertEquals("b", c.execute("e = { echo $1 } ; <e a b | capture>"));
+ assertEquals("a b", c.execute("e = { echo $args } ; <e a b | capture>"));
}
public void testArray() throws Exception