[jboss-svn-commits] JBL Code SVN: r15986 - labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 22 13:18:24 EDT 2007
Author: tirelli
Date: 2007-10-22 13:18:23 -0400 (Mon, 22 Oct 2007)
New Revision: 15986
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java
Log:
JBRULES-1295: applying patch
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java 2007-10-22 16:42:49 UTC (rev 15985)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/lang/dsl/DSLMappingFile.java 2007-10-22 17:18:23 UTC (rev 15986)
@@ -91,41 +91,68 @@
final BufferedReader dslFileReader = new BufferedReader( dsl );
this.mapping = new DefaultDSLMapping();
this.errors = new LinkedList();
+ //Note: Use a string builder for 1.5 targets
+ StringBuffer sb = new StringBuffer();
+ boolean spacesAllowed = true;
while ( (line = dslFileReader.readLine()) != null ) {
linecounter++;
- final Matcher mat = pattern.matcher( line );
+ String trimmedline = line.trim(); //this can be more efficient, get rid of trim(), iterate-- over last chars only.
+ if ( spacesAllowed ) { //prevents that the break of some line be mixed with comments or empty lines
+ if ( trimmedline.length() == 0 ) {
+ // empty line in DSL: [\t ]*\n
+ continue;
+ }
+ if ( trimmedline.startsWith( "#" ) ) {
+ // comment line in DSL: # bla bla \n
+ continue;
+ }
+ }
+ //else, add the chars in the buffer, we'll see about that in a sec
+ sb.append( trimmedline );
+ if ( sb.charAt( sb.length() - 1 ) == '\\' ) {
+ sb.append( ' ' ); //put a space, don't be ridiculous
+ spacesAllowed = false;
+ continue;
+ }
+ //reinit the buffer, no matter what, but keep the accumulated chars
+ String lineToParse = sb.toString();
+ spacesAllowed = true;
+ sb = new StringBuffer();
+ final Matcher mat = pattern.matcher( lineToParse );
+ // - END -
if ( mat.matches() ) {
final String sectionStr = mat.group( 2 );
final String metadataStr = mat.group( 4 );
- final String key = mat.group( 5 ).replaceAll( "\\\\=", "=" );
+ final String key = mat.group( 5 ).replaceAll( "\\\\=",
+ "=" );
final String value = mat.group( 7 );
DSLMappingEntry.Section section = DSLMappingEntry.ANY;
if ( KEYWORD.equals( sectionStr ) ) {
section = DSLMappingEntry.KEYWORD;
- } else if ( CONDITION.equals( sectionStr ) || WHEN.equals( sectionStr )) {
+ } else if ( CONDITION.equals( sectionStr ) || WHEN.equals( sectionStr ) ) {
section = DSLMappingEntry.CONDITION;
- } else if ( CONSEQUENCE.equals( sectionStr ) || THEN.equals( sectionStr )) {
+ } else if ( CONSEQUENCE.equals( sectionStr ) || THEN.equals( sectionStr ) ) {
section = DSLMappingEntry.CONSEQUENCE;
}
DSLMappingEntry.MetaData metadata;
- if( metadataStr == null || metadataStr.length() == 0 ) {
+ if ( metadataStr == null || metadataStr.length() == 0 ) {
metadata = DSLMappingEntry.EMPTY_METADATA;
} else {
metadata = new DefaultDSLEntryMetaData( metadataStr );
}
final DSLMappingEntry entry = new DefaultDSLMappingEntry( section,
- metadata,
- key,
- value );
+ metadata,
+ key,
+ value );
this.mapping.addEntry( entry );
- } else if ( !line.trim().startsWith( "#" ) ) { // it is not a comment
+ } else { // it is for sure an error !
final String error = "Error parsing mapping entry: " + line;
final DSLMappingParseException exception = new DSLMappingParseException( error,
- linecounter );
+ linecounter );
this.errors.add( exception );
}
}
More information about the jboss-svn-commits
mailing list