[jboss-cvs] jboss-seam ...

Gavin King gavin.king at jboss.com
Wed Jan 10 01:59:22 EST 2007


  User: gavin   
  Date: 07/01/10 01:59:22

  Modified:    jboss-seam  seam-text.g
  Log:
  better ws handling
  
  Revision  Changes    Path
  1.5       +46 -28    jboss-seam/seam-text.g
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: seam-text.g
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/seam-text.g,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- seam-text.g	10 Jan 2007 03:37:37 -0000	1.4
  +++ seam-text.g	10 Jan 2007 06:59:22 -0000	1.5
  @@ -9,6 +9,7 @@
   	k=2;
   }
   {   
  +    private int newLinesSinceWord = 0;
       private StringBuilder builder = new StringBuilder();
       
       public String toString() {
  @@ -18,6 +19,10 @@
       public void append(String... strings) {
           for (String string: strings) builder.append(string);
       }   
  +    
  +    private static boolean hasMultiple(String string, char c) {
  +        return string.indexOf(c)!=string.lastIndexOf(c);
  +    }
   }
   
   startRule: { append("<p>\n"); }
  @@ -25,19 +30,20 @@
              { append("\n</p>\n"); }
       ;
   
  -text: (word|punctuation|formatting|escape|ws|para|span)*
  +text: (word|punctuation|formatting|escape|space|para|span|list)*
       ;
       
   formatting: bold|underline|italic|monospace|superscript|deleted|preformatted|quoted
       ;
   
  -word: w:WORD { append( w.getText() ); }
  +word: w:WORD { append( w.getText() ); newLinesSinceWord=0; }
       ;
       
  -punctuation: p:PUNCTUATION { append( p.getText() ); }
  +punctuation: p:PUNCTUATION { append( p.getText() ); newLinesSinceWord=0; }
       ;
       
  -escape: ESCAPE ( q:QUOTE { append( q.getText() ); } | specialChars | htmlSpecialChars )
  +escape: ESCAPE { newLinesSinceWord=0; } 
  +        ( q:QUOTE { append( q.getText() ); } | specialChars | htmlSpecialChars )
       ;
       
   specialChars:
  @@ -48,9 +54,9 @@
           | m:MINUS { append( m.getText() ); } 
           | p:PLUS { append( p.getText() ); } 
           | eq:EQ { append( eq.getText() ); }
  +        | hh:HASH { append( hh.getText() ); }
           | e:ESCAPE { append( e.getText() ); }
           | u:UNDERSCORE { append( u.getText() ); }
  -        | n:NEWLINE { append( n.getText() ); }
       ;
   
   htmlSpecialChars: 
  @@ -61,55 +67,68 @@
       ;
       
   bold: STAR { append("<b>"); }
  -      (word|punctuation|escape|underline|italic|monospace|superscript|deleted|ws)*
  +      (word|punctuation|escape|underline|italic|monospace|superscript|deleted|space|newline)*
         STAR { append("</b>"); }
       ;
       
   underline: UNDERSCORE { append("<u>"); }
  -           (word|punctuation|escape|bold|italic|monospace|superscript|deleted|ws)*
  +           (word|punctuation|escape|bold|italic|monospace|superscript|deleted|space|newline)*
              UNDERSCORE { append("</u>"); }
       ;
       
   italic: SLASH { append("<i>"); }
  -        (word|punctuation|escape|bold|underline|monospace|superscript|deleted|ws)*
  +        (word|punctuation|escape|bold|underline|monospace|superscript|deleted|space|newline)*
           SLASH { append("</i>"); }
       ;
       
   monospace: BAR { append("<tt>"); }
  -           (word|punctuation|escape|bold|underline|italic|superscript|deleted|ws)*
  +           (word|punctuation|escape|bold|underline|italic|superscript|deleted|space|newline)*
              BAR { append("</tt>"); }
       ;
       
   superscript: HAT { append("<sup>"); }
  -             (word|punctuation|escape|bold|underline|italic|monospace|deleted|ws)*
  +             (word|punctuation|escape|bold|underline|italic|monospace|deleted|space|newline)*
                HAT { append("</sup>"); }
       ;
       
   deleted: MINUS { append("<del>"); }
  -         (word|punctuation|escape|bold|underline|italic|monospace|superscript|ws)*
  +         (word|punctuation|escape|bold|underline|italic|monospace|superscript|space|newline)*
            MINUS { append("</del>"); }
       ;
       
   preformatted: QUOTE { append("<pre>"); }
  -              (word|punctuation|specialChars|htmlSpecialChars|ws)*
  +              (word|punctuation|specialChars|htmlSpecialChars|space|newline)*
                 QUOTE { append("</pre>"); }
       ;
       
  -quoted: DOUBLEQUOTE { append("<quote>"); }
  -        (word|punctuation|escape|bold|underline|italic|monospace|superscript|deleted|preformatted|ws|para|span)*
  -        DOUBLEQUOTE { append("</quote>"); }
  +quoted: DOUBLEQUOTE { append("<quote><p>"); newLinesSinceWord=0; }
  +        (word|punctuation|escape|bold|underline|italic|monospace|superscript|deleted|preformatted|space|para|span)*
  +        DOUBLEQUOTE { append("</p></quote>"); newLinesSinceWord=0; }
  +    ;
  +    
  +list: para { append("<ol>\n"); } (listItem)+ { append("</ol>\n"); }
  +    ;
  +    
  +listItem: HASH { append("<li>"); newLinesSinceWord=0; }
  +      (word|punctuation|escape|bold|underline|italic|monospace|superscript|deleted|space)*
  +      { append("</li>"); } 
  +      para
  +    ;
  +    
  +space: s:SPACE { append( s.getText() ); }
       ;
       
  -ws: w:WS { append( w.getText() ); }
  +newline: n:NEWLINE { append( n.getText() ); }
       ;
           
  -para: n:NEWLINE { append( n.getText() ); } 
  -      NEWLINE { append("</p>\n<p>\n"); }
  +para: { if (newLinesSinceWord>0) append("</p>\n"); } 
  +      newline 
  +      { if (newLinesSinceWord>0) append("<p>\n"); newLinesSinceWord++; } 
       ;
   
   span: LT tag:WORD { append("<" + tag.getText()); } 
             (
  -              ws att:WORD EQ 
  +              space att:WORD EQ 
                 DOUBLEQUOTE { append(att.getText() + "=\""); } 
                 attributeValue 
                 DOUBLEQUOTE { append("\""); } 
  @@ -117,7 +136,7 @@
         (
             (
                 GT { append(">"); } 
  -              text 
  +              { newLinesSinceWord=0; } text { newLinesSinceWord=0; }
                 LT SLASH WORD GT { append("</" + tag.getText() + ">"); }
             )
         |   (
  @@ -126,7 +145,7 @@
         )
       ;
       
  -attributeValue: ( AMPERSAND { append("&amp;"); } | word | punctuation | ws | specialChars )*
  +attributeValue: ( AMPERSAND { append("&amp;"); } | word | punctuation | space | specialChars )*
       ;
   
   class L extends Lexer;
  @@ -186,10 +205,9 @@
   AMPERSAND: '&'
       ;
       
  -WS: (' '|'\t')+
  +SPACE: (' '|'\t')+
       ;
   
  -NEWLINE: '\r' '\n'   // DOS
  -    |    '\n'        // UNIX
  -    |    '\r'        // Mac
  +NEWLINE: '\r' '\n' | '\r' | '\n'
       ;
  +    
  \ No newline at end of file
  
  
  



More information about the jboss-cvs-commits mailing list