Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8688B6D30 for ; Tue, 14 Jun 2011 20:03:39 +0000 (UTC) Received: (qmail 93736 invoked by uid 500); 14 Jun 2011 20:03:39 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 93671 invoked by uid 500); 14 Jun 2011 20:03:39 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 93664 invoked by uid 99); 14 Jun 2011 20:03:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jun 2011 20:03:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jun 2011 20:03:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0BF132388A3D; Tue, 14 Jun 2011 20:03:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1135771 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl2/parser/ site/xdoc/ site/xdoc/reference/ test/java/org/apache/commons/jexl2/ Date: Tue, 14 Jun 2011 20:03:13 -0000 To: commits@commons.apache.org From: henrib@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110614200314.0BF132388A3D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: henrib Date: Tue Jun 14 20:03:13 2011 New Revision: 1135771 URL: http://svn.apache.org/viewvc?rev=1135771&view=rev Log: Related to JEXL-24, JEXL-112: Added notation for octal and hexadecimal natural literals (ie int as default, long as 'l' or 'L', big-integer as 'b' or 'B' as in big); mod Parser.jjt / ASTNumberLiteral.java Added notation for exponents for real literals (ie float as default, double as 'D' or 'd', big-decimal as 'h' or 'H' as in huge); mod Parser.jjt / ASTNumberLiteral.java Added specific tests; Initial documentation update; Updated changes.xml to reflect bug fixes Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTNumberLiteral.java commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt commons/proper/jexl/trunk/src/site/xdoc/changes.xml commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTNumberLiteral.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTNumberLiteral.java?rev=1135771&r1=1135770&r2=1135771&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTNumberLiteral.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTNumberLiteral.java Tue Jun 14 20:03:13 2011 @@ -32,7 +32,7 @@ public class ASTNumberLiteral extends Je public ASTNumberLiteral(Parser p, int id) { super(p, id); } - + /** * Gets the literal value. * @return the number literal @@ -40,78 +40,109 @@ public class ASTNumberLiteral extends Je public Number getLiteral() { return literal; } - + /** {@inheritDoc} */ @Override public Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } - + public Class getLiteralClass() { return clazz; } - + public boolean isInteger() { return Integer.class.equals(clazz); } - - public boolean isDouble() { - return Double.class.equals(clazz); - } - + + /** + * Sets this node as a natural literal. + * Originally from OGNL. + * @param s the natural as string + */ public void setNatural(String s) { Number result; Class rclass; - int last = s.length() - 1; + // determine the base + final int base; + if (s.charAt(0) == '0') { + if ((s.length() > 1 && (s.charAt(1) == 'x' || s.charAt(1) == 'X'))) { + base = 16; + s = s.substring(2); // Trim the 0x off the front + } else { + base = 8; + } + } else { + base = 10; + } + final int last = s.length() - 1; switch (s.charAt(last)) { case 'l': - case 'L': - result = Long.valueOf(s.substring(0, last)); + case 'L': { rclass = Long.class; + result = Long.valueOf(s.substring(0, last), base); break; + } case 'h': - case 'H': - result = new BigInteger(s.substring(0, last)); + case 'H': { rclass = BigInteger.class; + result = new BigInteger(s.substring(0, last), base); break; - default: + } + default: { rclass = Integer.class; try { - result = Integer.valueOf(s); - } catch(NumberFormatException xnumber) { - result = Long.valueOf(s); + result = Integer.valueOf(s, base); + } catch (NumberFormatException take2) { + try { + result = Long.valueOf(s, base); + } catch (NumberFormatException take3) { + result = new BigInteger(s, base); + } } - break; + } } literal = result; clazz = rclass; } + /** + * Sets this node as a real literal. + * Originally from OGNL. + * @param s the real as string + */ public void setReal(String s) { Number result; Class rclass; - int last = s.length() - 1; + final int last = s.length() - 1; switch (s.charAt(last)) { case 'b': - case 'B': + case 'B': { result = new BigDecimal(s.substring(0, last)); rclass = BigDecimal.class; break; + } case 'd': - case 'D': - result = Double.valueOf(s); + case 'D': { rclass = Double.class; + result = Double.valueOf(s); break; + } case 'f': case 'F': - default: + default: { rclass = Float.class; try { result = Float.valueOf(s); - } catch(NumberFormatException xnumber) { - result = Double.valueOf(s); + } catch (NumberFormatException take2) { + try { + result = Double.valueOf(s); + } catch (NumberFormatException take3) { + result = new BigDecimal(s); + } } break; + } } literal = result; clazz = rclass; Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt?rev=1135771&r1=1135770&r2=1135771&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt Tue Jun 14 20:03:13 2011 @@ -170,7 +170,7 @@ PARSER_END(Parser) (["l","L","h","H"])? > | - < FLOAT_LITERAL: ()+ "."()+ (["d","D","f","F","b","B"])? > + < FLOAT_LITERAL: ()+ "." ()+ ((["e","E"])(["+","-"])?()+)? (["d","D","f","F","b","B"])? > } <*> TOKEN : Modified: commons/proper/jexl/trunk/src/site/xdoc/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/site/xdoc/changes.xml?rev=1135771&r1=1135770&r2=1135771&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/jexl/trunk/src/site/xdoc/changes.xml Tue Jun 14 20:03:13 2011 @@ -26,6 +26,12 @@ + + Cannot parse Integer.MIN_VALUE. + + + Support Long for integer literal instead of Integers. + Added ObjectContext that wraps an object as JexlContext and added JexlContext as source to solve top-level namespace functions. Modified: commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml?rev=1135771&r1=1135770&r2=1135771&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml (original) +++ commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml Tue Jun 14 20:03:13 2011 @@ -130,39 +130,45 @@ ItemDescription Integer Literals - 1 or more digits from 0 to 9 + 1 or more digits from 0 to 9, eg 42. + - Long Literals - 1 or more digits from 0 to 9, followed by l or L + Float Literals + + 1 or more digits from 0 to 9, followed + by a decimal point and then one or more digits from + 0 to 9, eg 42.0. + - BigInteger Literals - 1 or more digits from 0 to 9, followed by h or H. + Long Literals + 1 or more digits from 0 to 9 suffixed with l or L + , eg 42.0l. + - BigDecimal Literals + Double Literals 1 or more digits from 0 to 9, followed by a decimal point and then one or more digits from - 0 to 9, followed by b or B. + 0 to 9 suffixed with d or D + , eg 42.0d.. - Floating point Literals - - 1 or more digits from 0 to 9, followed - by a decimal point and then one or more digits from - 0 to 9, - optionally followed by f or F. + Big Integer Literals + 1 or more digits from 0 to 9 suffixed with b or B + , eg 42B. - Double Literals + Big Decimal Literals 1 or more digits from 0 to 9, followed by a decimal point and then one or more digits from - 0 to 9, followed by d or D. + 0 to 9 suffixed with h or H (for Huge ala OGNL)) + , eg 42.0H. Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=1135771&r1=1135770&r2=1135771&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java Tue Jun 14 20:03:13 2011 @@ -64,7 +64,32 @@ public class IssuesTest extends JexlTest assertEquals(new BigInteger("10"), vars.get("b")); assertEquals(new BigDecimal("42.0"), vars.get("c")); assertEquals(new BigDecimal("42.0"), vars.get("d")); + } + + // JEXL-24: big decimals with exponent + public void test24C() throws Exception { + Map vars = new HashMap(); + JexlContext ctxt = new MapContext(vars); + String stmt = "{a = 42.0e1B; b = 42.0E+2B; c = 42.0e-1B; d = 42.0E-2b;}"; + Script expr = JEXL.createScript(stmt); + /* Object value = */ expr.execute(ctxt); + assertEquals(new BigDecimal("42.0e+1"), vars.get("a")); + assertEquals(new BigDecimal("42.0e+2"), vars.get("b")); + assertEquals(new BigDecimal("42.0e-1"), vars.get("c")); + assertEquals(new BigDecimal("42.0e-2"), vars.get("d")); + } + // JEXL-24: doubles with exponent + public void test24D() throws Exception { + Map vars = new HashMap(); + JexlContext ctxt = new MapContext(vars); + String stmt = "{a = 42.0e1D; b = 42.0E+2D; c = 42.0e-1d; d = 42.0E-2d;}"; + Script expr = JEXL.createScript(stmt); + /* Object value = */ expr.execute(ctxt); + assertEquals(Double.valueOf("42.0e+1"), vars.get("a")); + assertEquals(Double.valueOf("42.0e+2"), vars.get("b")); + assertEquals(Double.valueOf("42.0e-1"), vars.get("c")); + assertEquals(Double.valueOf("42.0e-2"), vars.get("d")); } // JEXL-49: blocks not parsed (fixed)