commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wer...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression CompositeExpression.java
Date Sun, 07 Jul 2002 19:38:12 GMT
werken      2002/07/07 12:38:11

  Modified:    jelly    maven.xml project.xml
               jelly/src/java/org/apache/commons/jelly/expression
                        CompositeExpression.java
  Log:
  Improved the lexing on strings to allow for $${foo} literals to be
  passed (double that dollar!), and for things like ${ a.b("}") }
  to no longer trick jelly into finding the end of the expression
  too early.
  
  Mmmm... lexers.
  
  Plus, modified slightly to support the maven-ng moving target.
  
  Revision  Changes    Path
  1.5       +3 -3      jakarta-commons-sandbox/jelly/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/maven.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- maven.xml	5 Jul 2002 18:47:25 -0000	1.4
  +++ maven.xml	7 Jul 2002 19:38:11 -0000	1.5
  @@ -1,7 +1,7 @@
  -<project default="maven:jar" xmlns:j="jelly:core">
  +<project default="java:jar" xmlns:j="jelly:core">
   
     <!-- runs the XML doclet -->	
  -  <goal name="xml-doclet" prereqs="maven:compile">
  +  <goal name="xml-doclet" prereqs="java:compile">
       <path id="doclet.classpath">
   		<pathelement path="${maven.build.dest}"/>
   		<path refid="maven.dependency.classpath"/>
  @@ -16,7 +16,7 @@
     </goal>
   
     <!-- runs the Tag doclet -->	
  -  <goal name="tag-doclet" prereqs="maven:compile">
  +  <goal name="tag-doclet" prereqs="java:compile">
       <path id="doclet.classpath">
         <pathelement path="target/classes"/>
         <pathelement path="${maven.build.dest}"/>
  
  
  
  1.34      +1 -1      jakarta-commons-sandbox/jelly/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/project.xml,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- project.xml	5 Jul 2002 13:29:12 -0000	1.33
  +++ project.xml	7 Jul 2002 19:38:11 -0000	1.34
  @@ -4,7 +4,7 @@
     <pomVersion>3</pomVersion>
     <name>commons-jelly</name>
     <id>commons-jelly</id>
  -  <currentVersion>1.0-dev</currentVersion>
  +  <currentVersion>1.0-dev-5</currentVersion>
     <organization>
       <name>Apache Software Foundation</name>
       <url>http://www.apache.org</url>
  
  
  
  1.2       +169 -28   jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/CompositeExpression.java
  
  Index: CompositeExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/CompositeExpression.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CompositeExpression.java	6 Jun 2002 07:13:41 -0000	1.1
  +++ CompositeExpression.java	7 Jul 2002 19:38:11 -0000	1.2
  @@ -110,48 +110,189 @@
        *  from the ExpressionFactory
        */
       public static Expression parse(String text, ExpressionFactory factory) throws Exception
{
  -        int length = text.length();
  +
  +        int len = text.length();
  +
           int startIndex = text.indexOf( "${" );
  -        if (startIndex < 0 ) {
  +
  +        if ( startIndex < 0) {
               return new ConstantExpression(text);
           }
  +
           int endIndex = text.indexOf( "}", startIndex+2 );
  +
           if ( endIndex < 0 ) {
               throw new JellyException( "Missing '}' character at the end of expression:
" + text );
           }
  -        if ( startIndex == 0 && endIndex == length - 1 ) {
  +        if ( startIndex == 0 && endIndex == len - 1 ) {
               return factory.createExpression(text.substring(2, endIndex));
           }
  -        else {
  -            CompositeExpression answer = new CompositeExpression();
  -            if ( startIndex > 0 ) {
  -                String prefix = text.substring(0, startIndex);
  -                answer.addTextExpression(prefix);
  -            }
  -            String middle = text.substring(startIndex+2, endIndex);
  -            answer.addExpression(factory.createExpression(middle));
  -            
  -            // now lets iterate through the rest of the string.                    
  -            while (++endIndex < length) {
  -                startIndex = text.indexOf( "${", endIndex );
  -                if ( startIndex < 0 ) {
  -                    String postfix = text.substring(endIndex);
  -                    answer.addTextExpression(postfix);
  +
  +        CompositeExpression answer = new CompositeExpression();
  +
  +        int cur = 0;
  +        char c = 0;
  +
  +        StringBuffer chars = new StringBuffer();
  +        StringBuffer expr  = new StringBuffer();
  +
  +      MAIN:
  +        while ( cur < len )
  +        {
  +            c = text.charAt( cur );
  +
  +            switch ( c )
  +            {
  +                case('$'):
  +                {
  +                    if ( cur+1<len )
  +                    {
  +                        ++cur;
  +                        c = text.charAt( cur );
  +
  +                        switch ( c )
  +                        {
  +                            case('$'):
  +                            {
  +                                chars.append( c );
  +                                break;
  +                            }
  +                            case('{'):
  +                            {
  +                                if ( chars.length() > 0 )
  +                                {
  +                                    answer.addTextExpression( chars.toString() );
  +                                    chars.delete(0, chars.length() );
  +                                }
  +
  +                                if (cur+1<len)
  +                                {
  +                                    ++cur;
  +
  +                                    while (cur<len)
  +                                    {
  +                                        c = text.charAt(cur);
  +                                        {
  +                                            switch ( c )
  +                                            {
  +                                                case('"'):
  +                                                {
  +                                                    expr.append( c );
  +                                                    ++cur;
  +
  +                                                  DOUBLE_QUOTE:
  +                                                    while(cur<len)
  +                                                    {
  +                                                        c = text.charAt(cur);
  +
  +                                                        boolean escape = false;
  +
  +                                                        switch ( c )
  +                                                        {
  +                                                            case('\\'):
  +                                                            {
  +                                                                escape = true;
  +                                                                ++cur;
  +                                                                expr.append(c);
  +                                                                break;
  +                                                            }
  +                                                            case('"'):
  +                                                            {
  +                                                                ++cur;
  +                                                                expr.append(c);
  +                                                                break DOUBLE_QUOTE;
  +                                                            }
  +                                                            default:
  +                                                            {
  +                                                                escape=false;
  +                                                                ++cur;
  +                                                                expr.append(c);
  +                                                            }
  +                                                        }
  +                                                    }
  +                                                    break;
  +                                                }
  +                                                case('\''):
  +                                                {
  +                                                    expr.append( c );
  +                                                    ++cur;
  +
  +                                                  SINGLE_QUOTE:
  +                                                    while(cur<len)
  +                                                    {
  +                                                        c = text.charAt(cur);
  +
  +                                                        boolean escape = false;
  +
  +                                                        switch ( c )
  +                                                        {
  +                                                            case('\\'):
  +                                                            {
  +                                                                escape = true;
  +                                                                ++cur;
  +                                                                expr.append(c);
  +                                                                break;
  +                                                            }
  +                                                            case('\''):
  +                                                            {
  +                                                                ++cur;
  +                                                                expr.append(c);
  +                                                                break SINGLE_QUOTE;
  +                                                            }
  +                                                            default:
  +                                                            {
  +                                                                escape=false;
  +                                                                ++cur;
  +                                                                expr.append(c);
  +                                                            }
  +                                                        }
  +                                                    }
  +                                                    break;
  +                                                }
  +                                                case('}'):
  +                                                {
  +                                                    answer.addExpression(factory.createExpression(expr.toString()));
  +                                                    expr.delete(0, expr.length());
  +                                                    ++cur;
  +                                                    continue MAIN;
  +                                                }
  +                                                default:
  +                                                {
  +                                                    expr.append( c );
  +                                                    ++cur;
  +                                                }
  +                                            }
  +                                        }
  +                                    }
  +                                }
  +                                break;
  +                            }
  +                            default:
  +                            {
  +                                chars.append(c);
  +                            }
  +                        }
  +                    }
  +                    else
  +                    {
  +                        chars.append(c);
  +                    }
                       break;
                   }
  -                // add text in between expresssions
  -                if (startIndex > endIndex ) {
  -                    answer.addTextExpression(text.substring(endIndex, startIndex));
  -                }
  -                endIndex = text.indexOf( "}", startIndex+2 );
  -                if ( endIndex < 0 ) {
  -                    throw new JellyException( "Missing '}' character at the end of expression:
" + text );
  +                default:
  +                {
  +                    chars.append( c );
                   }
  -                middle = text.substring(startIndex+2, endIndex);
  -                answer.addExpression(factory.createExpression(middle));
               }
  -            return answer;
  +            ++cur;
  +        }
  +
  +        if ( chars.length() > 0 )
  +        {
  +            answer.addTextExpression( chars.toString() );
           }
  +
  +        return answer;
       }
   
       // Properties
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message