[jboss-svn-commits] JBL Code SVN: r20384 - in labs/jbossrules/trunk/drools-compiler/src/main: resources/org/drools/lang/dsl and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 9 14:26:19 EDT 2008


Author: tirelli
Date: 2008-06-09 14:26:19 -0400 (Mon, 09 Jun 2008)
New Revision: 20384

Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/AntlrDSLMappingEntry.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMapWalker.java
   labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/lang/dsl/DSLMapWalker.g
Log:
Fixing jsr94 errors

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/AntlrDSLMappingEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/AntlrDSLMappingEntry.java	2008-06-09 16:46:04 UTC (rev 20383)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/AntlrDSLMappingEntry.java	2008-06-09 18:26:19 UTC (rev 20384)
@@ -26,120 +26,128 @@
  * 
  * @author mattgeis
  */
-public class AntlrDSLMappingEntry extends AbstractDSLMappingEntry implements DSLMappingEntry {
-	private boolean headMatchGroupAdded = false;
-	private boolean tailMatchGroupAdded = false;
-	
-	public AntlrDSLMappingEntry() {
-		this(DSLMappingEntry.ANY, DSLMappingEntry.EMPTY_METADATA, null, null);
-	}
+public class AntlrDSLMappingEntry extends AbstractDSLMappingEntry
+    implements
+    DSLMappingEntry {
+    private boolean headMatchGroupAdded = false;
+    private boolean tailMatchGroupAdded = false;
 
-	public AntlrDSLMappingEntry(final Section section, final MetaData metadata,
-			final String key, final String value) {
-		this.section = section;
-		this.metadata = metadata;
-		this.setMappingKey(key);
-		this.setMappingValue(value);
-	}
+    public AntlrDSLMappingEntry() {
+        this( DSLMappingEntry.ANY,
+              DSLMappingEntry.EMPTY_METADATA,
+              null,
+              null );
+    }
 
-	
-	/**
-	 * @param key
-	 *            the key to set
-	 */
-	public void setMappingKey(String key) {
-		//the "key" in this case is already mostly formed into 
-		//a pattern by ANTLR, and just requires a bit of post-processing.
-		if (key != null) {
-			key = key.trim();
-		}
-		this.key = key;
+    public AntlrDSLMappingEntry(final Section section,
+                                final MetaData metadata,
+                                final String key,
+                                final String value) {
+        this.section = section;
+        this.metadata = metadata;
+        this.setMappingKey( key );
+        this.setMappingValue( value );
+    }
 
-		if (key != null) {
-			int substr = 0;
-			// escape '$' to avoid errors
-			//final String escapedKey = key.replaceAll("\\$", "\\\\\\$");
-			// retrieving variables list and creating key pattern
-			final StringBuffer buf = new StringBuffer();
+    /**
+     * @param key
+     *            the key to set
+     */
+    public void setMappingKey(String key) {
+        //the "key" in this case is already mostly formed into 
+        //a pattern by ANTLR, and just requires a bit of post-processing.
+        if ( key != null ) {
+            key = key.trim();
+        }
+        this.key = key;
 
-			if (!key.startsWith("^")) {
-				// making it start with a space char or a line start
-				buf.append("(\\W|^)").append(key);
-				redistributeVariables();
-				headMatchGroupAdded = true;
-			}
+        if ( key != null ) {
+            int substr = 0;
+            // escape '$' to avoid errors
+            //final String escapedKey = key.replaceAll("\\$", "\\\\\\$");
+            // retrieving variables list and creating key pattern
+            final StringBuffer buf = new StringBuffer();
 
+            if ( !key.startsWith( "^" ) ) {
+                // making it start with a space char or a line start
+                buf.append( "(\\W|^)" ).append( key );
+                redistributeVariables();
+                headMatchGroupAdded = true;
+            }
 
-			// if pattern ends with a pure variable whose pattern could create
-			// a greedy match, append a line end to avoid multiple line matching
-			if (buf.toString().endsWith("(.*?)")) {
-				buf.append("$");
-			} else {
-				buf.append("(\\W|$)");
-				tailMatchGroupAdded = true;
-			}
+            // if pattern ends with a pure variable whose pattern could create
+            // a greedy match, append a line end to avoid multiple line matching
+            if ( buf.toString().endsWith( "(.*?)" ) ) {
+                buf.append( "$" );
+            } else {
+                buf.append( "(\\W|$)" );
+                tailMatchGroupAdded = true;
+            }
 
-			// setting the key pattern and making it space insensitive
-			String pat = buf.toString();
-			//first, look to see if it's 
-			if (key.substring(substr).trim().startsWith("-")
-					&& (!key.substring(substr).trim().startsWith("-\\s*"))) {
-				pat = pat.substring(0, pat.indexOf('-') + 1) + "\\s*"
-						+ pat.substring(pat.indexOf('-') + 1).trim();
-			}
-			//may not need to do this at all
-			//pat = pat.replaceAll("\\s+", "\\\\s+");
-			this.keyPattern = Pattern.compile(pat, Pattern.DOTALL
-					| Pattern.MULTILINE);
+            // setting the key pattern and making it space insensitive
+            String pat = buf.toString();
+            //first, look to see if it's 
+            if ( key.substring( substr ).trim().startsWith( "-" ) && (!key.substring( substr ).trim().startsWith( "-\\s*" )) ) {
+                pat = pat.substring( 0,
+                                     pat.indexOf( '-' ) + 1 ) + "\\s*" + pat.substring( pat.indexOf( '-' ) + 1 ).trim();
+            }
+            //may not need to do this at all
+            //pat = pat.replaceAll("\\s+", "\\\\s+");
+            this.keyPattern = Pattern.compile( pat,
+                                               Pattern.DOTALL | Pattern.MULTILINE );
 
-		} else {
-			this.keyPattern = null;
-		}
-		// update value mapping
-		//this.setMappingValue(this.value);
-	}
-	
-	/**
-	 * The keys for this map are integers, starting at 1.  However,
-	 * in certain cases we insert a matching group at the start of the
-	 * pattern, which means that 1 should become 2, 2 become 3, etc.
-	 */
-	private void redistributeVariables(){
-		for (Iterator it = variables.entrySet().iterator(); it.hasNext();) {
-			Map.Entry entry = (Map.Entry) it.next();
-			Integer i = (Integer)entry.getValue();
-			variables.put(entry.getKey(), new Integer(i.intValue() + 1));
-		}
-	}
+        } else {
+            this.keyPattern = null;
+        }
+        // update value mapping
+        //this.setMappingValue(this.value);
+    }
 
-	/**
-	 * @param value
-	 *            the value to set
-	 */
-	public void setMappingValue(final String value) {
-		StringBuffer valuePatternBuffer = new StringBuffer();
-		StringBuffer valueBuffer = new StringBuffer();
-		if(headMatchGroupAdded){
-			valuePatternBuffer.append("$1");
-			valueBuffer.append("$1");
-		}
-		valuePatternBuffer.append(value);
-		valueBuffer.append(value);
-		if(tailMatchGroupAdded){
-			int maxGroupIndex = 0;
-			if(!variables.isEmpty()){
-				Integer tailMatchGroupIndex = (Integer) Collections.max(variables.values());
-				maxGroupIndex = tailMatchGroupIndex.intValue();
-			}else if(headMatchGroupAdded){
-				//if empty, but head group matched, set max group to 1
-				maxGroupIndex++;
-			}
-			maxGroupIndex++;
-			valuePatternBuffer.append("$" + maxGroupIndex);
-			valueBuffer.append("$" + maxGroupIndex);
-		}
-		this.valuePattern = valuePatternBuffer.toString();
-		this.value = valueBuffer.toString();
-		
-	}
+    /**
+     * The keys for this map are integers, starting at 1.  However,
+     * in certain cases we insert a matching group at the start of the
+     * pattern, which means that 1 should become 2, 2 become 3, etc.
+     */
+    private void redistributeVariables() {
+        for ( Iterator it = variables.entrySet().iterator(); it.hasNext(); ) {
+            Map.Entry entry = (Map.Entry) it.next();
+            Integer i = (Integer) entry.getValue();
+            variables.put( entry.getKey(),
+                           new Integer( i.intValue() + 1 ) );
+        }
+    }
+
+    /**
+     * @param value
+     *            the value to set
+     */
+    public void setMappingValue(String value) {
+        if ( value != null ) {
+            StringBuffer valuePatternBuffer = new StringBuffer();
+            StringBuffer valueBuffer = new StringBuffer();
+
+            if ( headMatchGroupAdded ) {
+                valuePatternBuffer.append( "$1" );
+                valueBuffer.append( "$1" );
+            }
+            valuePatternBuffer.append( value );
+            valueBuffer.append( value );
+            if ( tailMatchGroupAdded ) {
+                int maxGroupIndex = 0;
+                if ( !variables.isEmpty() ) {
+                    Integer tailMatchGroupIndex = (Integer) Collections.max( variables.values() );
+                    maxGroupIndex = tailMatchGroupIndex.intValue();
+                } else if ( headMatchGroupAdded ) {
+                    //if empty, but head group matched, set max group to 1
+                    maxGroupIndex++;
+                }
+                maxGroupIndex++;
+                valuePatternBuffer.append( "$" + maxGroupIndex );
+                valueBuffer.append( "$" + maxGroupIndex );
+            }
+            this.valuePattern = valuePatternBuffer.toString();
+            this.value = valueBuffer.toString();
+        }
+
+    }
 }

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMapWalker.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMapWalker.java	2008-06-09 16:46:04 UTC (rev 20383)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMapWalker.java	2008-06-09 18:26:19 UTC (rev 20384)
@@ -751,7 +751,7 @@
                     match(input,VT_LITERAL,FOLLOW_VT_LITERAL_in_value_sentence302); 
                     
                     		//System.out.println("in value_sentence, literal is " + vtl.getText());
-                    		((entry_scope)entry_stack.peek()).valuebuffer.append(vtl.getText());
+                    		((entry_scope)entry_stack.peek()).valuebuffer.append(vtl.getText().replaceAll("\\$", "\\\\\\$"));
                     	
 
                     }

Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/lang/dsl/DSLMapWalker.g
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/lang/dsl/DSLMapWalker.g	2008-06-09 16:46:04 UTC (rev 20383)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/lang/dsl/DSLMapWalker.g	2008-06-09 18:26:19 UTC (rev 20384)
@@ -1,191 +1,193 @@
-tree grammar DSLMapWalker;
-
-options {
-	tokenVocab=DSLMap;
-	ASTLabelType=CommonTree;
-}
-
- at treeparser::header {
-	package org.drools.lang.dsl;
-	
-	import java.util.Map;
-	import java.util.HashMap;
-	
-}
-
-
-mapping_file returns [DSLMapping mapping]
-scope {
-	DSLMapping retval;
-}
- at init {
-	$mapping_file::retval = new DefaultDSLMapping() ;
-}
-	: ^(VT_DSL_GRAMMAR entry*)
-	{
-		//System.out.println("done parsing file");
-		//System.out.println($mapping_file::retval.dumpFile());
-		$mapping = $mapping_file::retval;
-		//java.io.StringWriter sw = new java.io.StringWriter();
-		//$mapping_file::retval.saveMapping(sw);
-		//System.out.println(sw.toString());
-	}
-	;
-	
-mapping_entry 
-	: ent=entry
-	{
-		$mapping_file::retval.addEntry(ent);
-		//System.out.println("mapping size is now " + $mapping_file::retval.getEntries().size());
-	}
-	;
-	
-valid_entry returns [DSLMappingEntry mappingEntry]
-	: ent=entry {$mappingEntry = ent;}
-	| VT_COMMENT {$mappingEntry = null;}
-	;
-
-
-entry returns [DSLMappingEntry mappingEntry]
-scope {
-	Map variables;
-	AntlrDSLMappingEntry retval;
-	int counter;
-	StringBuffer keybuffer;
-	StringBuffer valuebuffer;
-}
- at init {
-	$entry::retval = new AntlrDSLMappingEntry() ;
-	$entry::variables = new HashMap();
-	$entry::keybuffer = new StringBuffer();
-	$entry::valuebuffer = new StringBuffer();
-}
-	: ^(VT_ENTRY scope_section meta_section? key_section {$entry::retval.variables = $entry::variables; $entry::retval.setMappingKey($entry::keybuffer.toString());}
-		value_section)
-	{
-		//System.out.println("for this entry, metadata is " + $entry::retval.getMetaData().getMetaData());
-		//System.out.println("variables are " + $entry::variables);
-		
-		//System.out.println("keybuffer: " + $entry::keybuffer);
-		//System.out.println("valuebuffer: " + $entry::valuebuffer);
-//		$mapping_file::retval.addEntry($entry::retval);
-//		System.out.println("mapping size is now " + $mapping_file::retval.getEntries().size());
-		//$entry::retval.variables = $entry::variables;
-		//$entry::retval.setMappingKey($entry::keybuffer.toString());
-		$entry::retval.setMappingValue($entry::valuebuffer.toString());
-		//System.out.println("keypattern is " + $entry::retval.getKeyPattern());
-		//System.out.println("valuepattern is " + $entry::retval.getValuePattern());
-		$mappingEntry = $entry::retval;
-	}
-	;
-
-
-scope_section 
-	: ^(thescope=VT_SCOPE condition_key? consequence_key? keyword_key? any_key?)
-	;
-
-
-	
-meta_section
-	: ^(VT_META metalit=LITERAL?)
-	{
-		if ( $metalit == null || $metalit.text == null || $metalit.text.length() == 0 ) {
-			$entry::retval.setMetaData(DSLMappingEntry.EMPTY_METADATA);
-		} else {
-        		$entry::retval.setMetaData(new DSLMappingEntry.DefaultDSLEntryMetaData( $metalit.text ));
-	        }
-	}
-	;
-
-key_section
-	: ^(VT_ENTRY_KEY key_sentence+ )
-	{
-		//$entry::retval.setMappingKey($entry::keybuffer.toString());
-	}
-	;
- 
-key_sentence
-	: variable_definition
-	| vtl=VT_LITERAL 
-	{
-		//System.out.println("in key_sentence, literal is " + $vtl.text);
-		$entry::keybuffer.append($vtl.text);
-	}
-	| VT_SPACE
-	{
-		$entry::keybuffer.append("\\s+");
-	}
-	;		
-/*
-key_chunk
-	: literal+
-	;		
-*/	
-value_section
-	: ^(VT_ENTRY_VAL value_sentence+ )
-	{
-		//$entry::retval.setMappingValue($entry::valuebuffer.toString());
-	}
-	;
-	
-value_sentence 	
-	: variable_reference
-	| vtl=VT_LITERAL
-	{
-		//System.out.println("in value_sentence, literal is " + $vtl.text);
-		$entry::valuebuffer.append($vtl.text);
-	}
-	| VT_SPACE
-	{
-		$entry::valuebuffer.append(" ");
-	}
-	;	
-/*	
-value_chunk
-	: (literal|EQUALS)+
-	;	
-*/	
-literal 
-	: theliteral=VT_LITERAL {//System.out.println("theliteral is " + $theliteral.text);}
-	;	
-
-
-variable_definition
-
-	:   ^(VT_VAR_DEF varname=LITERAL pattern=VT_PATTERN? )
-	{
-		//System.out.println("variable " + $varname.text + " defined with pattern " + $pattern);
-		$entry::counter++;
-		$entry::variables.put($varname.text, new Integer($entry::counter));
-		$entry::keybuffer.append($pattern != null? "(" + $pattern.text + ")" : "(.*?)");
-	}
-	;
-
-
-variable_reference 
-	: ^(varref=VT_VAR_REF lit=LITERAL ) 
-	{
-		//System.out.println("varref is " + $varref.text + " and points to " + $lit.text);
-		$entry::valuebuffer.append("$" + $entry::variables.get($lit.text));
-	}
-	;	
-
-condition_key
-	: VT_CONDITION
-	{$entry::retval.setSection(DSLMappingEntry.CONDITION);}
-	;
-
-consequence_key 
-	: VT_CONSEQUENCE
-	{$entry::retval.setSection(DSLMappingEntry.CONSEQUENCE);}
-	;
-
-keyword_key 
-	: VT_KEYWORD
-	{$entry::retval.setSection(DSLMappingEntry.KEYWORD);}
-	;
-
-any_key 
-	: VT_ANY
-	{$entry::retval.setSection(DSLMappingEntry.ANY);}
-	;
+tree grammar DSLMapWalker;
+
+options {
+	tokenVocab=DSLMap;
+	ASTLabelType=CommonTree;
+}
+
+ at treeparser::header {
+	package org.drools.lang.dsl;
+	
+	import java.util.Map;
+	import java.util.HashMap;
+	
+}
+
+
+mapping_file returns [DSLMapping mapping]
+scope {
+	DSLMapping retval;
+}
+ at init {
+	$mapping_file::retval = new DefaultDSLMapping() ;
+}
+	: ^(VT_DSL_GRAMMAR entry*)
+	{
+		//System.out.println("done parsing file");
+		//System.out.println($mapping_file::retval.dumpFile());
+		$mapping = $mapping_file::retval;
+		//java.io.StringWriter sw = new java.io.StringWriter();
+		//$mapping_file::retval.saveMapping(sw);
+		//System.out.println(sw.toString());
+	}
+	;
+	
+mapping_entry 
+	: ent=entry
+	{
+		$mapping_file::retval.addEntry(ent);
+		//System.out.println("mapping size is now " + $mapping_file::retval.getEntries().size());
+	}
+	;
+	
+valid_entry returns [DSLMappingEntry mappingEntry]
+	: ent=entry {$mappingEntry = ent;}
+	| VT_COMMENT {$mappingEntry = null;}
+	;
+
+
+entry returns [DSLMappingEntry mappingEntry]
+scope {
+	Map variables;
+	AntlrDSLMappingEntry retval;
+	int counter;
+	StringBuffer keybuffer;
+	StringBuffer valuebuffer;
+}
+ at init {
+	$entry::retval = new AntlrDSLMappingEntry() ;
+	$entry::variables = new HashMap();
+	$entry::keybuffer = new StringBuffer();
+	$entry::valuebuffer = new StringBuffer();
+}
+	: ^(VT_ENTRY scope_section meta_section? key_section {$entry::retval.variables = $entry::variables; $entry::retval.setMappingKey($entry::keybuffer.toString());}
+		value_section)
+	{
+		//System.out.println("for this entry, metadata is " + $entry::retval.getMetaData().getMetaData());
+		//System.out.println("variables are " + $entry::variables);
+		
+		//System.out.println("keybuffer: " + $entry::keybuffer);
+		//System.out.println("valuebuffer: " + $entry::valuebuffer);
+//		$mapping_file::retval.addEntry($entry::retval);
+//		System.out.println("mapping size is now " + $mapping_file::retval.getEntries().size());
+		//$entry::retval.variables = $entry::variables;
+		//$entry::retval.setMappingKey($entry::keybuffer.toString());
+		$entry::retval.setMappingValue($entry::valuebuffer.toString());
+		//System.out.println("keypattern is " + $entry::retval.getKeyPattern());
+		//System.out.println("valuepattern is " + $entry::retval.getValuePattern());
+		$mappingEntry = $entry::retval;
+	}
+	;
+
+
+scope_section 
+	: ^(thescope=VT_SCOPE condition_key? consequence_key? keyword_key? any_key?)
+	;
+
+
+	
+meta_section
+	: ^(VT_META metalit=LITERAL?)
+	{
+		if ( $metalit == null || $metalit.text == null || $metalit.text.length() == 0 ) {
+			$entry::retval.setMetaData(DSLMappingEntry.EMPTY_METADATA);
+		} else {
+        		$entry::retval.setMetaData(new DSLMappingEntry.DefaultDSLEntryMetaData( $metalit.text ));
+	        }
+	}
+	;
+
+key_section
+	: ^(VT_ENTRY_KEY key_sentence+ )
+	{
+		//$entry::retval.setMappingKey($entry::keybuffer.toString());
+	}
+	;
+ 
+key_sentence
+	: variable_definition
+	| vtl=VT_LITERAL 
+	{
+		//System.out.println("in key_sentence, literal is " + $vtl.text);
+		$entry::keybuffer.append($vtl.text);
+	}
+	| VT_SPACE
+	{
+		$entry::keybuffer.append("\\s+");
+	}
+	;		
+/*
+key_chunk
+	: literal+
+	;		
+*/	
+value_section
+	: ^(VT_ENTRY_VAL value_sentence+ )
+	{
+		//$entry::retval.setMappingValue($entry::valuebuffer.toString());
+	}
+	;
+	
+value_sentence 	
+	: variable_reference
+	| vtl=VT_LITERAL
+	{
+		//System.out.println("in value_sentence, literal is " + $vtl.text);
+		$entry::valuebuffer.append($vtl.text.replaceAll("\\$", "\\\\\\$"));
+	}
+	| VT_SPACE
+	{
+		$entry::valuebuffer.append(" ");
+	}
+	;	
+/*	
+value_chunk
+	: (literal|EQUALS)+
+	;	
+*/	
+literal 
+	: theliteral=VT_LITERAL {//System.out.println("theliteral is " + $theliteral.text);}
+	;	
+
+
+variable_definition
+
+	:   ^(VT_VAR_DEF varname=LITERAL pattern=VT_PATTERN? )
+	{
+		//System.out.println("variable " + $varname.text + " defined with pattern " + $pattern);
+		$entry::counter++;
+		$entry::variables.put($varname.text, new Integer($entry::counter));
+		$entry::keybuffer.append($pattern != null? "(" + $pattern.text + ")" : "(.*?)");
+	}
+	;
+
+
+variable_reference 
+	: ^(varref=VT_VAR_REF lit=LITERAL ) 
+	{
+		//System.out.println("varref is " + $varref.text + " and points to " + $lit.text);
+		$entry::valuebuffer.append("$" + $entry::variables.get($lit.text));
+	}
+	;	
+
+condition_key
+	: VT_CONDITION
+	{$entry::retval.setSection(DSLMappingEntry.CONDITION);}
+	;
+
+consequence_key 
+	: VT_CONSEQUENCE
+	{$entry::retval.setSection(DSLMappingEntry.CONSEQUENCE);}
+	;
+
+keyword_key 
+	: VT_KEYWORD
+	{$entry::retval.setSection(DSLMappingEntry.KEYWORD);}
+	;
+
+any_key 
+	: VT_ANY
+	{$entry::retval.setSection(DSLMappingEntry.ANY);}
+	;
+	
+	




More information about the jboss-svn-commits mailing list