[jboss-svn-commits] JBL Code SVN: r8183 - in labs/jbossrules/trunk/drools-core: . src/main/java/org src/main/java/org/codehaus src/main/java/org/codehaus/jfdi src/main/java/org/codehaus/jfdi/interpreter src/main/java/org/codehaus/jfdi/interpreter/operations src/main/java/org/codehaus/jfdi/interpreter/types src/main/java/org/codehaus/jfdi/parser src/main/java/org/drools/base src/main/java/org/drools/base/dataproviders src/main/java/org/drools/reteoo src/main/java/org/drools/spi
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Dec 10 14:57:04 EST 2006
Author: mark.proctor at jboss.com
Date: 2006-12-10 14:56:41 -0500 (Sun, 10 Dec 2006)
New Revision: 8183
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/SymbolTable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AbstractValueHandlerFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AnonListValue.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AnonMapValue.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/BigDecimalOverloader.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ClassTypeResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/Coercion.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/CoercionException.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/DefaultExternalVariable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/DefaultValueHandlerFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ListValue.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/LiteralValue.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/LocalVariable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MapValue.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MethodInvoker.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MethodResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/NotAnLValueException.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ObjectValue.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/OperatorOverloader.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/SymbolTableImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/TypeResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ValueHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ValueHandlerFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/VariableValueHandler.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/AdditiveExpr.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/AssignmentStatement.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/CastExpr.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/CollectionIndexExpr.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/Expr.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/ForEachInStatement.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/LogicalAndExpr.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/LogicalOrExpr.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MemberAccessExpr.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MethodCall.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MultiplicativeExpr.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/Statement.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/types/
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/types/Type.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI.g
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI.tokens
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDILexer.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDIParser.java
labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI__.g
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIDeclarationVariable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIGlobalVariable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/JFDIDataProvider.java
Removed:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/Invoker.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MethodDataProvider.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MethodInvoker.java
Modified:
labs/jbossrules/trunk/drools-core/.classpath
labs/jbossrules/trunk/drools-core/pom.xml
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/DataProvider.java
Log:
JBRULES-339 'from' support for reasoning over facts not in the working memory
-inlined JFDI
-integrated JFDI
Modified: labs/jbossrules/trunk/drools-core/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-core/.classpath 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/.classpath 2006-12-10 19:56:41 UTC (rev 8183)
@@ -2,11 +2,12 @@
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
- <classpathentry output="target/test-classes" kind="src" path="src/test/java"/>
- <classpathentry output="target/test-classes" kind="src" path="src/test/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
<classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/antlr/antlr/3.0b5/antlr-3.0b5.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Modified: labs/jbossrules/trunk/drools-core/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-core/pom.xml 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/pom.xml 2006-12-10 19:56:41 UTC (rev 8183)
@@ -33,6 +33,12 @@
<version>1.1.3.4.O</version>
</dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr</artifactId>
+ <version>3.0b5</version>
+ </dependency>
+
</dependencies>
<build>
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/SymbolTable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/SymbolTable.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/SymbolTable.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,8 @@
+package org.codehaus.jfdi;
+
+public interface SymbolTable {
+
+ Object put(String identifier, Object object);
+ Object get(String identifier);
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AbstractValueHandlerFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AbstractValueHandlerFactory.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AbstractValueHandlerFactory.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,124 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This creates value handers to attach to nodes in the AST.
+ * This is an abstract factory, of which there will be a Drools implementation
+ * (but could also be a stand alone one).
+ *
+ * @author Michael Neale
+ */
+public abstract class AbstractValueHandlerFactory
+ implements
+ Serializable,
+ ValueHandlerFactory {
+
+ private static final long serialVersionUID = 320L;
+
+ protected final TypeResolver typeResolver;
+
+ protected String[] requiredVariables;
+
+ public AbstractValueHandlerFactory(TypeResolver typeResolver) {
+ this.typeResolver = typeResolver;
+ }
+
+ /* (non-Javadoc)
+ * @see org.codehaus.jfdi.interpreter.ValueHandlerFactory#createLiteral(int, java.lang.String)
+ */
+ public ValueHandler createLiteral(Class cls,
+ String val) {
+ if ( cls.getClass() == String.class ) {
+ return new LiteralValue( val );
+ } else {
+ Object objectValue = null;
+ try {
+ objectValue = cls.getDeclaredConstructor( new Class[]{String.class} ).newInstance( new Object[]{val} );
+ } catch ( Exception e ) {
+ throw new RuntimeException( e );
+ }
+ return new LiteralValue( objectValue );
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.codehaus.jfdi.interpreter.ValueHandlerFactory#createLocalVariable(java.lang.String, java.lang.String, boolean)
+ */
+ public ValueHandler createLocalVariable(String identifier,
+ String type,
+ boolean isFinal) {
+ Class clazz = null;
+ try {
+ clazz = this.typeResolver.resolveType( type );
+ } catch ( ClassNotFoundException e ) {
+ throw new RuntimeException( e );
+ }
+
+ return new LocalVariable( identifier,
+ clazz,
+ isFinal );
+ }
+
+ /* (non-Javadoc)
+ * @see org.codehaus.jfdi.interpreter.ValueHandlerFactory#createExternalVariable(java.lang.String)
+ */
+ public abstract ValueHandler createExternalVariable(String identifier);
+
+ protected void registerExternalVariable(String identifier) {
+ // Increase the size of the array and add the new variable
+ if ( this.requiredVariables == null ) {
+ this.requiredVariables = new String[] { identifier };
+ } else {
+ String[] newArray = new String[ this.requiredVariables.length + 1];
+ System.arraycopy(this.requiredVariables,
+ 0, newArray, 0, this.requiredVariables.length );
+ newArray[ newArray.length -1 ] = identifier;
+ this.requiredVariables = newArray;
+ }
+ }
+
+ public String[] getRequiredVariables() {
+ return this.requiredVariables;
+ }
+
+ public static class MapValue {
+
+ private List list;
+
+ public MapValue() {
+ list = new ArrayList();
+ }
+
+ public void add(KeyValuePair pair) {
+ this.list.add( pair );
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return (KeyValuePair[]) this.list.toArray( new KeyValuePair[this.list.size()] );
+ }
+ }
+
+ public static class KeyValuePair {
+ private ValueHandler key;
+ private ValueHandler value;
+
+ public KeyValuePair(ValueHandler key,
+ ValueHandler value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public ValueHandler getKey() {
+ return this.key;
+ }
+
+ public ValueHandler getValue() {
+ return this.value;
+ }
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AnonListValue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AnonListValue.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AnonListValue.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,106 @@
+/**
+ *
+ */
+package org.codehaus.jfdi.interpreter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.jfdi.interpreter.operations.Expr;
+
+public class AnonListValue implements ValueHandler {
+
+ private static final long serialVersionUID = 320L;
+
+ private final Expr[] values;
+
+ private Object cachedValue = null;
+
+ public AnonListValue(final List values) {
+ this( (Expr[]) values.toArray( new Expr[ values.size() ] ) );
+ }
+
+ public AnonListValue(final Expr[] values) {
+ this.values = values;
+ }
+
+ public Object getValue() {
+ if (this.cachedValue == null) {
+ final List resolvedList = new ArrayList();
+
+ for (int i = 0; i < values.length; ++i) {
+ resolvedList.add(values[i].getValue());
+ }
+
+ this.cachedValue = resolvedList;
+ }
+ return this.cachedValue;
+ }
+
+ public Class getExtractToClass() {
+ return List.class;
+ }
+
+ public void reset() {
+ this.cachedValue = null;
+ }
+
+ public String toString() {
+ return "[ListValue list=" + Arrays.asList(values) + "]";
+ }
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + values.hashCode();
+ return result;
+ }
+
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+
+ if (object == null || getClass() != object.getClass()) {
+ return false;
+ }
+
+ final AnonListValue other = (AnonListValue) object;
+
+ if (values.length != other.values.length) {
+ return false;
+ }
+
+ for ( int i = 0 ; i < values.length ; ++i ) {
+ if ( values[i] != other.values[i] ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public Class getType() {
+ return List.class;
+ }
+
+ public boolean isFinal() {
+ return true;
+ }
+
+ public boolean isLiteral() {
+ return false;
+ }
+
+ public boolean isLocal() {
+ return false;
+ }
+
+ public void setValue(Object variable) {
+ throw new UnsupportedOperationException(
+ "Not allowed to set the value of a list.");
+ }
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AnonMapValue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AnonMapValue.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/AnonMapValue.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,136 @@
+/**
+ *
+ */
+package org.codehaus.jfdi.interpreter;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.codehaus.jfdi.interpreter.operations.Expr;
+
+public class AnonMapValue
+ implements
+ ValueHandler {
+
+ private static final long serialVersionUID = 320L;
+
+ private final KeyValuePair[] pairs;
+
+
+ private Object cachedValue = null;
+
+ public AnonMapValue(final KeyValuePair[] pairs) {
+ this.pairs = pairs;
+ }
+
+ public Object getValue() {
+ if ( this.cachedValue == null ) {
+ final Map map = new HashMap();
+
+ for ( int i = 0, length = this.pairs.length; i < length; i++ ) {
+ final Expr key = this.pairs[i].getKey();
+ final Expr value = this.pairs[i].getValue();
+ map.put( key.getValue( ),
+ value.getValue( ) );
+ }
+ this.cachedValue = map;
+ }
+
+ return this.cachedValue;
+ }
+
+ public Class getExtractToClass() {
+ return Map.class;
+ }
+
+ public void reset() {
+ this.cachedValue = null;
+ }
+
+ public static class KeyValuePair implements Serializable {
+ private static final long serialVersionUID = 320L;
+
+ private Expr key;
+ private Expr value;
+
+ public KeyValuePair(final Expr key,
+ final Expr value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ /**
+ *
+ * @return The ValueHandler for the key
+ */
+ public Expr getKey() {
+ return this.key;
+ }
+
+ /**
+ *
+ * @return The ValueHandler for the value
+ */
+ public Expr getValue() {
+ return this.value;
+ }
+
+ public String toString() {
+ return this.key + "/" + this.value;
+ }
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + this.key.hashCode();
+ result = PRIME * result + this.value.hashCode();
+ return result;
+ }
+
+ public boolean equals(Object object) {
+ if ( this == object ) {
+ return true;
+ }
+
+ if ( object == null || getClass() != object.getClass() ) {
+ return false;
+ }
+ final KeyValuePair other = (KeyValuePair) object;
+ return this.key.equals( other.key ) && this.value.equals( other.value );
+ }
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "MapValue pairs=" );
+ for ( int i = 0, length = this.pairs.length; i < length; i++ ) {
+ buffer.append( this.pairs[i] );
+ }
+ buffer.append( "]" );
+
+ return buffer.toString();
+ }
+
+
+ public Class getType() {
+ return Map.class;
+ }
+
+ public boolean isFinal() {
+ return true;
+ }
+
+ public boolean isLiteral() {
+ return false;
+ }
+
+ public boolean isLocal() {
+ return false;
+ }
+
+ public void setValue(Object variable) {
+ throw new UnsupportedOperationException("You can't change the value of a map (only the contents).");
+ }
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/BigDecimalOverloader.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/BigDecimalOverloader.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/BigDecimalOverloader.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,41 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.math.BigDecimal;
+
+
+public class BigDecimalOverloader
+ implements
+ OperatorOverloader {
+
+ public Object divide(Object left,
+ Object right) {
+ BigDecimal l = (BigDecimal) left;
+ return l.divide( (BigDecimal) right, BigDecimal.ROUND_HALF_UP );
+ }
+
+ public Class getApplicableType() {
+ return BigDecimal.class;
+ }
+
+ public Object minus(Object left,
+ Object right) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object multiply(Object left,
+ Object right) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object plus(Object left,
+ Object right) {
+ BigDecimal l = (BigDecimal) left;
+ BigDecimal r = (BigDecimal) right;
+
+ //hmmm... should the right allow a string or something else?
+ return l.add( r );
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ClassTypeResolver.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ClassTypeResolver.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ClassTypeResolver.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,226 @@
+package org.codehaus.jfdi.interpreter;
+
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class ClassTypeResolver
+ implements
+ TypeResolver {
+ private final List imports;
+
+ private final ClassLoader classLoader;
+
+ private Map cachedImports = new HashMap();
+ public ClassTypeResolver() {
+ this( Collections.EMPTY_LIST );
+ }
+
+ public ClassTypeResolver(final List imports) {
+ this( imports,
+ null );
+ }
+
+ public ClassTypeResolver(final List imports,
+ ClassLoader classLoader) {
+ this.imports = imports;
+
+ if ( classLoader == null ) {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ }
+
+ if ( classLoader == null ) {
+ classLoader = getClass().getClassLoader();
+ }
+
+ this.classLoader = classLoader;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.drools.semantics.base.Importer#getImports( Class clazz )
+ */
+ /* (non-Javadoc)
+ * @see org.drools.semantics.java.TypeResolver#getImports()
+ */
+ public List getImports() {
+ return this.imports;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.drools.semantics.base.Importer#addImports(org.drools.spi.ImportEntry)
+ */
+ /* (non-Javadoc)
+ * @see org.drools.semantics.java.TypeResolver#addImport(java.lang.String)
+ */
+ public void addImport(final String importEntry) {
+ if ( !this.imports.contains( importEntry ) ) {
+ this.imports.add( importEntry );
+ }
+ }
+
+ public Class lookupFromCache(final String className) {
+ return (Class) this.cachedImports.get( className );
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.drools.semantics.base.Importer#importClass(java.lang.ClassLoader,
+ * java.lang.String)
+ */
+ /* (non-Javadoc)
+ * @see org.drools.semantics.java.TypeResolver#resolveType(java.lang.String)
+ */
+ public Class resolveType(final String className) throws ClassNotFoundException {
+ Class clazz = null;
+
+ // Now try the package object type cache
+ clazz = lookupFromCache( className );
+
+ // try loading className
+ if ( clazz == null ) {
+ try {
+ clazz = this.classLoader.loadClass( className );
+ } catch ( final ClassNotFoundException e ) {
+ clazz = null;
+ }
+ }
+
+ // Now try the className with each of the given imports
+ if ( clazz == null ) {
+ final Set validClazzCandidates = new HashSet();
+
+ final Iterator it = this.imports.iterator();
+ while ( it.hasNext() ) {
+ clazz = importClass( (String) it.next(),
+ className );
+ if ( clazz != null ) {
+ validClazzCandidates.add( clazz );
+ }
+ }
+
+ // If there are more than one possible resolutions, complain about
+ // the ambiguity
+ if ( validClazzCandidates.size() > 1 ) {
+ final StringBuffer sb = new StringBuffer();
+ final Iterator clazzCandIter = validClazzCandidates.iterator();
+ while ( clazzCandIter.hasNext() ) {
+ if ( 0 != sb.length() ) {
+ sb.append( ", " );
+ }
+ sb.append( ((Class) clazzCandIter.next()).getName() );
+ }
+ throw new Error( "Unable to find unambiguously defined class '" + className + "', candidates are: [" + sb.toString() + "]" );
+ } else if ( validClazzCandidates.size() == 1 ) {
+ clazz = (Class) validClazzCandidates.toArray()[0];
+ } else {
+ clazz = null;
+ }
+
+ }
+
+ // Now try the java.lang package
+ if (clazz == null) {
+ clazz = defaultClass( className );
+ }
+
+ // We still can't find the class so throw an exception
+ if ( clazz == null ) {
+ throw new ClassNotFoundException( "Unable to find class '" + className + "'" );
+ }
+
+ return clazz;
+ }
+
+ private Class importClass(final String importText,
+ final String className) {
+ String qualifiedClass = null;
+ Class clazz = null;
+
+ // not python
+ if ( importText.endsWith( "*" ) ) {
+ qualifiedClass = importText.substring( 0,
+ importText.indexOf( '*' ) ) + className;
+ } else if ( importText.endsWith( "." + className ) ) {
+ qualifiedClass = importText;
+ } else if ( importText.equals( className ) ) {
+ qualifiedClass = importText;
+ }
+
+ if ( qualifiedClass != null ) {
+ try {
+ clazz = this.classLoader.loadClass( qualifiedClass );
+ } catch ( final ClassNotFoundException e ) {
+ clazz = null;
+ }
+
+ // maybe its a nested class?
+ if ( clazz == null ) {
+ try {
+ final int lastIndex = qualifiedClass.lastIndexOf( '.' );
+ qualifiedClass = qualifiedClass.substring( 0,
+ lastIndex ) + "$" + qualifiedClass.substring( lastIndex + 1 );
+ clazz = this.classLoader.loadClass( qualifiedClass );
+ } catch ( final ClassNotFoundException e ) {
+ clazz = null;
+ }
+ }
+ }
+
+ if ( clazz != null ) {
+ if ( this.cachedImports == Collections.EMPTY_MAP ) {
+ this.cachedImports = new HashMap();
+ }
+
+ this.cachedImports.put( className,
+ clazz );
+ }
+
+ return clazz;
+ }
+
+ private Class defaultClass(String className) {
+ String qualifiedClass = "java.lang." + className;
+ Class clazz = null;
+ try {
+ clazz = this.classLoader.loadClass(qualifiedClass);
+ } catch (final ClassNotFoundException e) {
+ // do nothing
+ }
+ if (clazz != null) {
+ if (this.cachedImports == Collections.EMPTY_MAP) {
+ this.cachedImports = new HashMap();
+ }
+ this.cachedImports.put(className, clazz);
+ }
+ return clazz;
+ }
+
+ public boolean isEmpty() {
+ return this.imports.isEmpty();
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/Coercion.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/Coercion.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/Coercion.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,50 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+public class Coercion {
+
+ public static boolean toBoolean(Object obj) {
+ if ( obj instanceof Boolean ) {
+ return ((Boolean)obj).booleanValue();
+ }
+
+ throw new CoercionException( obj, "boolean" );
+ }
+
+ public static int toInteger(Object obj) {
+ if ( obj instanceof Number ) {
+ return ((Number)obj).intValue();
+ }
+ throw new CoercionException( obj, "integer" );
+ }
+
+ public static BigInteger toBigInteger(Object object) {
+ if ( object instanceof BigInteger ) {
+ return (BigInteger) object;
+ }
+
+ if ( object instanceof BigDecimal ) {
+ return ((BigDecimal)object).toBigInteger();
+ }
+
+ return new BigInteger( object.toString() );
+ }
+
+ public static double toFloat(Object obj) {
+ if ( obj instanceof Number ) {
+ return ((Number)obj).doubleValue();
+ }
+ throw new CoercionException( obj, "floating-point" );
+ }
+
+ public static BigDecimal toBigDecimal(Object object) {
+ if ( object instanceof BigDecimal ) {
+ return (BigDecimal) object;
+ }
+
+ return new BigDecimal( object.toString() );
+ }
+}
+
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/CoercionException.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/CoercionException.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/CoercionException.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,17 @@
+package org.codehaus.jfdi.interpreter;
+
+public class CoercionException extends RuntimeException {
+
+ private Object obj;
+ private String type;
+
+ public CoercionException(Object obj, String type) {
+ this.obj = obj;
+ this.type = type;
+ }
+
+ public String getMessage() {
+ return "Invalid coercion: " + obj.getClass().getName() + " to " + type;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/DefaultExternalVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/DefaultExternalVariable.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/DefaultExternalVariable.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,52 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.util.Map;
+
+public class DefaultExternalVariable
+ implements
+ VariableValueHandler {
+ private Map context;
+
+ private Object cachedValue;
+
+ private String identifer;
+ private Class type;
+
+ public DefaultExternalVariable(String identifier,
+ Map context) {
+ this.identifer = identifier;
+ this.context = context;
+ }
+
+ public String getIdentifier() {
+ return this.identifer;
+ }
+
+ public Class getType() {
+ return getValue().getClass();
+ }
+
+ public Object getValue() {
+ if ( this.cachedValue == null ) {
+ this.cachedValue = this.context.get( this.identifer );
+ }
+ return this.cachedValue;
+ }
+
+ public boolean isFinal() {
+ return true;
+ }
+
+ public boolean isLiteral() {
+ return false;
+ }
+
+ public boolean isLocal() {
+ return false;
+ }
+
+ public void setValue(Object value) {
+ throw new UnsupportedOperationException( "External Variable identifer='" + this.identifer + "' type='" + this.type + "' is final, it cannot be set" );
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/DefaultValueHandlerFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/DefaultValueHandlerFactory.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/DefaultValueHandlerFactory.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,32 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DefaultValueHandlerFactory extends AbstractValueHandlerFactory {
+
+ public Map variables = new HashMap();
+
+ public DefaultValueHandlerFactory(TypeResolver typeResolver) {
+ super( typeResolver );
+ }
+
+ public void addVariable(String identifier,
+ Object instance) {
+ this.variables.put( identifier,
+ instance );
+ }
+
+ public ValueHandler createExternalVariable(String identifier) {
+ registerExternalVariable( identifier );
+
+ VariableValueHandler handler = new DefaultExternalVariable( identifier,
+ this.variables );
+
+ return handler;
+ }
+
+ public boolean isValidVariable(String identifier) {
+ return variables.containsKey( identifier );
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ListValue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ListValue.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ListValue.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,21 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.util.List;
+
+public class ListValue extends AnonListValue
+ implements
+ VariableValueHandler {
+
+ private final String identifier;
+
+ public ListValue(List list, String identifier) {
+ super( list );
+ this.identifier = identifier;
+
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/LiteralValue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/LiteralValue.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/LiteralValue.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,78 @@
+/**
+ *
+ */
+package org.codehaus.jfdi.interpreter;
+
+
+public class LiteralValue
+ implements
+ ValueHandler {
+
+ private static final long serialVersionUID = 320L;
+
+ private final Object value;
+
+ private int id;
+
+ public LiteralValue(final Object value) {
+ this.value = value;
+ }
+
+ public Object getValue() {
+ return this.value;
+ }
+
+ public void reset() {
+ // N/A
+ }
+
+ public String toString() {
+ return "LiteralValue value=[" + this.value + "]";
+ }
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * this.value.hashCode();
+ return result;
+ }
+
+ public boolean equals(Object object) {
+ if ( this == object ) {
+ return true;
+ }
+ if ( object == null || getClass() != object.getClass()) {
+ return false;
+ }
+ final LiteralValue other = (LiteralValue) object;
+ return this.value.equals( other.value );
+ }
+
+ public int getId() {
+
+ return this.id;
+ }
+
+ public Class getType() {
+ return this.value.getClass();
+ }
+
+ public boolean isFinal() {
+ return true;
+ }
+
+ public boolean isLiteral() {
+ return true;
+ }
+
+ public boolean isLocal() {
+ return true;
+ }
+
+ public void setValue(Object variable) {
+ throw new UnsupportedOperationException("You can't treat a literal value as a variable.");
+ }
+
+
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/LocalVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/LocalVariable.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/LocalVariable.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,51 @@
+package org.codehaus.jfdi.interpreter;
+
+public class LocalVariable implements VariableValueHandler {
+
+
+ private final Class type;
+ private Object value;
+ private final boolean isFinal;
+ private final String identifier;
+
+
+ public LocalVariable(String identifier,
+ Class type,
+ boolean isFinal) {
+ this.type = type;
+ this.isFinal = isFinal;
+ this.identifier = identifier;
+ }
+
+ public Class getType() {
+ return this.type;
+ }
+
+ public Object getValue() {
+
+ return this.value;
+ }
+
+ public boolean isFinal() {
+
+ return isFinal;
+ }
+
+ public boolean isLiteral() {
+ return false;
+ }
+
+ public boolean isLocal() {
+ return true;
+ }
+
+ public void setValue(Object variable) {
+ this.value = variable;
+
+ }
+
+ public String getIdentifier() {
+ return this.identifier;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MapValue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MapValue.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MapValue.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,18 @@
+package org.codehaus.jfdi.interpreter;
+
+
+/** This is a map value that is a variable (still inline, but it has been assigned to something */
+public class MapValue extends AnonMapValue implements VariableValueHandler {
+
+ private final String identifier;
+
+ public MapValue(KeyValuePair[] pairs, String identifier) {
+ super( pairs );
+ this.identifier = identifier;
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MethodInvoker.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MethodInvoker.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MethodInvoker.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,87 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Date;
+
+public class MethodInvoker {
+ private Method method;
+
+ private boolean isFunction;
+
+ private final Object[] params;
+
+ private Class[] parameterTypes;
+
+ /**
+ * Method invoker
+ */
+ public MethodInvoker(Method method, boolean isFunction, Object[] params) {
+ this.method = method;
+ this.params = params;
+ this.isFunction = isFunction;
+ }
+
+ public Object invoke(Object instance) throws IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException {
+
+ System.err.println( "invoke ::" + method + " on " + instance );
+
+ // None static methods cannot have a null instance
+ if (!isFunction && instance == null) {
+ throw new NullPointerException(
+ "Cannot call the non-static method ["
+ + this.method.getName() + "] on the class ["
+ + this.method.getDeclaringClass().getName()
+ + " with a null instance");
+ }
+
+ Object result = null;
+
+ System.err.println("invoke on " + instance);
+ System.err.println("invoke of " + method);
+ System.err.println("invoke with " + Arrays.asList( params ) );
+
+ // now the actual invoking of the method
+ result = this.method.invoke(instance, params);
+
+ return result;
+ }
+
+ /**
+ * Attempt to convert text to the target class type
+ */
+ private static Object convert(String text, Class type) {
+ if (type == Integer.class || type == int.class) {
+ return new Integer(text);
+ } else if (text == "null") {
+ return null;
+ } else if (type == Character.class || type == char.class) {
+ return (new Character(text.charAt(0)));
+ } else if (type == Short.class || type == short.class) {
+ return new Short(text);
+ } else if (type == Long.class || type == long.class) {
+ return new Long(text);
+ } else if (type == Float.class || type == float.class) {
+ return new Float(text);
+ } else if (type == Double.class || type == double.class) {
+ return new Double(text);
+ } else if (type == Boolean.class || type == boolean.class) {
+ return new Boolean(text);
+ } else if (type == Date.class) {
+ // return DateFactory.parseDate( text );
+ throw new UnsupportedOperationException(
+ "Whoops ! need to do dates !");
+ } else if (type == BigDecimal.class) {
+ return new BigDecimal(text);
+ } else if (type == BigInteger.class) {
+ return new BigInteger(text);
+ } else {
+ throw new IllegalArgumentException("Unable to convert [" + text
+ + "] to type: [" + type.getName() + "]");
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MethodResolver.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MethodResolver.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/MethodResolver.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,159 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.codehaus.jfdi.interpreter.operations.Expr;
+
+/**
+ * Determines the method to call, based on the given values
+ *
+ */
+public class MethodResolver {
+
+ private final static MethodResolver instance = new MethodResolver();
+
+ public static MethodResolver getInstance() {
+ return instance;
+ }
+
+ private MethodResolver() {
+ }
+
+ public Method resolveMethod(Class clazz, String name, Object[] params) {
+
+ System.err.println("resolve " + name + " on " + clazz);
+
+ Class[] classes = new Class[params.length];
+ for (int i = 0, length = params.length; i < length; i++) {
+ classes[i] = params[i].getClass();
+ }
+
+ return resolveMethod(clazz, name, classes);
+ }
+
+ public Method resolveMethod(Class clazz, String name, Class[] params) {
+ Method method = null;
+
+ boolean allDefined = true;
+
+ // check for null params, so we know if all the types are defined
+ for (int i = 0, length = params.length; i < length; i++) {
+ System.err.println( "param: " + params[i] );
+ if (params[i] == null) {
+ allDefined = false;
+ }
+ }
+
+ System.err.println( "clazz: " + clazz );
+ System.err.println( "name: " + name );
+
+ if (allDefined) {
+ method = getMethod(clazz, name, params);
+ } else {
+ // For some reason all the types are not specified, so just match
+ // the first method with the same
+ // number of arguments
+ Method[] methods = getMethods(clazz, name, params.length);
+ if (methods != null && methods.length != 0) {
+ method = methods[0];
+ }
+ }
+
+ // @todo We could potentially output a warning here
+ // if ( (method.getModifiers() & Modifier.PUBLIC) != Modifier.PUBLIC ) {
+ // throw new RuntimeDroolsException( "Unable to call the private method
+ // [" + name + "] on class [" + clazz.getName() + "] for parameters " +
+ // arrayToString( params ) );
+ // }
+ System.err.println( "find " + method );
+ return method;
+ }
+
+ public boolean isStatic(Method method) {
+ return (method != null && (method.getModifiers() & Modifier.STATIC) == Modifier.STATIC);
+ }
+
+ /**
+ * work out what method we will be calling at runtime, based on the name and
+ * number of parameters.
+ */
+ private Method getMethod(Class clazz, String methodName, Class[] args) {
+
+ // Fist get methods with same number of arguments
+ Method[] methods = getMethods(clazz, methodName, args.length);
+ if (methods.length == 0) {
+ return null;
+ }
+
+ // now iterate to find correct method
+ for (int i = 0, length = methods.length; i < length; i++) {
+ if (matchesTypes(methods[i].getParameterTypes(), args)) {
+ return methods[i];
+ }
+ }
+
+ // Casting hasn't worked, so just return the first method with the same
+ // number of params
+ return methods[0];
+ }
+
+ private Method[] getMethods(Class clazz, String methodName, int length) {
+ List list = new ArrayList();
+ Method[] methods = clazz.getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].getName().equals(methodName)) {
+ System.err.println( "NAME: " + methods[i] );
+ System.err.println( "len: " + length );
+ if (methods[i].getParameterTypes().length == length) {
+ System.err.println( "ADD: " + methods[i] );
+ list.add(methods[i]);
+ }
+ }
+ }
+ return (Method[]) list.toArray(new Method[list.size()]);
+ }
+
+ private boolean matchesTypes(Class[] methodClasses, Class[] argumentClasses) {
+ for (int i = 0, length = methodClasses.length; i < length; i++) {
+ Class methodClass = methodClasses[i];
+ Class argumentClass = argumentClasses[i];
+ if (methodClasses[i].isPrimitive()) {
+ // try matching to primitive
+ if (methodClass == int.class && argumentClass == Integer.class) {
+ continue;
+ } else if (methodClass == long.class
+ && argumentClass == Long.class) {
+ continue;
+ } else if (methodClass == float.class
+ && argumentClass == Float.class) {
+ continue;
+ } else if (methodClass == double.class
+ && argumentClass == Double.class) {
+ continue;
+ } else {
+ return false;
+ }
+ } else if (methodClasses[i] != argumentClasses[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private String arrayToString(Object[] values) {
+ StringBuffer args = new StringBuffer();
+ for (int i = 0, length = values.length; i < length; i++) {
+ args.append("[");
+ args.append(values[i].getClass());
+ args.append("]");
+ if (i < length - 1) {
+ args.append(", ");
+ }
+ }
+ return args.toString();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/NotAnLValueException.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/NotAnLValueException.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/NotAnLValueException.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,15 @@
+package org.codehaus.jfdi.interpreter;
+
+public class NotAnLValueException extends RuntimeException {
+
+ private Object obj;
+
+ public NotAnLValueException(Object obj) {
+ this.obj = obj;
+ }
+
+ public String getMessage() {
+ return "Not an l-value: " + obj;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ObjectValue.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ObjectValue.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ObjectValue.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,37 @@
+package org.codehaus.jfdi.interpreter;
+
+public class ObjectValue implements ValueHandler {
+
+ private Object value;
+
+ public ObjectValue(Object value) {
+ this.value = value;
+ }
+
+ public void setValue(Object value) {
+ throw new NotAnLValueException( value );
+ }
+
+ public boolean isLocal() {
+ return true;
+ }
+
+ public boolean isFinal() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ public boolean isLiteral() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Class getType() {
+ return value.getClass();
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/OperatorOverloader.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/OperatorOverloader.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/OperatorOverloader.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,19 @@
+package org.codehaus.jfdi.interpreter;
+
+/**
+ * This interface is to be implemented by users, to provide declarations of operator overloading.
+ * The engine can use this to apply operators accordingly when it is registered.
+ *
+ * @author Michael Neale
+ */
+public interface OperatorOverloader {
+
+ Object plus(Object left, Object right);
+ Object minus(Object left, Object right);
+ Object multiply(Object left, Object right);
+ Object divide(Object left, Object right);
+
+ Class getApplicableType();
+
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/SymbolTableImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/SymbolTableImpl.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/SymbolTableImpl.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,49 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.jfdi.SymbolTable;
+
+class SymbolTableImpl implements SymbolTable {
+
+ private List stackFrames;
+
+ SymbolTableImpl() {
+ this.stackFrames = new ArrayList();
+ }
+
+ void pushFrame() {
+ stackFrames.add( new HashMap() );
+ }
+
+ void popFrame() {
+ stackFrames.remove( stackFrames.size() - 1 );
+ }
+
+ public Object put(String identifier, Object object) {
+ for ( Iterator frameIter = stackFrames.iterator(); frameIter.hasNext(); ) {
+ Map frame = (Map) frameIter.next();
+ if ( frame.containsKey( identifier ) ) {
+ return frame.put( identifier, object );
+ }
+ }
+
+ Map lastFrame = (Map) stackFrames.get( stackFrames.size() - 1 );
+ return lastFrame.put( identifier, object );
+ }
+
+ public Object get(String identifier) {
+ for ( int i = stackFrames.size(); i >= 0 ; --i ) {
+ Map frame = (Map) stackFrames.get( i );
+ if ( frame.containsKey( identifier ) ) {
+ return frame.get( identifier );
+ }
+ }
+ return null;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/TypeResolver.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/TypeResolver.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/TypeResolver.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,12 @@
+package org.codehaus.jfdi.interpreter;
+
+import java.util.List;
+
+public interface TypeResolver {
+ public List getImports();
+
+ public void addImport(String importEntry);
+
+ public Class resolveType(String className) throws ClassNotFoundException;
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ValueHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ValueHandler.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ValueHandler.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,16 @@
+package org.codehaus.jfdi.interpreter;
+
+import org.codehaus.jfdi.interpreter.operations.Expr;
+
+/**
+ * This specifies a container for a variable that will be used at runtime.
+ * The runtime will call this when executing.
+ */
+public interface ValueHandler extends Expr {
+ void setValue(Object value);
+
+ boolean isLocal();
+ boolean isFinal();
+ boolean isLiteral();
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ValueHandlerFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ValueHandlerFactory.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/ValueHandlerFactory.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,48 @@
+package org.codehaus.jfdi.interpreter;
+
+public interface ValueHandlerFactory {
+
+ /** the type parameter is one of the following constants */
+ /** Obviously if it was in quotes, its a string literal (which could be anything) */
+ public static final int STRING = 1;
+ /** Means true integer, not Javas interpretation of it */
+ public static final int CHAR = 2;
+ public static final int INTEGER = 4;
+ public static final int LONG = 8;
+ public static final int FLOAT = 16;
+ public static final int DOUBLE = 32;
+ public static final int BIGINTEGER = 64;
+ public static final int BIGDECIMAL = 128;
+ public static final int BOOLEAN = 256;
+ public static final int NULL = 512;
+ public static final int MAP = 1024;
+ public static final int LIST = 2048;
+
+ /**
+ * This is for creating a literal "value handler"
+ */
+ public ValueHandler createLiteral(Class cls,
+ String val);
+
+ /**
+ * A local variable requires a type of some form (class).
+ */
+ public ValueHandler createLocalVariable(String identifier,
+ String type,
+ boolean isFinal);
+
+ /**
+ * To be implemented by the concrete factory.
+ * External variables will be provided to the parser ahead of time.
+ */
+ public ValueHandler createExternalVariable(String identifier);
+
+ /**
+ * return true if the specified external identifier is a variable.
+ */
+ public boolean isValidVariable(String identifier);
+
+ public String[] getRequiredVariables();
+
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/VariableValueHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/VariableValueHandler.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/VariableValueHandler.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,8 @@
+package org.codehaus.jfdi.interpreter;
+
+public interface VariableValueHandler extends ValueHandler {
+
+ /** the id of the actual variable in the source. */
+ String getIdentifier();
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/AdditiveExpr.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/AdditiveExpr.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/AdditiveExpr.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,90 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import org.codehaus.jfdi.interpreter.Coercion;
+
+public class AdditiveExpr implements Expr {
+
+ public static class Operator {
+ private String str;
+
+ public Operator(String str) {
+ this.str = str;
+ }
+
+ public String toString() {
+ return str;
+ }
+
+ }
+
+ public static final Operator PLUS = new Operator("+");
+ public static final Operator MINUS = new Operator("-");
+
+ private Expr lhs;
+ private Expr rhs;
+ private Operator op;
+
+ public AdditiveExpr(Expr lhs, Expr rhs, Operator op) {
+ this.lhs = lhs;
+ this.rhs = rhs;
+ this.op = op;
+ }
+
+ public Object getValue() {
+ Object lhsObj = lhs.getValue();
+ Object rhsObj = rhs.getValue();
+
+ if ( op == PLUS && ( lhsObj instanceof String || rhsObj instanceof String ) ) {
+ return lhsObj.toString() + rhsObj.toString();
+ }
+
+ if ( lhsObj instanceof Integer || rhsObj instanceof Integer ) {
+ int lhsInt = Coercion.toInteger( lhs.getValue() );
+ int rhsInt = Coercion.toInteger( rhs.getValue() );
+
+ int result = 0;
+
+ if ( op == PLUS ) {
+ result = lhsInt + rhsInt;
+ } else {
+ result = lhsInt - rhsInt;
+ }
+
+ return new Integer( result );
+ }
+
+ if ( lhsObj instanceof Double || rhsObj instanceof Double ) {
+ double lhsDouble = Coercion.toFloat( lhs.getValue() );
+ double rhsDouble = Coercion.toFloat( rhs.getValue() );
+
+ double result = 0;
+
+ if ( op == PLUS ) {
+ result = lhsDouble + rhsDouble;
+ } else {
+ result = lhsDouble - rhsDouble;
+ }
+
+ return new Double( result );
+ }
+
+ throw new ArithmeticException( lhsObj.toString() + op.toString() + rhsObj.toString() );
+ }
+
+ public Class getType() {
+ if ( op == PLUS && ( lhs.getType() == String.class || rhs.getType() == String.class ) ) {
+ return String.class;
+ }
+
+ if ( lhs.getType() == Integer.class || rhs.getType() == Integer.class ) {
+ return Integer.class;
+ }
+
+ if ( lhs.getType() == Double.class || rhs.getType() == Double.class ) {
+ return Double.class;
+ }
+
+ throw new ArithmeticException( "invalid arithmetic types" );
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/AssignmentStatement.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/AssignmentStatement.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/AssignmentStatement.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,19 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import org.codehaus.jfdi.SymbolTable;
+
+public class AssignmentStatement implements Statement {
+
+ private Expr lhs;
+ private Expr rhs;
+
+ public AssignmentStatement(Expr lhs, Expr rhs) {
+ this.lhs = lhs;
+ this.rhs = rhs;
+ }
+
+ public void execute(SymbolTable symbolTable) {
+
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/CastExpr.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/CastExpr.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/CastExpr.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,21 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+public class CastExpr implements Expr {
+
+ private Class type;
+ private Expr expr;
+
+ public CastExpr(Class type, Expr expr) {
+ this.type = type;
+ this.expr = expr;
+ }
+
+ public Object getValue() {
+ return expr.getValue();
+ }
+
+ public Class getType() {
+ return type;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/CollectionIndexExpr.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/CollectionIndexExpr.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/CollectionIndexExpr.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,28 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import org.codehaus.jfdi.SymbolTable;
+
+public class CollectionIndexExpr implements Expr {
+
+ private Expr lhs;
+ private Expr index;
+
+ public CollectionIndexExpr(Expr lhs, Expr index) {
+ this.lhs = lhs;
+ this.index = index;
+ }
+
+ public Object evaluate(SymbolTable symbolTable) {
+ return null;
+ }
+
+ public Object getValue() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class getType() {
+ return Object.class;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/Expr.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/Expr.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/Expr.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,7 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+
+public interface Expr extends Statement {
+ Object getValue();
+ Class getType();
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/ForEachInStatement.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/ForEachInStatement.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/ForEachInStatement.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,19 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import org.codehaus.jfdi.SymbolTable;
+
+public class ForEachInStatement implements Statement {
+
+ private String iteratorName;
+ private Expr collection;
+
+ public ForEachInStatement(String iteratorName, Expr collection) {
+ this.iteratorName = iteratorName;
+ this.collection = collection;
+ }
+
+ public void execute(SymbolTable symbolTable) {
+ }
+
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/LogicalAndExpr.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/LogicalAndExpr.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/LogicalAndExpr.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,36 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import org.codehaus.jfdi.SymbolTable;
+import org.codehaus.jfdi.interpreter.Coercion;
+
+public class LogicalAndExpr implements Expr {
+
+ private Expr lhs;
+ private Expr rhs;
+
+ public LogicalAndExpr(Expr lhs, Expr rhs) {
+ System.err.println( "LogicalAndExpr l: " + lhs );
+ System.err.println( "LogicalAndExpr r: " + rhs );
+ this.lhs = lhs;
+ this.rhs = rhs;
+ }
+
+ public Object getValue() {
+ System.err.println( "L: " + lhs );
+ System.err.println( "R: " + rhs );
+ boolean lhsBool = Coercion.toBoolean( lhs.getValue() );
+ if ( ! lhsBool ) {
+ // short-circuit, avoid rhs
+ return Boolean.FALSE;
+ }
+
+ boolean rhsBool = Coercion.toBoolean( rhs.getValue() );
+
+ return ( rhsBool ? Boolean.TRUE : Boolean.FALSE );
+ }
+
+ public Class getType() {
+ return Boolean.class;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/LogicalOrExpr.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/LogicalOrExpr.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/LogicalOrExpr.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,33 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import org.codehaus.jfdi.interpreter.Coercion;
+import org.codehaus.jfdi.interpreter.CoercionException;
+
+
+public class LogicalOrExpr implements Expr {
+
+ private Expr lhs;
+ private Expr rhs;
+
+ public LogicalOrExpr(Expr lhs, Expr rhs) {
+ this.lhs = lhs;
+ this.rhs = rhs;
+ }
+
+ public Object getValue() {
+ boolean lhsBool = Coercion.toBoolean( lhs.getValue() );
+ if ( lhsBool ) {
+ // short-circuit, avoid rhs
+ return Boolean.TRUE;
+ }
+
+ boolean rhsBool = Coercion.toBoolean( rhs.getValue() );
+
+ return ( rhsBool ? Boolean.TRUE : Boolean.FALSE );
+ }
+
+ public Class getType() {
+ return Boolean.class;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MemberAccessExpr.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MemberAccessExpr.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MemberAccessExpr.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,30 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import org.codehaus.jfdi.SymbolTable;
+
+public class MemberAccessExpr implements Expr {
+
+ private Expr lhs;
+ private String name;
+ private Expr[] args;
+
+ public MemberAccessExpr(Expr lhs, String name, Expr[] args) {
+ this.lhs = lhs;
+ this.name = name;
+ this.args = args;
+ }
+
+ public Object evaluate(SymbolTable symbolTable) {
+ return null;
+ }
+
+ public Object getValue() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class getType() {
+ return Object.class;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MethodCall.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MethodCall.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MethodCall.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,62 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import org.codehaus.jfdi.interpreter.MethodInvoker;
+import org.codehaus.jfdi.interpreter.MethodResolver;
+
+public class MethodCall implements Expr {
+
+ private Expr obj;
+ private String name;
+ private Expr[] params;
+
+ private Method method;
+
+ public MethodCall(Expr obj, String name, Expr[] params) {
+ this.obj = obj;
+ this.name = name;
+ this.params = params;
+ Class[] paramTypes = new Class[ params.length ];
+ for ( int i = 0 ; i < paramTypes.length ; ++i ) {
+ paramTypes[ i ] = params[ i ].getType();
+ }
+ System.err.println( "obj.getType(): " + obj.getType() );
+ System.err.println( "name: " + name );
+ this.method = MethodResolver.getInstance().resolveMethod( obj.getType(), name, paramTypes );
+ System.err.println( "method: " + method );
+ }
+
+ public Object getValue() {
+ Object thisObj = obj.getValue();
+ Object[] paramObjs = new Object[ params.length ];
+
+ for ( int i = 0 ; i < params.length ; ++i ) {
+ paramObjs[i] = params[i].getValue();
+ }
+
+ System.err.println( "CALL " + name + " " + Arrays.asList( paramObjs ) );
+ MethodInvoker invoker = new MethodInvoker( method, false, paramObjs );
+ try {
+ return invoker.invoke( thisObj );
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public Class getType() {
+ return method.getReturnType();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MultiplicativeExpr.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MultiplicativeExpr.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/MultiplicativeExpr.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,84 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+import org.codehaus.jfdi.SymbolTable;
+import org.codehaus.jfdi.interpreter.Coercion;
+
+public class MultiplicativeExpr implements Expr {
+
+ public static class Operator {
+ private String str;
+ public Operator(String str) {
+ this.str = str;
+ }
+
+ public String toString() {
+ return str;
+ }
+
+ }
+ public static final Operator MULT = new Operator( "*" );
+ public static final Operator DIV = new Operator( "/" );
+
+ private Expr lhs;
+ private Expr rhs;
+ private Object op;
+
+ public MultiplicativeExpr(Expr lhs, Expr rhs, Operator op) {
+ this.lhs = lhs;
+ this.rhs = rhs;
+ this.op = op;
+ }
+
+ public Object getValue() {
+
+ Object lhsObj = lhs.getValue();
+ Object rhsObj = rhs.getValue();
+
+ if ( lhsObj instanceof Integer || rhsObj instanceof Integer ) {
+ int lhsInt = Coercion.toInteger( lhs.getValue() );
+ int rhsInt = Coercion.toInteger( rhs.getValue() );
+
+ int result = 0;
+
+ if ( op == MULT ) {
+ result = lhsInt * rhsInt;
+ } else {
+ result = lhsInt / rhsInt;
+ }
+
+ return new Integer( result );
+ }
+
+ if ( lhsObj instanceof Double || rhsObj instanceof Double ) {
+ double lhsDouble = Coercion.toFloat( lhs.getValue() );
+ double rhsDouble = Coercion.toFloat( rhs.getValue() );
+
+ double result = 0;
+
+ if ( op == MULT ) {
+ result = lhsDouble * rhsDouble;
+ } else {
+ result = lhsDouble / rhsDouble;
+ }
+
+ return new Double( result );
+ }
+
+ throw new ArithmeticException( lhsObj.toString() + op.toString() + rhsObj.toString() );
+ }
+
+ public Class getType() {
+
+ if ( lhs.getType() == Integer.class || rhs.getType() == Integer.class ) {
+ return Integer.class;
+ }
+
+ if ( lhs.getType() == Double.class || rhs.getType() == Double.class ) {
+ return Double.class;
+ }
+
+ throw new ArithmeticException( "invalid arithmetic types" );
+ }
+
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/Statement.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/Statement.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/operations/Statement.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,5 @@
+package org.codehaus.jfdi.interpreter.operations;
+
+public interface Statement {
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/types/Type.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/types/Type.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/interpreter/types/Type.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,7 @@
+package org.codehaus.jfdi.interpreter.types;
+
+import org.codehaus.jfdi.interpreter.operations.Expr;
+
+public interface Type extends Expr {
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI.g
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI.g 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI.g 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,288 @@
+grammar JFDI;
+
+ at parser::header {
+ package org.codehaus.jfdi.parser;
+ import org.codehaus.jfdi.interpreter.*;
+ import org.codehaus.jfdi.interpreter.operations.*;
+ import java.util.List;
+ import java.util.ArrayList;
+}
+
+ at parser::members {
+
+ private ValueHandlerFactory factory;
+ private TypeResolver typeResolver;
+
+ public void setValueHandlerFactory(ValueHandlerFactory factory) {
+ this.factory = factory;
+ }
+
+ public ValueHandlerFactory getValueHandlerFactory() {
+ return this.factory;
+ }
+
+ public void setTypeResolver(TypeResolver typeResolver) {
+ this.typeResolver = typeResolver;
+ }
+
+ public TypeResolver getTypeResolver() {
+ return typeResolver;
+ }
+
+}
+
+ at lexer::header {
+ package org.codehaus.jfdi.parser;
+}
+
+
+compilation_unit
+ :
+ statements
+ ;
+
+
+statements
+ :
+ (statement ';')*
+ ;
+
+statement
+ :
+ ( expr
+ | for_in_statement
+ )
+ ;
+
+statement_block
+ :
+ '{' statements '}'
+ ;
+
+for_in_statement
+ :
+ 'for' IDENT 'in' expr statement_block
+ ;
+
+assignment_statement
+ :
+ object_expr '=' expr
+ ;
+
+expr returns [Expr e]
+ @init {
+ e = null;
+ }
+ :
+ /*(t=cast)?*/ ex=logical_or_expr { e = ex; }
+ /*{
+ if ( t != null ) {
+ e = new CastExpr( t, e );
+ }
+ }*/
+ ;
+
+logical_or_expr returns [Expr e]
+ @init {
+ e = null;
+ }
+ :
+ lhs=logical_and_expr { e = lhs; }
+ ( '||' rhs=logical_and_expr
+ { e = new LogicalOrExpr( e, rhs ); }
+ )*
+ ;
+
+logical_and_expr returns [Expr e]
+ @init {
+ e = null;
+ }
+ :
+ lhs=additive_expr { e = lhs; }
+ ( '&&' rhs=additive_expr
+ { e = new LogicalAndExpr( e, rhs ); }
+ )*
+ ;
+
+
+additive_expr returns [Expr e]
+ @init {
+ e = null;
+ AdditiveExpr.Operator op = null;
+ }
+ :
+ lhs=multiplicative_expr { e = lhs; }
+ (
+ ( '+' { op = AdditiveExpr.PLUS; }
+ | '-' { op = AdditiveExpr.MINUS; }
+ )
+ rhs=multiplicative_expr
+ { e = new AdditiveExpr( e, rhs, op ); }
+ )*
+ {System.err.println( "add_expr returns " + e ); }
+ ;
+
+multiplicative_expr returns [Expr e]
+ @init {
+ e = null;
+ MultiplicativeExpr.Operator op = null;
+ }
+ :
+ lhs=atom { e = lhs; }
+ (
+ ( '*' { op = MultiplicativeExpr.MULT; }
+ | '/' { op = MultiplicativeExpr.DIV; }
+ )
+ rhs=atom
+ { e = new MultiplicativeExpr( e, rhs, op ); }
+ )*
+ {System.err.println( "mult_expr returns " + e ); }
+ ;
+
+atom returns [Expr e]
+ @init{
+ e = null;
+ }
+ :
+ ( i=INTEGER { e = factory.createLiteral( java.lang.Integer.class, i.getText() ); }
+ | s=STRING { e = factory.createLiteral( java.lang.String.class, s.getText().substring( 1, s.getText().length()-1 ) ); }
+ | f=FLOAT { e = factory.createLiteral( java.lang.Double.class, f.getText() ); }
+ | 'true' { e = factory.createLiteral( java.lang.Boolean.class, "true" ); }
+ | 'false' { e = factory.createLiteral( java.lang.Boolean.class, "false" ); }
+ | '(' ex=expr ')' { e = ex; }
+ | l=list { e = l; }
+ | m=map { e = m; }
+ | ex=object_expr { e = ex; }
+ )
+ {System.err.println( "atom returns " + e ); }
+ ;
+
+arg_list returns [List args]
+ @init {
+ args = new ArrayList();
+ }
+ :
+ first=expr { args.add( first ); }
+ ( ',' other=expr
+ { args.add( other ); }
+ )*
+ ;
+
+object_expr returns [Expr e]
+ @init {
+ e = null;
+ boolean isMethod = false;
+ Expr[] paramExprs = new Expr[0];
+ }
+ :
+ i=IDENT { e = factory.createExternalVariable( i.getText() ); }
+ ( ( '[' ~'[' )=> '[' expr ']'
+ | '.' n=IDENT
+ ( '('
+ ( a=arg_list
+ {
+ paramExprs = new Expr[ a.size() ];
+ for ( int j = 0 ; j < paramExprs.length ; ++j ) {
+ paramExprs[j] = (Expr) a.get( j );
+ }
+ }
+ )?
+ ')'
+ { isMethod = true; }
+ )?
+ {
+ String name = n.getText();
+ if ( ! isMethod ) {
+ name = "get" + name.substring(0,1).toUpperCase() + name.substring(1);
+ }
+ e = new MethodCall( e, name, paramExprs );
+ paramExprs = new Expr[0];
+ isMethod = false;
+ }
+ )*
+ ;
+
+cast returns [Class type] throws ClassNotFoundException
+ @init {
+ type = null;
+ }
+ :
+ '(' i=IDENT ')'
+ {
+ try {
+ type = typeResolver.resolveType( i.getText() );
+ System.err.println( "CASTING TO " + type);
+ } catch (ClassNotFoundException e) {
+ System.err.println( e.getMessage() );
+ }
+ }
+ ;
+
+map returns [AnonMapValue m]
+ @init {
+ m = null;
+ List pairs = new ArrayList();
+ }
+ :
+ '{'
+ ( k=expr '=>' v=expr
+ { pairs.add( new AnonMapValue.KeyValuePair( k, v ) ); }
+ ( ','
+ k=expr '=>' v=expr
+ { pairs.add( new AnonMapValue.KeyValuePair( k, v ) ); }
+ )*
+ ','?
+ )?
+ '}'
+ {
+ m = new AnonMapValue( (AnonMapValue.KeyValuePair[]) pairs.toArray( new AnonMapValue.KeyValuePair[ pairs.size() ] ) );
+ }
+ ;
+
+
+list returns [AnonListValue l]
+ @init {
+ l = null;
+ List values = new ArrayList();
+ }
+ :
+ '[' ( v=expr
+ { values.add( v ); }
+ ( ',' v=expr
+ { values.add( v ); }
+ )*
+ ','?
+ )?
+ ']'
+ {
+ l = new AnonListValue( values );
+ }
+ ;
+
+
+
+
+IDENT
+ :
+ ('a'..'z'|'A'..'Z'|'_'|'$')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
+ ;
+
+INTEGER
+ :
+ ( ('1'..'9')('0'..'9')*
+ | '0x' ('0'..'9'|'A'..'F'|'a'..'f')+
+ | '0' ('0'..'7')+
+ )
+ ;
+
+STRING
+ :
+ ( ('"' ~'"'+ '"') | ('\'' ~'\'' + '\'') )
+ ;
+
+FLOAT
+ :
+ ('0'..'9')+'.'('0'..'9')+
+ ;
+
+
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI.tokens
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI.tokens 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI.tokens 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,25 @@
+INTEGER=5
+IDENT=4
+STRING=6
+FLOAT=7
+')'=23
+'=>'=28
+';'=8
+'{'=9
+'-'=17
+']'=26
+'true'=20
+'false'=21
+','=24
+'('=22
+'&&'=15
+'for'=11
+'.'=27
+'*'=18
+'||'=14
+'='=13
+'in'=12
+'['=25
+'}'=10
+'+'=16
+'/'=19
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDILexer.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDILexer.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDILexer.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,1428 @@
+// $ANTLR 3.0b5 /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g 2006-11-27 17:08:59
+
+ package org.codehaus.jfdi.parser;
+
+
+import org.antlr.runtime.*;
+import java.util.Stack;
+import java.util.List;
+import java.util.ArrayList;
+
+public class JFDILexer extends Lexer {
+ public static final int T21=21;
+ public static final int T14=14;
+ public static final int IDENT=4;
+ public static final int T22=22;
+ public static final int T11=11;
+ public static final int T9=9;
+ public static final int STRING=6;
+ public static final int FLOAT=7;
+ public static final int T12=12;
+ public static final int T28=28;
+ public static final int T23=23;
+ public static final int T13=13;
+ public static final int T20=20;
+ public static final int T10=10;
+ public static final int T25=25;
+ public static final int INTEGER=5;
+ public static final int T18=18;
+ public static final int T26=26;
+ public static final int T15=15;
+ public static final int EOF=-1;
+ public static final int T17=17;
+ public static final int Tokens=29;
+ public static final int T16=16;
+ public static final int T27=27;
+ public static final int T8=8;
+ public static final int T24=24;
+ public static final int T19=19;
+ public JFDILexer() {;}
+ public JFDILexer(CharStream input) {
+ super(input);
+ }
+ public String getGrammarFileName() { return "/Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g"; }
+
+ // $ANTLR start T8
+ public void mT8() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T8;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:6:6: ( ';' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:6:6: ';'
+ {
+ match(';');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T8
+
+ // $ANTLR start T9
+ public void mT9() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T9;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:7:6: ( '{' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:7:6: '{'
+ {
+ match('{');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T9
+
+ // $ANTLR start T10
+ public void mT10() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T10;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:8:7: ( '}' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:8:7: '}'
+ {
+ match('}');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T10
+
+ // $ANTLR start T11
+ public void mT11() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T11;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:9:7: ( 'for' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:9:7: 'for'
+ {
+ match("for");
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T11
+
+ // $ANTLR start T12
+ public void mT12() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T12;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:10:7: ( 'in' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:10:7: 'in'
+ {
+ match("in");
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T12
+
+ // $ANTLR start T13
+ public void mT13() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T13;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:11:7: ( '=' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:11:7: '='
+ {
+ match('=');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T13
+
+ // $ANTLR start T14
+ public void mT14() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T14;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:12:7: ( '||' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:12:7: '||'
+ {
+ match("||");
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T14
+
+ // $ANTLR start T15
+ public void mT15() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T15;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:13:7: ( '&&' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:13:7: '&&'
+ {
+ match("&&");
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T15
+
+ // $ANTLR start T16
+ public void mT16() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T16;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:14:7: ( '+' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:14:7: '+'
+ {
+ match('+');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T16
+
+ // $ANTLR start T17
+ public void mT17() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T17;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:15:7: ( '-' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:15:7: '-'
+ {
+ match('-');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T17
+
+ // $ANTLR start T18
+ public void mT18() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T18;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:16:7: ( '*' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:16:7: '*'
+ {
+ match('*');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T18
+
+ // $ANTLR start T19
+ public void mT19() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T19;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:17:7: ( '/' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:17:7: '/'
+ {
+ match('/');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T19
+
+ // $ANTLR start T20
+ public void mT20() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T20;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:18:7: ( 'true' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:18:7: 'true'
+ {
+ match("true");
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T20
+
+ // $ANTLR start T21
+ public void mT21() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T21;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:19:7: ( 'false' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:19:7: 'false'
+ {
+ match("false");
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T21
+
+ // $ANTLR start T22
+ public void mT22() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T22;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:20:7: ( '(' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:20:7: '('
+ {
+ match('(');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T22
+
+ // $ANTLR start T23
+ public void mT23() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T23;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:21:7: ( ')' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:21:7: ')'
+ {
+ match(')');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T23
+
+ // $ANTLR start T24
+ public void mT24() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T24;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:22:7: ( ',' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:22:7: ','
+ {
+ match(',');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T24
+
+ // $ANTLR start T25
+ public void mT25() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T25;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:23:7: ( '[' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:23:7: '['
+ {
+ match('[');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T25
+
+ // $ANTLR start T26
+ public void mT26() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T26;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:24:7: ( ']' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:24:7: ']'
+ {
+ match(']');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T26
+
+ // $ANTLR start T27
+ public void mT27() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T27;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:25:7: ( '.' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:25:7: '.'
+ {
+ match('.');
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T27
+
+ // $ANTLR start T28
+ public void mT28() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = T28;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:26:7: ( '=>' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:26:7: '=>'
+ {
+ match("=>");
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end T28
+
+ // $ANTLR start IDENT
+ public void mIDENT() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = IDENT;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:267:3: ( ('a'..'z'|'A'..'Z'|'_'|'$') ( ('a'..'z'|'A'..'Z'|'_'|'0'..'9'))* )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:267:3: ('a'..'z'|'A'..'Z'|'_'|'$') ( ('a'..'z'|'A'..'Z'|'_'|'0'..'9'))*
+ {
+ if ( input.LA(1)=='$'||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z') ) {
+ input.consume();
+
+ }
+ else {
+ MismatchedSetException mse =
+ new MismatchedSetException(null,input);
+ recover(mse); throw mse;
+ }
+
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:267:30: ( ('a'..'z'|'A'..'Z'|'_'|'0'..'9'))*
+ loop1:
+ do {
+ int alt1=2;
+ int LA1_0 = input.LA(1);
+ if ( ((LA1_0>='0' && LA1_0<='9')||(LA1_0>='A' && LA1_0<='Z')||LA1_0=='_'||(LA1_0>='a' && LA1_0<='z')) ) {
+ alt1=1;
+ }
+
+
+ switch (alt1) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:267:31: ('a'..'z'|'A'..'Z'|'_'|'0'..'9')
+ {
+ if ( (input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z') ) {
+ input.consume();
+
+ }
+ else {
+ MismatchedSetException mse =
+ new MismatchedSetException(null,input);
+ recover(mse); throw mse;
+ }
+
+
+ }
+ break;
+
+ default :
+ break loop1;
+ }
+ } while (true);
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end IDENT
+
+ // $ANTLR start INTEGER
+ public void mINTEGER() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = INTEGER;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:272:3: ( ( ( '1' .. '9' ) ( '0' .. '9' )* | '0x' ( ('0'..'9'|'A'..'F'|'a'..'f'))+ | '0' ( '0' .. '7' )+ ) )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:272:3: ( ( '1' .. '9' ) ( '0' .. '9' )* | '0x' ( ('0'..'9'|'A'..'F'|'a'..'f'))+ | '0' ( '0' .. '7' )+ )
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:272:3: ( ( '1' .. '9' ) ( '0' .. '9' )* | '0x' ( ('0'..'9'|'A'..'F'|'a'..'f'))+ | '0' ( '0' .. '7' )+ )
+ int alt5=3;
+ int LA5_0 = input.LA(1);
+ if ( ((LA5_0>='1' && LA5_0<='9')) ) {
+ alt5=1;
+ }
+ else if ( (LA5_0=='0') ) {
+ int LA5_2 = input.LA(2);
+ if ( (LA5_2=='x') ) {
+ alt5=2;
+ }
+ else if ( ((LA5_2>='0' && LA5_2<='7')) ) {
+ alt5=3;
+ }
+ else {
+ NoViableAltException nvae =
+ new NoViableAltException("272:3: ( ( '1' .. '9' ) ( '0' .. '9' )* | '0x' ( ('0'..'9'|'A'..'F'|'a'..'f'))+ | '0' ( '0' .. '7' )+ )", 5, 2, input);
+
+ throw nvae;
+ }
+ }
+ else {
+ NoViableAltException nvae =
+ new NoViableAltException("272:3: ( ( '1' .. '9' ) ( '0' .. '9' )* | '0x' ( ('0'..'9'|'A'..'F'|'a'..'f'))+ | '0' ( '0' .. '7' )+ )", 5, 0, input);
+
+ throw nvae;
+ }
+ switch (alt5) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:272:5: ( '1' .. '9' ) ( '0' .. '9' )*
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:272:5: ( '1' .. '9' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:272:6: '1' .. '9'
+ {
+ matchRange('1','9');
+
+ }
+
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:272:15: ( '0' .. '9' )*
+ loop2:
+ do {
+ int alt2=2;
+ int LA2_0 = input.LA(1);
+ if ( ((LA2_0>='0' && LA2_0<='9')) ) {
+ alt2=1;
+ }
+
+
+ switch (alt2) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:272:16: '0' .. '9'
+ {
+ matchRange('0','9');
+
+ }
+ break;
+
+ default :
+ break loop2;
+ }
+ } while (true);
+
+
+ }
+ break;
+ case 2 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:273:5: '0x' ( ('0'..'9'|'A'..'F'|'a'..'f'))+
+ {
+ match("0x");
+
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:273:10: ( ('0'..'9'|'A'..'F'|'a'..'f'))+
+ int cnt3=0;
+ loop3:
+ do {
+ int alt3=2;
+ int LA3_0 = input.LA(1);
+ if ( ((LA3_0>='0' && LA3_0<='9')||(LA3_0>='A' && LA3_0<='F')||(LA3_0>='a' && LA3_0<='f')) ) {
+ alt3=1;
+ }
+
+
+ switch (alt3) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:273:11: ('0'..'9'|'A'..'F'|'a'..'f')
+ {
+ if ( (input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='F')||(input.LA(1)>='a' && input.LA(1)<='f') ) {
+ input.consume();
+
+ }
+ else {
+ MismatchedSetException mse =
+ new MismatchedSetException(null,input);
+ recover(mse); throw mse;
+ }
+
+
+ }
+ break;
+
+ default :
+ if ( cnt3 >= 1 ) break loop3;
+ EarlyExitException eee =
+ new EarlyExitException(3, input);
+ throw eee;
+ }
+ cnt3++;
+ } while (true);
+
+
+ }
+ break;
+ case 3 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:274:5: '0' ( '0' .. '7' )+
+ {
+ match('0');
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:274:9: ( '0' .. '7' )+
+ int cnt4=0;
+ loop4:
+ do {
+ int alt4=2;
+ int LA4_0 = input.LA(1);
+ if ( ((LA4_0>='0' && LA4_0<='7')) ) {
+ alt4=1;
+ }
+
+
+ switch (alt4) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:274:10: '0' .. '7'
+ {
+ matchRange('0','7');
+
+ }
+ break;
+
+ default :
+ if ( cnt4 >= 1 ) break loop4;
+ EarlyExitException eee =
+ new EarlyExitException(4, input);
+ throw eee;
+ }
+ cnt4++;
+ } while (true);
+
+
+ }
+ break;
+
+ }
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end INTEGER
+
+ // $ANTLR start STRING
+ public void mSTRING() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = STRING;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:3: ( ( ( '\"' (~ '\"' )+ '\"' ) | ( '\\'' (~ '\\'' )+ '\\'' ) ) )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:3: ( ( '\"' (~ '\"' )+ '\"' ) | ( '\\'' (~ '\\'' )+ '\\'' ) )
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:3: ( ( '\"' (~ '\"' )+ '\"' ) | ( '\\'' (~ '\\'' )+ '\\'' ) )
+ int alt8=2;
+ int LA8_0 = input.LA(1);
+ if ( (LA8_0=='\"') ) {
+ alt8=1;
+ }
+ else if ( (LA8_0=='\'') ) {
+ alt8=2;
+ }
+ else {
+ NoViableAltException nvae =
+ new NoViableAltException("280:3: ( ( '\"' (~ '\"' )+ '\"' ) | ( '\\'' (~ '\\'' )+ '\\'' ) )", 8, 0, input);
+
+ throw nvae;
+ }
+ switch (alt8) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:5: ( '\"' (~ '\"' )+ '\"' )
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:5: ( '\"' (~ '\"' )+ '\"' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:6: '\"' (~ '\"' )+ '\"'
+ {
+ match('\"');
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:10: (~ '\"' )+
+ int cnt6=0;
+ loop6:
+ do {
+ int alt6=2;
+ int LA6_0 = input.LA(1);
+ if ( ((LA6_0>='\u0000' && LA6_0<='!')||(LA6_0>='#' && LA6_0<='\uFFFE')) ) {
+ alt6=1;
+ }
+
+
+ switch (alt6) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:10: ~ '\"'
+ {
+ if ( (input.LA(1)>='\u0000' && input.LA(1)<='!')||(input.LA(1)>='#' && input.LA(1)<='\uFFFE') ) {
+ input.consume();
+
+ }
+ else {
+ MismatchedSetException mse =
+ new MismatchedSetException(null,input);
+ recover(mse); throw mse;
+ }
+
+
+ }
+ break;
+
+ default :
+ if ( cnt6 >= 1 ) break loop6;
+ EarlyExitException eee =
+ new EarlyExitException(6, input);
+ throw eee;
+ }
+ cnt6++;
+ } while (true);
+
+ match('\"');
+
+ }
+
+
+ }
+ break;
+ case 2 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:23: ( '\\'' (~ '\\'' )+ '\\'' )
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:23: ( '\\'' (~ '\\'' )+ '\\'' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:24: '\\'' (~ '\\'' )+ '\\''
+ {
+ match('\'');
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:29: (~ '\\'' )+
+ int cnt7=0;
+ loop7:
+ do {
+ int alt7=2;
+ int LA7_0 = input.LA(1);
+ if ( ((LA7_0>='\u0000' && LA7_0<='&')||(LA7_0>='(' && LA7_0<='\uFFFE')) ) {
+ alt7=1;
+ }
+
+
+ switch (alt7) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:280:29: ~ '\\''
+ {
+ if ( (input.LA(1)>='\u0000' && input.LA(1)<='&')||(input.LA(1)>='(' && input.LA(1)<='\uFFFE') ) {
+ input.consume();
+
+ }
+ else {
+ MismatchedSetException mse =
+ new MismatchedSetException(null,input);
+ recover(mse); throw mse;
+ }
+
+
+ }
+ break;
+
+ default :
+ if ( cnt7 >= 1 ) break loop7;
+ EarlyExitException eee =
+ new EarlyExitException(7, input);
+ throw eee;
+ }
+ cnt7++;
+ } while (true);
+
+ match('\'');
+
+ }
+
+
+ }
+ break;
+
+ }
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end STRING
+
+ // $ANTLR start FLOAT
+ public void mFLOAT() throws RecognitionException {
+ try {
+ ruleNestingLevel++;
+ int _type = FLOAT;
+ int _start = getCharIndex();
+ int _line = getLine();
+ int _charPosition = getCharPositionInLine();
+ int _channel = Token.DEFAULT_CHANNEL;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:285:3: ( ( '0' .. '9' )+ '.' ( '0' .. '9' )+ )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:285:3: ( '0' .. '9' )+ '.' ( '0' .. '9' )+
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:285:3: ( '0' .. '9' )+
+ int cnt9=0;
+ loop9:
+ do {
+ int alt9=2;
+ int LA9_0 = input.LA(1);
+ if ( ((LA9_0>='0' && LA9_0<='9')) ) {
+ alt9=1;
+ }
+
+
+ switch (alt9) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:285:4: '0' .. '9'
+ {
+ matchRange('0','9');
+
+ }
+ break;
+
+ default :
+ if ( cnt9 >= 1 ) break loop9;
+ EarlyExitException eee =
+ new EarlyExitException(9, input);
+ throw eee;
+ }
+ cnt9++;
+ } while (true);
+
+ match('.');
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:285:17: ( '0' .. '9' )+
+ int cnt10=0;
+ loop10:
+ do {
+ int alt10=2;
+ int LA10_0 = input.LA(1);
+ if ( ((LA10_0>='0' && LA10_0<='9')) ) {
+ alt10=1;
+ }
+
+
+ switch (alt10) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:285:18: '0' .. '9'
+ {
+ matchRange('0','9');
+
+ }
+ break;
+
+ default :
+ if ( cnt10 >= 1 ) break loop10;
+ EarlyExitException eee =
+ new EarlyExitException(10, input);
+ throw eee;
+ }
+ cnt10++;
+ } while (true);
+
+
+ }
+
+
+
+ if ( token==null && ruleNestingLevel==1 ) {
+ emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);
+ }
+
+ }
+ finally {
+ ruleNestingLevel--;
+ }
+ }
+ // $ANTLR end FLOAT
+
+ public void mTokens() throws RecognitionException {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:10: ( T8 | T9 | T10 | T11 | T12 | T13 | T14 | T15 | T16 | T17 | T18 | T19 | T20 | T21 | T22 | T23 | T24 | T25 | T26 | T27 | T28 | IDENT | INTEGER | STRING | FLOAT )
+ int alt11=25;
+ alt11 = dfa11.predict(input);
+ switch (alt11) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:10: T8
+ {
+ mT8();
+
+ }
+ break;
+ case 2 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:13: T9
+ {
+ mT9();
+
+ }
+ break;
+ case 3 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:16: T10
+ {
+ mT10();
+
+ }
+ break;
+ case 4 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:20: T11
+ {
+ mT11();
+
+ }
+ break;
+ case 5 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:24: T12
+ {
+ mT12();
+
+ }
+ break;
+ case 6 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:28: T13
+ {
+ mT13();
+
+ }
+ break;
+ case 7 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:32: T14
+ {
+ mT14();
+
+ }
+ break;
+ case 8 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:36: T15
+ {
+ mT15();
+
+ }
+ break;
+ case 9 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:40: T16
+ {
+ mT16();
+
+ }
+ break;
+ case 10 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:44: T17
+ {
+ mT17();
+
+ }
+ break;
+ case 11 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:48: T18
+ {
+ mT18();
+
+ }
+ break;
+ case 12 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:52: T19
+ {
+ mT19();
+
+ }
+ break;
+ case 13 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:56: T20
+ {
+ mT20();
+
+ }
+ break;
+ case 14 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:60: T21
+ {
+ mT21();
+
+ }
+ break;
+ case 15 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:64: T22
+ {
+ mT22();
+
+ }
+ break;
+ case 16 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:68: T23
+ {
+ mT23();
+
+ }
+ break;
+ case 17 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:72: T24
+ {
+ mT24();
+
+ }
+ break;
+ case 18 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:76: T25
+ {
+ mT25();
+
+ }
+ break;
+ case 19 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:80: T26
+ {
+ mT26();
+
+ }
+ break;
+ case 20 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:84: T27
+ {
+ mT27();
+
+ }
+ break;
+ case 21 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:88: T28
+ {
+ mT28();
+
+ }
+ break;
+ case 22 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:92: IDENT
+ {
+ mIDENT();
+
+ }
+ break;
+ case 23 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:98: INTEGER
+ {
+ mINTEGER();
+
+ }
+ break;
+ case 24 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:106: STRING
+ {
+ mSTRING();
+
+ }
+ break;
+ case 25 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:1:113: FLOAT
+ {
+ mFLOAT();
+
+ }
+ break;
+
+ }
+
+ }
+
+
+ protected DFA11 dfa11 = new DFA11(this);
+ public static final String DFA11_eotS =
+ "\4\uffff\2\24\1\34\6\uffff\1\24\7\uffff\1\40\2\uffff\2\24\1\44\2"+
+ "\uffff\1\24\1\uffff\1\40\1\uffff\1\40\1\24\1\47\1\uffff\2\24\1\uffff"+
+ "\1\52\1\53\2\uffff";
+ public static final String DFA11_eofS =
+ "\54\uffff";
+ public static final String DFA11_minS =
+ "\1\42\3\uffff\1\141\1\156\1\76\6\uffff\1\162\7\uffff\2\56\1\uffff"+
+ "\1\154\1\162\1\60\2\uffff\1\165\1\uffff\1\56\1\uffff\1\56\1\163"+
+ "\1\60\1\uffff\2\145\1\uffff\2\60\2\uffff";
+ public static final String DFA11_maxS =
+ "\1\175\3\uffff\1\157\1\156\1\76\6\uffff\1\162\7\uffff\1\71\1\170"+
+ "\1\uffff\1\154\1\162\1\172\2\uffff\1\165\1\uffff\1\71\1\uffff\1"+
+ "\71\1\163\1\172\1\uffff\2\145\1\uffff\2\172\2\uffff";
+ public static final String DFA11_acceptS =
+ "\1\uffff\1\1\1\2\1\3\3\uffff\1\7\1\10\1\11\1\12\1\13\1\14\1\uffff"+
+ "\1\17\1\20\1\21\1\22\1\23\1\24\1\26\2\uffff\1\30\3\uffff\1\25\1"+
+ "\6\1\uffff\1\31\1\uffff\1\27\3\uffff\1\5\2\uffff\1\4\2\uffff\1\15"+
+ "\1\16";
+ public static final String DFA11_specialS =
+ "\54\uffff}>";
+ public static final String[] DFA11_transition = {
+ "\1\27\1\uffff\1\24\1\uffff\1\10\1\27\1\16\1\17\1\13\1\11\1\20\1"+
+ "\12\1\23\1\14\1\26\11\25\1\uffff\1\1\1\uffff\1\6\3\uffff\32\24\1"+
+ "\21\1\uffff\1\22\1\uffff\1\24\1\uffff\5\24\1\4\2\24\1\5\12\24\1"+
+ "\15\6\24\1\2\1\7\1\3",
+ "",
+ "",
+ "",
+ "\1\30\15\uffff\1\31",
+ "\1\32",
+ "\1\33",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "\1\35",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "\1\36\1\uffff\12\37",
+ "\1\36\1\uffff\10\41\2\36\76\uffff\1\40",
+ "",
+ "\1\42",
+ "\1\43",
+ "\12\24\7\uffff\32\24\4\uffff\1\24\1\uffff\32\24",
+ "",
+ "",
+ "\1\45",
+ "",
+ "\1\36\1\uffff\12\37",
+ "",
+ "\1\36\1\uffff\10\41\2\36",
+ "\1\46",
+ "\12\24\7\uffff\32\24\4\uffff\1\24\1\uffff\32\24",
+ "",
+ "\1\50",
+ "\1\51",
+ "",
+ "\12\24\7\uffff\32\24\4\uffff\1\24\1\uffff\32\24",
+ "\12\24\7\uffff\32\24\4\uffff\1\24\1\uffff\32\24",
+ "",
+ ""
+ };
+
+ class DFA11 extends DFA {
+ public DFA11(BaseRecognizer recognizer) {
+ this.recognizer = recognizer;
+ this.decisionNumber = 11;
+ this.eot = DFA.unpackEncodedString(DFA11_eotS);
+ this.eof = DFA.unpackEncodedString(DFA11_eofS);
+ this.min = DFA.unpackEncodedStringToUnsignedChars(DFA11_minS);
+ this.max = DFA.unpackEncodedStringToUnsignedChars(DFA11_maxS);
+ this.accept = DFA.unpackEncodedString(DFA11_acceptS);
+ this.special = DFA.unpackEncodedString(DFA11_specialS);
+ int numStates = DFA11_transition.length;
+ this.transition = new short[numStates][];
+ for (int i=0; i<numStates; i++) {
+ transition[i] = DFA.unpackEncodedString(DFA11_transition[i]);
+ }
+ }
+ public String getDescription() {
+ return "1:1: Tokens : ( T8 | T9 | T10 | T11 | T12 | T13 | T14 | T15 | T16 | T17 | T18 | T19 | T20 | T21 | T22 | T23 | T24 | T25 | T26 | T27 | T28 | IDENT | INTEGER | STRING | FLOAT );";
+ }
+ }
+
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDIParser.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDIParser.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDIParser.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,1450 @@
+// $ANTLR 3.0b5 /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g 2006-11-27 17:08:59
+
+ package org.codehaus.jfdi.parser;
+ import org.codehaus.jfdi.interpreter.*;
+ import org.codehaus.jfdi.interpreter.operations.*;
+ import java.util.List;
+ import java.util.ArrayList;
+
+
+import org.antlr.runtime.*;
+import java.util.Stack;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+public class JFDIParser extends Parser {
+ public static final String[] tokenNames = new String[] {
+ "<invalid>", "<EOR>", "<DOWN>", "<UP>", "IDENT", "INTEGER", "STRING", "FLOAT", "';'", "'{'", "'}'", "'for'", "'in'", "'='", "'||'", "'&&'", "'+'", "'-'", "'*'", "'/'", "'true'", "'false'", "'('", "')'", "','", "'['", "']'", "'.'", "'=>'"
+ };
+ public static final int INTEGER=5;
+ public static final int IDENT=4;
+ public static final int EOF=-1;
+ public static final int STRING=6;
+ public static final int FLOAT=7;
+
+ public JFDIParser(TokenStream input) {
+ super(input);
+ ruleMemo = new HashMap[18+1];
+ }
+
+
+ public String[] getTokenNames() { return tokenNames; }
+ public String getGrammarFileName() { return "/Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g"; }
+
+
+
+ private ValueHandlerFactory factory;
+ private TypeResolver typeResolver;
+
+ public void setValueHandlerFactory(ValueHandlerFactory factory) {
+ this.factory = factory;
+ }
+
+ public ValueHandlerFactory getValueHandlerFactory() {
+ return this.factory;
+ }
+
+ public void setTypeResolver(TypeResolver typeResolver) {
+ this.typeResolver = typeResolver;
+ }
+
+ public TypeResolver getTypeResolver() {
+ return typeResolver;
+ }
+
+
+
+
+ // $ANTLR start compilation_unit
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:39:1: compilation_unit : statements ;
+ public void compilation_unit() throws RecognitionException {
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:41:3: ( statements )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:41:3: statements
+ {
+ pushFollow(FOLLOW_statements_in_compilation_unit41);
+ statements();
+ _fsp--;
+ if (failed) return ;
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return ;
+ }
+ // $ANTLR end compilation_unit
+
+
+ // $ANTLR start statements
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:45:1: statements : ( statement ';' )* ;
+ public void statements() throws RecognitionException {
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:47:3: ( ( statement ';' )* )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:47:3: ( statement ';' )*
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:47:3: ( statement ';' )*
+ loop1:
+ do {
+ int alt1=2;
+ int LA1_0 = input.LA(1);
+ if ( ((LA1_0>=IDENT && LA1_0<=FLOAT)||LA1_0==9||LA1_0==11||(LA1_0>=20 && LA1_0<=22)||LA1_0==25) ) {
+ alt1=1;
+ }
+
+
+ switch (alt1) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:47:4: statement ';'
+ {
+ pushFollow(FOLLOW_statement_in_statements58);
+ statement();
+ _fsp--;
+ if (failed) return ;
+ match(input,8,FOLLOW_8_in_statements60); if (failed) return ;
+
+ }
+ break;
+
+ default :
+ break loop1;
+ }
+ } while (true);
+
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return ;
+ }
+ // $ANTLR end statements
+
+
+ // $ANTLR start statement
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:50:1: statement : ( expr | for_in_statement ) ;
+ public void statement() throws RecognitionException {
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:52:3: ( ( expr | for_in_statement ) )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:52:3: ( expr | for_in_statement )
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:52:3: ( expr | for_in_statement )
+ int alt2=2;
+ int LA2_0 = input.LA(1);
+ if ( ((LA2_0>=IDENT && LA2_0<=FLOAT)||LA2_0==9||(LA2_0>=20 && LA2_0<=22)||LA2_0==25) ) {
+ alt2=1;
+ }
+ else if ( (LA2_0==11) ) {
+ alt2=2;
+ }
+ else {
+ if (backtracking>0) {failed=true; return ;}
+ NoViableAltException nvae =
+ new NoViableAltException("52:3: ( expr | for_in_statement )", 2, 0, input);
+
+ throw nvae;
+ }
+ switch (alt2) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:52:5: expr
+ {
+ pushFollow(FOLLOW_expr_in_statement78);
+ expr();
+ _fsp--;
+ if (failed) return ;
+
+ }
+ break;
+ case 2 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:53:5: for_in_statement
+ {
+ pushFollow(FOLLOW_for_in_statement_in_statement84);
+ for_in_statement();
+ _fsp--;
+ if (failed) return ;
+
+ }
+ break;
+
+ }
+
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return ;
+ }
+ // $ANTLR end statement
+
+
+ // $ANTLR start statement_block
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:57:1: statement_block : '{' statements '}' ;
+ public void statement_block() throws RecognitionException {
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:59:3: ( '{' statements '}' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:59:3: '{' statements '}'
+ {
+ match(input,9,FOLLOW_9_in_statement_block102); if (failed) return ;
+ pushFollow(FOLLOW_statements_in_statement_block104);
+ statements();
+ _fsp--;
+ if (failed) return ;
+ match(input,10,FOLLOW_10_in_statement_block106); if (failed) return ;
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return ;
+ }
+ // $ANTLR end statement_block
+
+
+ // $ANTLR start for_in_statement
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:62:1: for_in_statement : 'for' IDENT 'in' expr statement_block ;
+ public void for_in_statement() throws RecognitionException {
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:64:3: ( 'for' IDENT 'in' expr statement_block )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:64:3: 'for' IDENT 'in' expr statement_block
+ {
+ match(input,11,FOLLOW_11_in_for_in_statement120); if (failed) return ;
+ match(input,IDENT,FOLLOW_IDENT_in_for_in_statement122); if (failed) return ;
+ match(input,12,FOLLOW_12_in_for_in_statement124); if (failed) return ;
+ pushFollow(FOLLOW_expr_in_for_in_statement126);
+ expr();
+ _fsp--;
+ if (failed) return ;
+ pushFollow(FOLLOW_statement_block_in_for_in_statement128);
+ statement_block();
+ _fsp--;
+ if (failed) return ;
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return ;
+ }
+ // $ANTLR end for_in_statement
+
+
+ // $ANTLR start assignment_statement
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:67:1: assignment_statement : object_expr '=' expr ;
+ public void assignment_statement() throws RecognitionException {
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:69:3: ( object_expr '=' expr )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:69:3: object_expr '=' expr
+ {
+ pushFollow(FOLLOW_object_expr_in_assignment_statement141);
+ object_expr();
+ _fsp--;
+ if (failed) return ;
+ match(input,13,FOLLOW_13_in_assignment_statement143); if (failed) return ;
+ pushFollow(FOLLOW_expr_in_assignment_statement145);
+ expr();
+ _fsp--;
+ if (failed) return ;
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return ;
+ }
+ // $ANTLR end assignment_statement
+
+
+ // $ANTLR start expr
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:72:1: expr returns [Expr e] : ex= logical_or_expr ;
+ public Expr expr() throws RecognitionException {
+ Expr e = null;
+
+ Expr ex = null;
+
+
+
+ e = null;
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:77:18: (ex= logical_or_expr )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:77:18: ex= logical_or_expr
+ {
+ pushFollow(FOLLOW_logical_or_expr_in_expr174);
+ ex=logical_or_expr();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = ex;
+ }
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return e;
+ }
+ // $ANTLR end expr
+
+
+ // $ANTLR start logical_or_expr
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:85:1: logical_or_expr returns [Expr e] : lhs= logical_and_expr ( '||' rhs= logical_and_expr )* ;
+ public Expr logical_or_expr() throws RecognitionException {
+ Expr e = null;
+
+ Expr lhs = null;
+
+ Expr rhs = null;
+
+
+
+ e = null;
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:90:3: (lhs= logical_and_expr ( '||' rhs= logical_and_expr )* )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:90:3: lhs= logical_and_expr ( '||' rhs= logical_and_expr )*
+ {
+ pushFollow(FOLLOW_logical_and_expr_in_logical_or_expr206);
+ lhs=logical_and_expr();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = lhs;
+ }
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:91:3: ( '||' rhs= logical_and_expr )*
+ loop3:
+ do {
+ int alt3=2;
+ int LA3_0 = input.LA(1);
+ if ( (LA3_0==14) ) {
+ alt3=1;
+ }
+
+
+ switch (alt3) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:91:5: '||' rhs= logical_and_expr
+ {
+ match(input,14,FOLLOW_14_in_logical_or_expr214); if (failed) return e;
+ pushFollow(FOLLOW_logical_and_expr_in_logical_or_expr218);
+ rhs=logical_and_expr();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = new LogicalOrExpr( e, rhs );
+ }
+
+ }
+ break;
+
+ default :
+ break loop3;
+ }
+ } while (true);
+
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return e;
+ }
+ // $ANTLR end logical_or_expr
+
+
+ // $ANTLR start logical_and_expr
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:96:1: logical_and_expr returns [Expr e] : lhs= additive_expr ( '&&' rhs= additive_expr )* ;
+ public Expr logical_and_expr() throws RecognitionException {
+ Expr e = null;
+
+ Expr lhs = null;
+
+ Expr rhs = null;
+
+
+
+ e = null;
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:101:3: (lhs= additive_expr ( '&&' rhs= additive_expr )* )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:101:3: lhs= additive_expr ( '&&' rhs= additive_expr )*
+ {
+ pushFollow(FOLLOW_additive_expr_in_logical_and_expr255);
+ lhs=additive_expr();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = lhs;
+ }
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:102:3: ( '&&' rhs= additive_expr )*
+ loop4:
+ do {
+ int alt4=2;
+ int LA4_0 = input.LA(1);
+ if ( (LA4_0==15) ) {
+ alt4=1;
+ }
+
+
+ switch (alt4) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:102:5: '&&' rhs= additive_expr
+ {
+ match(input,15,FOLLOW_15_in_logical_and_expr263); if (failed) return e;
+ pushFollow(FOLLOW_additive_expr_in_logical_and_expr267);
+ rhs=additive_expr();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = new LogicalAndExpr( e, rhs );
+ }
+
+ }
+ break;
+
+ default :
+ break loop4;
+ }
+ } while (true);
+
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return e;
+ }
+ // $ANTLR end logical_and_expr
+
+
+ // $ANTLR start additive_expr
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:108:1: additive_expr returns [Expr e] : lhs= multiplicative_expr ( ( '+' | '-' ) rhs= multiplicative_expr )* ;
+ public Expr additive_expr() throws RecognitionException {
+ Expr e = null;
+
+ Expr lhs = null;
+
+ Expr rhs = null;
+
+
+
+ e = null;
+ AdditiveExpr.Operator op = null;
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:114:3: (lhs= multiplicative_expr ( ( '+' | '-' ) rhs= multiplicative_expr )* )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:114:3: lhs= multiplicative_expr ( ( '+' | '-' ) rhs= multiplicative_expr )*
+ {
+ pushFollow(FOLLOW_multiplicative_expr_in_additive_expr305);
+ lhs=multiplicative_expr();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = lhs;
+ }
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:115:3: ( ( '+' | '-' ) rhs= multiplicative_expr )*
+ loop6:
+ do {
+ int alt6=2;
+ int LA6_0 = input.LA(1);
+ if ( ((LA6_0>=16 && LA6_0<=17)) ) {
+ alt6=1;
+ }
+
+
+ switch (alt6) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:116:4: ( '+' | '-' ) rhs= multiplicative_expr
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:116:4: ( '+' | '-' )
+ int alt5=2;
+ int LA5_0 = input.LA(1);
+ if ( (LA5_0==16) ) {
+ alt5=1;
+ }
+ else if ( (LA5_0==17) ) {
+ alt5=2;
+ }
+ else {
+ if (backtracking>0) {failed=true; return e;}
+ NoViableAltException nvae =
+ new NoViableAltException("116:4: ( '+' | '-' )", 5, 0, input);
+
+ throw nvae;
+ }
+ switch (alt5) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:116:6: '+'
+ {
+ match(input,16,FOLLOW_16_in_additive_expr319); if (failed) return e;
+ if ( backtracking==0 ) {
+ op = AdditiveExpr.PLUS;
+ }
+
+ }
+ break;
+ case 2 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:117:6: '-'
+ {
+ match(input,17,FOLLOW_17_in_additive_expr328); if (failed) return e;
+ if ( backtracking==0 ) {
+ op = AdditiveExpr.MINUS;
+ }
+
+ }
+ break;
+
+ }
+
+ pushFollow(FOLLOW_multiplicative_expr_in_additive_expr343);
+ rhs=multiplicative_expr();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = new AdditiveExpr( e, rhs, op );
+ }
+
+ }
+ break;
+
+ default :
+ break loop6;
+ }
+ } while (true);
+
+ if ( backtracking==0 ) {
+ System.err.println( "add_expr returns " + e );
+ }
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return e;
+ }
+ // $ANTLR end additive_expr
+
+
+ // $ANTLR start multiplicative_expr
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:125:1: multiplicative_expr returns [Expr e] : lhs= atom ( ( '*' | '/' ) rhs= atom )* ;
+ public Expr multiplicative_expr() throws RecognitionException {
+ Expr e = null;
+
+ Expr lhs = null;
+
+ Expr rhs = null;
+
+
+
+ e = null;
+ MultiplicativeExpr.Operator op = null;
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:131:3: (lhs= atom ( ( '*' | '/' ) rhs= atom )* )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:131:3: lhs= atom ( ( '*' | '/' ) rhs= atom )*
+ {
+ pushFollow(FOLLOW_atom_in_multiplicative_expr383);
+ lhs=atom();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = lhs;
+ }
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:132:3: ( ( '*' | '/' ) rhs= atom )*
+ loop8:
+ do {
+ int alt8=2;
+ int LA8_0 = input.LA(1);
+ if ( ((LA8_0>=18 && LA8_0<=19)) ) {
+ alt8=1;
+ }
+
+
+ switch (alt8) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:133:4: ( '*' | '/' ) rhs= atom
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:133:4: ( '*' | '/' )
+ int alt7=2;
+ int LA7_0 = input.LA(1);
+ if ( (LA7_0==18) ) {
+ alt7=1;
+ }
+ else if ( (LA7_0==19) ) {
+ alt7=2;
+ }
+ else {
+ if (backtracking>0) {failed=true; return e;}
+ NoViableAltException nvae =
+ new NoViableAltException("133:4: ( '*' | '/' )", 7, 0, input);
+
+ throw nvae;
+ }
+ switch (alt7) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:133:6: '*'
+ {
+ match(input,18,FOLLOW_18_in_multiplicative_expr396); if (failed) return e;
+ if ( backtracking==0 ) {
+ op = MultiplicativeExpr.MULT;
+ }
+
+ }
+ break;
+ case 2 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:134:6: '/'
+ {
+ match(input,19,FOLLOW_19_in_multiplicative_expr406); if (failed) return e;
+ if ( backtracking==0 ) {
+ op = MultiplicativeExpr.DIV;
+ }
+
+ }
+ break;
+
+ }
+
+ pushFollow(FOLLOW_atom_in_multiplicative_expr421);
+ rhs=atom();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = new MultiplicativeExpr( e, rhs, op );
+ }
+
+ }
+ break;
+
+ default :
+ break loop8;
+ }
+ } while (true);
+
+ if ( backtracking==0 ) {
+ System.err.println( "mult_expr returns " + e );
+ }
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return e;
+ }
+ // $ANTLR end multiplicative_expr
+
+
+ // $ANTLR start atom
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:142:1: atom returns [Expr e] : (i= INTEGER | s= STRING | f= FLOAT | 'true' | 'false' | '(' ex= expr ')' | l= list | m= map | ex= object_expr ) ;
+ public Expr atom() throws RecognitionException {
+ Expr e = null;
+
+ Token i=null;
+ Token s=null;
+ Token f=null;
+ Expr ex = null;
+
+ AnonListValue l = null;
+
+ AnonMapValue m = null;
+
+
+
+ e = null;
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:147:3: ( (i= INTEGER | s= STRING | f= FLOAT | 'true' | 'false' | '(' ex= expr ')' | l= list | m= map | ex= object_expr ) )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:147:3: (i= INTEGER | s= STRING | f= FLOAT | 'true' | 'false' | '(' ex= expr ')' | l= list | m= map | ex= object_expr )
+ {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:147:3: (i= INTEGER | s= STRING | f= FLOAT | 'true' | 'false' | '(' ex= expr ')' | l= list | m= map | ex= object_expr )
+ int alt9=9;
+ switch ( input.LA(1) ) {
+ case INTEGER:
+ alt9=1;
+ break;
+ case STRING:
+ alt9=2;
+ break;
+ case FLOAT:
+ alt9=3;
+ break;
+ case 20:
+ alt9=4;
+ break;
+ case 21:
+ alt9=5;
+ break;
+ case 22:
+ alt9=6;
+ break;
+ case 25:
+ alt9=7;
+ break;
+ case 9:
+ alt9=8;
+ break;
+ case IDENT:
+ alt9=9;
+ break;
+ default:
+ if (backtracking>0) {failed=true; return e;}
+ NoViableAltException nvae =
+ new NoViableAltException("147:3: (i= INTEGER | s= STRING | f= FLOAT | 'true' | 'false' | '(' ex= expr ')' | l= list | m= map | ex= object_expr )", 9, 0, input);
+
+ throw nvae;
+ }
+
+ switch (alt9) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:147:5: i= INTEGER
+ {
+ i=(Token)input.LT(1);
+ match(input,INTEGER,FOLLOW_INTEGER_in_atom463); if (failed) return e;
+ if ( backtracking==0 ) {
+ e = factory.createLiteral( java.lang.Integer.class, i.getText() );
+ }
+
+ }
+ break;
+ case 2 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:148:5: s= STRING
+ {
+ s=(Token)input.LT(1);
+ match(input,STRING,FOLLOW_STRING_in_atom473); if (failed) return e;
+ if ( backtracking==0 ) {
+ e = factory.createLiteral( java.lang.String.class, s.getText().substring( 1, s.getText().length()-1 ) );
+ }
+
+ }
+ break;
+ case 3 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:149:5: f= FLOAT
+ {
+ f=(Token)input.LT(1);
+ match(input,FLOAT,FOLLOW_FLOAT_in_atom484); if (failed) return e;
+ if ( backtracking==0 ) {
+ e = factory.createLiteral( java.lang.Double.class, f.getText() );
+ }
+
+ }
+ break;
+ case 4 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:150:5: 'true'
+ {
+ match(input,20,FOLLOW_20_in_atom494); if (failed) return e;
+ if ( backtracking==0 ) {
+ e = factory.createLiteral( java.lang.Boolean.class, "true" );
+ }
+
+ }
+ break;
+ case 5 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:151:5: 'false'
+ {
+ match(input,21,FOLLOW_21_in_atom505); if (failed) return e;
+ if ( backtracking==0 ) {
+ e = factory.createLiteral( java.lang.Boolean.class, "false" );
+ }
+
+ }
+ break;
+ case 6 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:152:5: '(' ex= expr ')'
+ {
+ match(input,22,FOLLOW_22_in_atom515); if (failed) return e;
+ pushFollow(FOLLOW_expr_in_atom519);
+ ex=expr();
+ _fsp--;
+ if (failed) return e;
+ match(input,23,FOLLOW_23_in_atom521); if (failed) return e;
+ if ( backtracking==0 ) {
+ e = ex;
+ }
+
+ }
+ break;
+ case 7 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:153:5: l= list
+ {
+ pushFollow(FOLLOW_list_in_atom531);
+ l=list();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = l;
+ }
+
+ }
+ break;
+ case 8 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:154:5: m= map
+ {
+ pushFollow(FOLLOW_map_in_atom541);
+ m=map();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = m;
+ }
+
+ }
+ break;
+ case 9 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:155:5: ex= object_expr
+ {
+ pushFollow(FOLLOW_object_expr_in_atom551);
+ ex=object_expr();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+ e = ex;
+ }
+
+ }
+ break;
+
+ }
+
+ if ( backtracking==0 ) {
+ System.err.println( "atom returns " + e );
+ }
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return e;
+ }
+ // $ANTLR end atom
+
+
+ // $ANTLR start arg_list
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:160:1: arg_list returns [List args] : first= expr ( ',' other= expr )* ;
+ public List arg_list() throws RecognitionException {
+ List args = null;
+
+ Expr first = null;
+
+ Expr other = null;
+
+
+
+ args = new ArrayList();
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:165:3: (first= expr ( ',' other= expr )* )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:165:3: first= expr ( ',' other= expr )*
+ {
+ pushFollow(FOLLOW_expr_in_arg_list589);
+ first=expr();
+ _fsp--;
+ if (failed) return args;
+ if ( backtracking==0 ) {
+ args.add( first );
+ }
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:166:3: ( ',' other= expr )*
+ loop10:
+ do {
+ int alt10=2;
+ int LA10_0 = input.LA(1);
+ if ( (LA10_0==24) ) {
+ alt10=1;
+ }
+
+
+ switch (alt10) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:166:6: ',' other= expr
+ {
+ match(input,24,FOLLOW_24_in_arg_list599); if (failed) return args;
+ pushFollow(FOLLOW_expr_in_arg_list603);
+ other=expr();
+ _fsp--;
+ if (failed) return args;
+ if ( backtracking==0 ) {
+ args.add( other );
+ }
+
+ }
+ break;
+
+ default :
+ break loop10;
+ }
+ } while (true);
+
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return args;
+ }
+ // $ANTLR end arg_list
+
+
+ // $ANTLR start object_expr
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:171:1: object_expr returns [Expr e] : i= IDENT ( ( '[' ~ '[' )=> '[' expr ']' | '.' n= IDENT ( '(' (a= arg_list )? ')' )? )* ;
+ public Expr object_expr() throws RecognitionException {
+ Expr e = null;
+
+ Token i=null;
+ Token n=null;
+ List a = null;
+
+
+
+ e = null;
+ boolean isMethod = false;
+ Expr[] paramExprs = new Expr[0];
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:178:3: (i= IDENT ( ( '[' ~ '[' )=> '[' expr ']' | '.' n= IDENT ( '(' (a= arg_list )? ')' )? )* )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:178:3: i= IDENT ( ( '[' ~ '[' )=> '[' expr ']' | '.' n= IDENT ( '(' (a= arg_list )? ')' )? )*
+ {
+ i=(Token)input.LT(1);
+ match(input,IDENT,FOLLOW_IDENT_in_object_expr640); if (failed) return e;
+ if ( backtracking==0 ) {
+ e = factory.createExternalVariable( i.getText() );
+ }
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:179:3: ( ( '[' ~ '[' )=> '[' expr ']' | '.' n= IDENT ( '(' (a= arg_list )? ')' )? )*
+ loop13:
+ do {
+ int alt13=3;
+ int LA13_0 = input.LA(1);
+ if ( (LA13_0==25) ) {
+ alt13=1;
+ }
+ else if ( (LA13_0==27) ) {
+ alt13=2;
+ }
+
+
+ switch (alt13) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:179:5: ( '[' ~ '[' )=> '[' expr ']'
+ {
+ match(input,25,FOLLOW_25_in_object_expr658); if (failed) return e;
+ pushFollow(FOLLOW_expr_in_object_expr660);
+ expr();
+ _fsp--;
+ if (failed) return e;
+ match(input,26,FOLLOW_26_in_object_expr662); if (failed) return e;
+
+ }
+ break;
+ case 2 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:180:5: '.' n= IDENT ( '(' (a= arg_list )? ')' )?
+ {
+ match(input,27,FOLLOW_27_in_object_expr668); if (failed) return e;
+ n=(Token)input.LT(1);
+ match(input,IDENT,FOLLOW_IDENT_in_object_expr672); if (failed) return e;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:181:4: ( '(' (a= arg_list )? ')' )?
+ int alt12=2;
+ int LA12_0 = input.LA(1);
+ if ( (LA12_0==22) ) {
+ alt12=1;
+ }
+ switch (alt12) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:181:6: '(' (a= arg_list )? ')'
+ {
+ match(input,22,FOLLOW_22_in_object_expr680); if (failed) return e;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:182:6: (a= arg_list )?
+ int alt11=2;
+ int LA11_0 = input.LA(1);
+ if ( ((LA11_0>=IDENT && LA11_0<=FLOAT)||LA11_0==9||(LA11_0>=20 && LA11_0<=22)||LA11_0==25) ) {
+ alt11=1;
+ }
+ switch (alt11) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:182:8: a= arg_list
+ {
+ pushFollow(FOLLOW_arg_list_in_object_expr691);
+ a=arg_list();
+ _fsp--;
+ if (failed) return e;
+ if ( backtracking==0 ) {
+
+ paramExprs = new Expr[ a.size() ];
+ for ( int j = 0 ; j < paramExprs.length ; ++j ) {
+ paramExprs[j] = (Expr) a.get( j );
+ }
+
+ }
+
+ }
+ break;
+
+ }
+
+ match(input,23,FOLLOW_23_in_object_expr714); if (failed) return e;
+ if ( backtracking==0 ) {
+ isMethod = true;
+ }
+
+ }
+ break;
+
+ }
+
+ if ( backtracking==0 ) {
+
+ String name = n.getText();
+ if ( ! isMethod ) {
+ name = "get" + name.substring(0,1).toUpperCase() + name.substring(1);
+ }
+ e = new MethodCall( e, name, paramExprs );
+ paramExprs = new Expr[0];
+ isMethod = false;
+
+ }
+
+ }
+ break;
+
+ default :
+ break loop13;
+ }
+ } while (true);
+
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return e;
+ }
+ // $ANTLR end object_expr
+
+
+ // $ANTLR start cast
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:205:1: cast returns [Class type] : '(' i= IDENT ')' ;
+ public Class cast() throws RecognitionException {
+ Class type = null;
+
+ Token i=null;
+
+
+ type = null;
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:210:3: ( '(' i= IDENT ')' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:210:3: '(' i= IDENT ')'
+ {
+ match(input,22,FOLLOW_22_in_cast766); if (failed) return type;
+ i=(Token)input.LT(1);
+ match(input,IDENT,FOLLOW_IDENT_in_cast770); if (failed) return type;
+ match(input,23,FOLLOW_23_in_cast772); if (failed) return type;
+ if ( backtracking==0 ) {
+
+ try {
+ type = typeResolver.resolveType( i.getText() );
+ System.err.println( "CASTING TO " + type);
+ } catch (ClassNotFoundException e) {
+ System.err.println( e.getMessage() );
+ }
+
+ }
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return type;
+ }
+ // $ANTLR end cast
+
+
+ // $ANTLR start map
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:221:1: map returns [AnonMapValue m] : '{' (k= expr '=>' v= expr ( ',' k= expr '=>' v= expr )* ( ',' )? )? '}' ;
+ public AnonMapValue map() throws RecognitionException {
+ AnonMapValue m = null;
+
+ Expr k = null;
+
+ Expr v = null;
+
+
+
+ m = null;
+ List pairs = new ArrayList();
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:227:3: ( '{' (k= expr '=>' v= expr ( ',' k= expr '=>' v= expr )* ( ',' )? )? '}' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:227:3: '{' (k= expr '=>' v= expr ( ',' k= expr '=>' v= expr )* ( ',' )? )? '}'
+ {
+ match(input,9,FOLLOW_9_in_map799); if (failed) return m;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:228:4: (k= expr '=>' v= expr ( ',' k= expr '=>' v= expr )* ( ',' )? )?
+ int alt16=2;
+ int LA16_0 = input.LA(1);
+ if ( ((LA16_0>=IDENT && LA16_0<=FLOAT)||LA16_0==9||(LA16_0>=20 && LA16_0<=22)||LA16_0==25) ) {
+ alt16=1;
+ }
+ switch (alt16) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:228:6: k= expr '=>' v= expr ( ',' k= expr '=>' v= expr )* ( ',' )?
+ {
+ pushFollow(FOLLOW_expr_in_map808);
+ k=expr();
+ _fsp--;
+ if (failed) return m;
+ match(input,28,FOLLOW_28_in_map810); if (failed) return m;
+ pushFollow(FOLLOW_expr_in_map814);
+ v=expr();
+ _fsp--;
+ if (failed) return m;
+ if ( backtracking==0 ) {
+ pairs.add( new AnonMapValue.KeyValuePair( k, v ) );
+ }
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:230:5: ( ',' k= expr '=>' v= expr )*
+ loop14:
+ do {
+ int alt14=2;
+ int LA14_0 = input.LA(1);
+ if ( (LA14_0==24) ) {
+ int LA14_1 = input.LA(2);
+ if ( ((LA14_1>=IDENT && LA14_1<=FLOAT)||LA14_1==9||(LA14_1>=20 && LA14_1<=22)||LA14_1==25) ) {
+ alt14=1;
+ }
+
+
+ }
+
+
+ switch (alt14) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:230:7: ',' k= expr '=>' v= expr
+ {
+ match(input,24,FOLLOW_24_in_map829); if (failed) return m;
+ pushFollow(FOLLOW_expr_in_map839);
+ k=expr();
+ _fsp--;
+ if (failed) return m;
+ match(input,28,FOLLOW_28_in_map841); if (failed) return m;
+ pushFollow(FOLLOW_expr_in_map845);
+ v=expr();
+ _fsp--;
+ if (failed) return m;
+ if ( backtracking==0 ) {
+ pairs.add( new AnonMapValue.KeyValuePair( k, v ) );
+ }
+
+ }
+ break;
+
+ default :
+ break loop14;
+ }
+ } while (true);
+
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:234:5: ( ',' )?
+ int alt15=2;
+ int LA15_0 = input.LA(1);
+ if ( (LA15_0==24) ) {
+ alt15=1;
+ }
+ switch (alt15) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:234:5: ','
+ {
+ match(input,24,FOLLOW_24_in_map866); if (failed) return m;
+
+ }
+ break;
+
+ }
+
+
+ }
+ break;
+
+ }
+
+ match(input,10,FOLLOW_10_in_map878); if (failed) return m;
+ if ( backtracking==0 ) {
+
+ m = new AnonMapValue( (AnonMapValue.KeyValuePair[]) pairs.toArray( new AnonMapValue.KeyValuePair[ pairs.size() ] ) );
+
+ }
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return m;
+ }
+ // $ANTLR end map
+
+
+ // $ANTLR start list
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:243:1: list returns [AnonListValue l] : '[' (v= expr ( ',' v= expr )* ( ',' )? )? ']' ;
+ public AnonListValue list() throws RecognitionException {
+ AnonListValue l = null;
+
+ Expr v = null;
+
+
+
+ l = null;
+ List values = new ArrayList();
+
+ try {
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:249:3: ( '[' (v= expr ( ',' v= expr )* ( ',' )? )? ']' )
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:249:3: '[' (v= expr ( ',' v= expr )* ( ',' )? )? ']'
+ {
+ match(input,25,FOLLOW_25_in_list906); if (failed) return l;
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:249:7: (v= expr ( ',' v= expr )* ( ',' )? )?
+ int alt19=2;
+ int LA19_0 = input.LA(1);
+ if ( ((LA19_0>=IDENT && LA19_0<=FLOAT)||LA19_0==9||(LA19_0>=20 && LA19_0<=22)||LA19_0==25) ) {
+ alt19=1;
+ }
+ switch (alt19) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:249:9: v= expr ( ',' v= expr )* ( ',' )?
+ {
+ pushFollow(FOLLOW_expr_in_list912);
+ v=expr();
+ _fsp--;
+ if (failed) return l;
+ if ( backtracking==0 ) {
+ values.add( v );
+ }
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:251:5: ( ',' v= expr )*
+ loop17:
+ do {
+ int alt17=2;
+ int LA17_0 = input.LA(1);
+ if ( (LA17_0==24) ) {
+ int LA17_1 = input.LA(2);
+ if ( ((LA17_1>=IDENT && LA17_1<=FLOAT)||LA17_1==9||(LA17_1>=20 && LA17_1<=22)||LA17_1==25) ) {
+ alt17=1;
+ }
+
+
+ }
+
+
+ switch (alt17) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:251:7: ',' v= expr
+ {
+ match(input,24,FOLLOW_24_in_list926); if (failed) return l;
+ pushFollow(FOLLOW_expr_in_list930);
+ v=expr();
+ _fsp--;
+ if (failed) return l;
+ if ( backtracking==0 ) {
+ values.add( v );
+ }
+
+ }
+ break;
+
+ default :
+ break loop17;
+ }
+ } while (true);
+
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:254:5: ( ',' )?
+ int alt18=2;
+ int LA18_0 = input.LA(1);
+ if ( (LA18_0==24) ) {
+ alt18=1;
+ }
+ switch (alt18) {
+ case 1 :
+ // /Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g:254:5: ','
+ {
+ match(input,24,FOLLOW_24_in_list951); if (failed) return l;
+
+ }
+ break;
+
+ }
+
+
+ }
+ break;
+
+ }
+
+ match(input,26,FOLLOW_26_in_list964); if (failed) return l;
+ if ( backtracking==0 ) {
+
+ l = new AnonListValue( values );
+
+ }
+
+ }
+
+ }
+ catch (RecognitionException re) {
+ reportError(re);
+ recover(input,re);
+ }
+ finally {
+ }
+ return l;
+ }
+ // $ANTLR end list
+
+
+
+
+ public static final BitSet FOLLOW_statements_in_compilation_unit41 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_statement_in_statements58 = new BitSet(new long[]{0x0000000000000100L});
+ public static final BitSet FOLLOW_8_in_statements60 = new BitSet(new long[]{0x0000000002700AF2L});
+ public static final BitSet FOLLOW_expr_in_statement78 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_for_in_statement_in_statement84 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_9_in_statement_block102 = new BitSet(new long[]{0x0000000002700EF0L});
+ public static final BitSet FOLLOW_statements_in_statement_block104 = new BitSet(new long[]{0x0000000000000400L});
+ public static final BitSet FOLLOW_10_in_statement_block106 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_11_in_for_in_statement120 = new BitSet(new long[]{0x0000000000000010L});
+ public static final BitSet FOLLOW_IDENT_in_for_in_statement122 = new BitSet(new long[]{0x0000000000001000L});
+ public static final BitSet FOLLOW_12_in_for_in_statement124 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_for_in_statement126 = new BitSet(new long[]{0x0000000000000200L});
+ public static final BitSet FOLLOW_statement_block_in_for_in_statement128 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_object_expr_in_assignment_statement141 = new BitSet(new long[]{0x0000000000002000L});
+ public static final BitSet FOLLOW_13_in_assignment_statement143 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_assignment_statement145 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_logical_or_expr_in_expr174 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_logical_and_expr_in_logical_or_expr206 = new BitSet(new long[]{0x0000000000004002L});
+ public static final BitSet FOLLOW_14_in_logical_or_expr214 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_logical_and_expr_in_logical_or_expr218 = new BitSet(new long[]{0x0000000000004002L});
+ public static final BitSet FOLLOW_additive_expr_in_logical_and_expr255 = new BitSet(new long[]{0x0000000000008002L});
+ public static final BitSet FOLLOW_15_in_logical_and_expr263 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_additive_expr_in_logical_and_expr267 = new BitSet(new long[]{0x0000000000008002L});
+ public static final BitSet FOLLOW_multiplicative_expr_in_additive_expr305 = new BitSet(new long[]{0x0000000000030002L});
+ public static final BitSet FOLLOW_16_in_additive_expr319 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_17_in_additive_expr328 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_multiplicative_expr_in_additive_expr343 = new BitSet(new long[]{0x0000000000030002L});
+ public static final BitSet FOLLOW_atom_in_multiplicative_expr383 = new BitSet(new long[]{0x00000000000C0002L});
+ public static final BitSet FOLLOW_18_in_multiplicative_expr396 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_19_in_multiplicative_expr406 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_atom_in_multiplicative_expr421 = new BitSet(new long[]{0x00000000000C0002L});
+ public static final BitSet FOLLOW_INTEGER_in_atom463 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_STRING_in_atom473 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_FLOAT_in_atom484 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_20_in_atom494 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_21_in_atom505 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_22_in_atom515 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_atom519 = new BitSet(new long[]{0x0000000000800000L});
+ public static final BitSet FOLLOW_23_in_atom521 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_list_in_atom531 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_map_in_atom541 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_object_expr_in_atom551 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_expr_in_arg_list589 = new BitSet(new long[]{0x0000000001000002L});
+ public static final BitSet FOLLOW_24_in_arg_list599 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_arg_list603 = new BitSet(new long[]{0x0000000001000002L});
+ public static final BitSet FOLLOW_IDENT_in_object_expr640 = new BitSet(new long[]{0x000000000A000002L});
+ public static final BitSet FOLLOW_25_in_object_expr658 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_object_expr660 = new BitSet(new long[]{0x0000000004000000L});
+ public static final BitSet FOLLOW_26_in_object_expr662 = new BitSet(new long[]{0x000000000A000002L});
+ public static final BitSet FOLLOW_27_in_object_expr668 = new BitSet(new long[]{0x0000000000000010L});
+ public static final BitSet FOLLOW_IDENT_in_object_expr672 = new BitSet(new long[]{0x000000000A400002L});
+ public static final BitSet FOLLOW_22_in_object_expr680 = new BitSet(new long[]{0x0000000002F002F0L});
+ public static final BitSet FOLLOW_arg_list_in_object_expr691 = new BitSet(new long[]{0x0000000000800000L});
+ public static final BitSet FOLLOW_23_in_object_expr714 = new BitSet(new long[]{0x000000000A000002L});
+ public static final BitSet FOLLOW_22_in_cast766 = new BitSet(new long[]{0x0000000000000010L});
+ public static final BitSet FOLLOW_IDENT_in_cast770 = new BitSet(new long[]{0x0000000000800000L});
+ public static final BitSet FOLLOW_23_in_cast772 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_9_in_map799 = new BitSet(new long[]{0x00000000027006F0L});
+ public static final BitSet FOLLOW_expr_in_map808 = new BitSet(new long[]{0x0000000010000000L});
+ public static final BitSet FOLLOW_28_in_map810 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_map814 = new BitSet(new long[]{0x0000000001000400L});
+ public static final BitSet FOLLOW_24_in_map829 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_map839 = new BitSet(new long[]{0x0000000010000000L});
+ public static final BitSet FOLLOW_28_in_map841 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_map845 = new BitSet(new long[]{0x0000000001000400L});
+ public static final BitSet FOLLOW_24_in_map866 = new BitSet(new long[]{0x0000000000000400L});
+ public static final BitSet FOLLOW_10_in_map878 = new BitSet(new long[]{0x0000000000000002L});
+ public static final BitSet FOLLOW_25_in_list906 = new BitSet(new long[]{0x00000000067002F0L});
+ public static final BitSet FOLLOW_expr_in_list912 = new BitSet(new long[]{0x0000000005000000L});
+ public static final BitSet FOLLOW_24_in_list926 = new BitSet(new long[]{0x00000000027002F0L});
+ public static final BitSet FOLLOW_expr_in_list930 = new BitSet(new long[]{0x0000000005000000L});
+ public static final BitSet FOLLOW_24_in_list951 = new BitSet(new long[]{0x0000000004000000L});
+ public static final BitSet FOLLOW_26_in_list964 = new BitSet(new long[]{0x0000000000000002L});
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI__.g
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI__.g 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/codehaus/jfdi/parser/JFDI__.g 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,55 @@
+lexer grammar JFDI;
+ at header {
+ package org.codehaus.jfdi.parser;
+}
+
+T8 : ';' ;
+T9 : '{' ;
+T10 : '}' ;
+T11 : 'for' ;
+T12 : 'in' ;
+T13 : '=' ;
+T14 : '||' ;
+T15 : '&&' ;
+T16 : '+' ;
+T17 : '-' ;
+T18 : '*' ;
+T19 : '/' ;
+T20 : 'true' ;
+T21 : 'false' ;
+T22 : '(' ;
+T23 : ')' ;
+T24 : ',' ;
+T25 : '[' ;
+T26 : ']' ;
+T27 : '.' ;
+T28 : '=>' ;
+
+// $ANTLR src "/Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g" 265
+IDENT
+ :
+ ('a'..'z'|'A'..'Z'|'_'|'$')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
+ ;
+
+// $ANTLR src "/Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g" 270
+INTEGER
+ :
+ ( ('1'..'9')('0'..'9')*
+ | '0x' ('0'..'9'|'A'..'F'|'a'..'f')+
+ | '0' ('0'..'7')+
+ )
+ ;
+
+// $ANTLR src "/Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g" 278
+STRING
+ :
+ ( ('"' ~'"'+ '"') | ('\'' ~'\'' + '\'') )
+ ;
+
+// $ANTLR src "/Users/bob/checkouts/jfdi/src/org/codehaus/jfdi/parser/JFDI.g" 283
+FLOAT
+ :
+ ('0'..'9')+'.'('0'..'9')+
+ ;
+
+
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIDeclarationVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIDeclarationVariable.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIDeclarationVariable.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,51 @@
+package org.drools.base;
+
+import java.util.Map;
+
+import org.codehaus.jfdi.interpreter.VariableValueHandler;
+import org.drools.reteoo.ReteTuple;
+import org.drools.rule.Declaration;
+import org.drools.spi.FieldExtractor;
+
+public class DroolsJFDIDeclarationVariable
+ implements
+ VariableValueHandler {
+
+ private Declaration declaration;
+ private DroolsJFDIFactory factory;
+
+ public DroolsJFDIDeclarationVariable(Declaration declaration,
+ DroolsJFDIFactory factory ) {
+ this.declaration = declaration;
+ this.factory = factory;
+ }
+
+ public String getIdentifier() {
+ return this.declaration.getIdentifier();
+ }
+
+ public Class getType() {
+ return declaration.getExtractor().getExtractToClass();
+ }
+
+ public Object getValue() {
+ return declaration.getValue( this.factory.getValue( this.declaration ));
+ }
+
+ public boolean isFinal() {
+ return true;
+ }
+
+ public boolean isLiteral() {
+ return false;
+ }
+
+ public boolean isLocal() {
+ return false;
+ }
+
+ public void setValue(Object value) {
+ throw new UnsupportedOperationException( "External Variable identifer='" + getIdentifier() + "' type='" + getType() + "' is final, it cannot be set" );
+ }
+
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIFactory.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIFactory.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,69 @@
+package org.drools.base;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.jfdi.interpreter.AbstractValueHandlerFactory;
+import org.codehaus.jfdi.interpreter.TypeResolver;
+import org.codehaus.jfdi.interpreter.ValueHandler;
+import org.drools.WorkingMemory;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.ReteTuple;
+import org.drools.rule.Declaration;
+
+public class DroolsJFDIFactory extends AbstractValueHandlerFactory {
+ private ReteTuple tuple;
+ private Map declarations;
+ private Map globals;
+ //private
+ private WorkingMemory workingMemory;
+
+ public DroolsJFDIFactory(TypeResolver typeResolver) {
+ super( typeResolver );
+ }
+
+ public void setDeclarationMap(Map declarations) {
+ this.declarations = declarations;
+ }
+
+ public void setGlobalsMap(Map globals) {
+ this.globals = globals;
+ }
+
+ public void setContext(ReteTuple tuple, WorkingMemory workingMemory) {
+ this.tuple = tuple;
+ this.workingMemory = workingMemory;
+ }
+
+ public Object getValue(Declaration declaration) {
+ return tuple.get( declaration ).getObject();
+ }
+
+ public Object getValue(String identifier) {
+ return this.workingMemory.getGlobal( identifier );
+ }
+
+ public ValueHandler createExternalVariable(String identifier) {
+ registerExternalVariable( identifier );
+ ValueHandler variable;
+ if ( this.declarations.containsKey( identifier )) {
+ variable = new DroolsJFDIDeclarationVariable( (Declaration) this.declarations.get( identifier ), this );
+ } else {
+ variable = new DroolsJFDIGlobalVariable( identifier, (Class) this.globals.get( identifier ), this );
+ }
+ return variable;
+ }
+
+ public boolean isValidVariable(String identifier) {
+ return this.declarations.containsKey( identifier );
+ }
+
+ public Declaration[] getRequiredDeclarations() {
+ List list = new ArrayList();
+ for (int i = 0, length = this.requiredVariables.length; i < length; i++) {
+ list.add( this.declarations.get( this.requiredVariables[i] ) );
+ }
+ return (Declaration[]) list.toArray( new Declaration[list.size() ] );
+ }
+}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIGlobalVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIGlobalVariable.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsJFDIGlobalVariable.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,54 @@
+package org.drools.base;
+
+import java.util.Map;
+
+import org.codehaus.jfdi.interpreter.VariableValueHandler;
+import org.drools.reteoo.ReteTuple;
+import org.drools.rule.Declaration;
+import org.drools.spi.FieldExtractor;
+
+public class DroolsJFDIGlobalVariable
+ implements
+ VariableValueHandler {
+
+ private String identifier;
+ private Class type;
+ private DroolsJFDIFactory factory;
+
+ public DroolsJFDIGlobalVariable(String identifier,
+ Class type,
+ DroolsJFDIFactory factory ) {
+ this.identifier = identifier;
+ this.factory = factory;
+ this.type = type;
+ }
+
+ public String getIdentifier() {
+ return this.identifier;
+ }
+
+ public Class getType() {
+ return this.type;
+ }
+
+ public Object getValue() {
+ return this.factory.getValue( this.identifier );
+ }
+
+ public boolean isFinal() {
+ return true;
+ }
+
+ public boolean isLiteral() {
+ return false;
+ }
+
+ public boolean isLocal() {
+ return false;
+ }
+
+ public void setValue(Object value) {
+ throw new UnsupportedOperationException( "External Variable identifer='" + getIdentifier() + "' type='" + getType() + "' is final, it cannot be set" );
+ }
+
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/Invoker.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/Invoker.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/Invoker.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -1,14 +0,0 @@
-package org.drools.base.dataproviders;
-
-import org.drools.WorkingMemory;
-import org.drools.rule.Declaration;
-import org.drools.spi.PropagationContext;
-import org.drools.spi.Tuple;
-
-public interface Invoker {
- public Object invoke(Tuple tuple,
- WorkingMemory wm,
- PropagationContext ctx);
-
- public Declaration[] getRequiredDeclarations();
-}
Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/JFDIDataProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/JFDIDataProvider.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/JFDIDataProvider.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -0,0 +1,46 @@
+package org.drools.base.dataproviders;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.codehaus.jfdi.interpreter.operations.Expr;
+import org.codehaus.jfdi.parser.JFDIParser;
+import org.drools.WorkingMemory;
+import org.drools.base.DroolsJFDIFactory;
+import org.drools.reteoo.ReteTuple;
+import org.drools.rule.Declaration;
+import org.drools.spi.DataProvider;
+import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
+
+public class JFDIDataProvider
+ implements
+ DataProvider {
+ private final Expr expression;
+ private final DroolsJFDIFactory factory;
+
+ public JFDIDataProvider(final Expr expression,
+ final DroolsJFDIFactory factory) {
+ this.expression = expression;
+ this.factory = factory;
+ }
+
+ public Declaration[] getRequiredDeclarations() {
+ return factory.getRequiredDeclarations();
+ }
+
+ public Iterator getResults(final ReteTuple tuple,
+ final WorkingMemory wm,
+ final PropagationContext ctx) {
+ factory.setContext( tuple, wm );
+ Object result = this.expression.getValue();
+ if ( result instanceof Collection ) {
+ return ((Collection) result).iterator();
+ } else if ( result instanceof Iterator ) {
+ return (Iterator) result;
+ } else {
+ return Collections.singletonList( result ).iterator();
+ }
+ }
+}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MethodDataProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MethodDataProvider.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MethodDataProvider.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -1,41 +0,0 @@
-package org.drools.base.dataproviders;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-
-import org.drools.WorkingMemory;
-import org.drools.rule.Declaration;
-import org.drools.spi.DataProvider;
-import org.drools.spi.PropagationContext;
-import org.drools.spi.Tuple;
-
-public class MethodDataProvider
- implements
- DataProvider {
- private final Invoker invoker;
-
- public MethodDataProvider(final Invoker invoker) {
- this.invoker = invoker;
- }
-
- public Declaration[] getRequiredDeclarations() {
- return this.invoker.getRequiredDeclarations();
- }
-
- public Iterator getResults(final Tuple tuple,
- final WorkingMemory wm,
- final PropagationContext ctx) {
- final Object result = this.invoker.invoke( tuple,
- wm,
- ctx );
- if ( result instanceof Collection ) {
- return ((Collection) result).iterator();
- } else if ( result instanceof Iterator ) {
- return (Iterator) result;
- } else {
- return Collections.singletonList( result ).iterator();
- }
- }
-
-}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MethodInvoker.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MethodInvoker.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MethodInvoker.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -1,202 +0,0 @@
-package org.drools.base.dataproviders;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.drools.RuntimeDroolsException;
-import org.drools.WorkingMemory;
-import org.drools.base.evaluators.DateFactory;
-import org.drools.base.resolvers.DeclarationVariable;
-import org.drools.base.resolvers.LiteralValue;
-import org.drools.base.resolvers.ValueHandler;
-import org.drools.rule.Declaration;
-import org.drools.spi.PropagationContext;
-import org.drools.spi.Tuple;
-
-public class MethodInvoker
- implements
- Invoker {
- private final ValueHandler instanceValueHandler;
- private final Method method;
- private final Class[] parameterTypes;
- private final ValueHandler[] valueHandlers;
- private final Declaration[] requiredDeclarations;
- private static final Declaration[] EMPTY_DECLARATIONS = new Declaration[0];
-
- /**
- * Method invoker for static method
- */
- public MethodInvoker(final String methodName,
- final Class clazz,
- final ValueHandler[] valueHandlers) {
- this.instanceValueHandler = null;
- this.valueHandlers = valueHandlers;
-
- // determine required declarations
- final List list = new ArrayList( 1 );
-
- for ( int i = 0, length = valueHandlers.length; i < length; i++ ) {
- if ( valueHandlers[i].getClass() == DeclarationVariable.class ) {
- list.add( ((DeclarationVariable) valueHandlers[i]).getDeclaration() );
- }
- }
-
- if ( list.isEmpty() ) {
- this.requiredDeclarations = MethodInvoker.EMPTY_DECLARATIONS;
- } else {
- this.requiredDeclarations = (Declaration[]) list.toArray( new Declaration[list.size()] );
- }
-
- this.method = configureMethod( clazz,
- methodName,
- valueHandlers.length );
-
- //the types we have to convert the arguments to
- this.parameterTypes = this.method.getParameterTypes();
-
- }
-
- /**
- * Method invoker for an instance
- */
- public MethodInvoker(final String methodName,
- final ValueHandler instanceValueHandler,
- final ValueHandler[] valueHandlers) {
- this.instanceValueHandler = instanceValueHandler;
- this.valueHandlers = valueHandlers;
-
- // determine required declarations
- final List list = new ArrayList( 1 );
- if ( instanceValueHandler != null && instanceValueHandler.getClass() == DeclarationVariable.class ) {
- list.add( ((DeclarationVariable) instanceValueHandler).getDeclaration() );
- }
-
- for ( int i = 0, length = valueHandlers.length; i < length; i++ ) {
- if ( valueHandlers[i].getClass() == DeclarationVariable.class ) {
- list.add( ((DeclarationVariable) valueHandlers[i]).getDeclaration() );
- }
- }
-
- if ( list.isEmpty() ) {
- this.requiredDeclarations = MethodInvoker.EMPTY_DECLARATIONS;
- } else {
- this.requiredDeclarations = (Declaration[]) list.toArray( new Declaration[list.size()] );
- }
-
- this.method = configureMethod( this.instanceValueHandler.getExtractToClass(),
- methodName,
- valueHandlers.length );
-
- //the types we have to convert the arguments to
- this.parameterTypes = this.method.getParameterTypes();
- }
-
- /**
- * work out what method we will be calling at runtime, based on the name and number of parameters.
- */
- private static Method configureMethod(final Class clazz,
- final String methodName,
- final int numOfArgs) {
- final Method[] methods = clazz.getMethods();
- for ( int i = 0; i < methods.length; i++ ) {
- if ( methods[i].getName().equals( methodName ) ) {
- if ( methods[i].getParameterTypes().length == numOfArgs ) {
- return methods[i];
- }
- }
- }
- throw new IllegalArgumentException( "Unable to resolve the method: [" + methodName + "] on class: [" + clazz.getName() + "] with " + numOfArgs + " parameters." );
- }
-
- public Declaration[] getRequiredDeclarations() {
- return this.requiredDeclarations;
- }
-
- public Object invoke(final Tuple tuple,
- final WorkingMemory wm,
- final PropagationContext ctx) {
-
- //get the instance that we are operating on
- final Object instance = this.instanceValueHandler.getValue( tuple,
- wm );
-
- if ( instance == null ) {
- throw new IllegalArgumentException( "Unable to resolve the variable: [" + this.instanceValueHandler + "]" );
- }
-
- //the args values that we will pass
- final Object[] args = new Object[this.valueHandlers.length];
-
- //now we need to set all the values, convert if literal
- for ( int i = 0; i < this.valueHandlers.length; i++ ) {
- final ValueHandler handler = this.valueHandlers[i];
- if ( handler instanceof LiteralValue ) {
- final String text = (String) handler.getValue( tuple,
- wm );
- final Class type = this.parameterTypes[i];
- if ( type == String.class ) {
- args[i] = text;
- } else {
- args[i] = convert( text,
- type );
- }
- } else {
- args[i] = handler.getValue( tuple,
- wm );
- }
- }
-
- Object result = null;
- //now the actual invoking of the method
- try {
- result = this.method.invoke( instance,
- args );
- // @todo : should wrap and return an exception that the user understands
- } catch ( final IllegalArgumentException e ) {
- throw new RuntimeDroolsException( e );
- } catch ( final IllegalAccessException e ) {
- throw new RuntimeDroolsException( e );
- } catch ( final InvocationTargetException e ) {
- throw new RuntimeDroolsException( e );
- }
-
- return result;
- }
-
- /**
- * Attempt to convert text to the target class type
- */
- private static Object convert(final String text,
- final Class type) {
- if ( type == Integer.class || type == int.class ) {
- return new Integer( text );
- } else if ( text == "null" ) {
- return null;
- } else if ( type == Character.class || type == char.class ) {
- return (new Character( text.charAt( 0 ) ));
- } else if ( type == Short.class || type == short.class ) {
- return new Short( text );
- } else if ( type == Long.class || type == long.class ) {
- return new Long( text );
- } else if ( type == Float.class || type == float.class ) {
- return new Float( text );
- } else if ( type == Double.class || type == double.class ) {
- return new Double( text );
- } else if ( type == Boolean.class || type == boolean.class ) {
- return new Boolean( text );
- } else if ( type == Date.class ) {
- return DateFactory.parseDate( text );
- } else if ( type == BigDecimal.class ) {
- return new BigDecimal( text );
- } else if ( type == BigInteger.class ) {
- return new BigInteger( text );
- } else {
- throw new IllegalArgumentException( "Unable to convert [" + text + "] to type: [" + type.getName() + "]" );
- }
- }
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -18,7 +18,7 @@
public class FromNode extends TupleSource
implements
- TupleSink,
+ TupleSinkNode,
NodeMemory {
/**
*
@@ -30,6 +30,9 @@
private AlphaNodeFieldConstraint[] alphaConstraints;
private BetaConstraints betaConstraints;
+ private TupleSinkNode previousTupleSinkNode;
+ private TupleSinkNode nextTupleSinkNode;
+
public FromNode(final int id,
final DataProvider dataProvider,
final TupleSource tupleSource,
@@ -60,7 +63,7 @@
context ); it.hasNext(); ) {
final Object object = it.next();
- if( this.alphaConstraints != null ) {
+ if ( this.alphaConstraints != null ) {
// First alpha node filters
boolean isAllowed = true;
for ( int i = 0, length = this.alphaConstraints.length; i < length; i++ ) {
@@ -71,7 +74,7 @@
break;
}
}
- if( !isAllowed ) {
+ if ( !isAllowed ) {
continue;
}
}
@@ -179,4 +182,40 @@
null );
}
+ /**
+ * Returns the next node
+ * @return
+ * The next TupleSinkNode
+ */
+ public TupleSinkNode getNextTupleSinkNode() {
+ return this.nextTupleSinkNode;
+ }
+
+ /**
+ * Sets the next node
+ * @param next
+ * The next TupleSinkNode
+ */
+ public void setNextTupleSinkNode(final TupleSinkNode next) {
+ this.nextTupleSinkNode = next;
+ }
+
+ /**
+ * Returns the previous node
+ * @return
+ * The previous TupleSinkNode
+ */
+ public TupleSinkNode getPreviousTupleSinkNode() {
+ return this.previousTupleSinkNode;
+ }
+
+ /**
+ * Sets the previous node
+ * @param previous
+ * The previous TupleSinkNode
+ */
+ public void setPreviousTupleSinkNode(final TupleSinkNode previous) {
+ this.previousTupleSinkNode = previous;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/DataProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/DataProvider.java 2006-12-10 19:30:34 UTC (rev 8182)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/DataProvider.java 2006-12-10 19:56:41 UTC (rev 8183)
@@ -3,13 +3,14 @@
import java.util.Iterator;
import org.drools.WorkingMemory;
+import org.drools.reteoo.ReteTuple;
import org.drools.rule.Declaration;
public interface DataProvider {
public Declaration[] getRequiredDeclarations();
- public Iterator getResults(Tuple tuple,
+ public Iterator getResults(ReteTuple tuple,
WorkingMemory wm,
PropagationContext ctx);
More information about the jboss-svn-commits
mailing list