Ignore:
Timestamp:
11/05/10 16:46:19 (14 years ago)
Author:
zeiss
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfHtmlFormatterVisitor.java

    r40 r41  
    88import org.eclipse.emf.ecore.EObject; 
    99import org.eclipse.xtext.parsetree.LeafNode; 
     10import org.eclipse.xtext.parsetree.NodeUtil; 
    1011 
    1112import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf; 
     13import de.ugoe.cs.swe.bnftools.ebnf.Import; 
    1214import de.ugoe.cs.swe.bnftools.ebnf.Rule; 
    1315import de.ugoe.cs.swe.bnftools.ebnf.RuleReference; 
     
    2022        private ArrayList<MetaTextEntry> transformedTexts = new ArrayList<MetaTextEntry>(); 
    2123        private int lastMetaTextBlock = 0; 
     24        private boolean isParagraphOpen = false; 
    2225         
    2326        public EbnfHtmlFormatterVisitor(EObject rootNode, FormatterConfig config) { 
     
    111114                                } 
    112115                        } else { 
    113                                 if (lastMetaTextBlock == 0 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) { 
     116                                while (lastMetaTextBlock == 0 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces >= currentMetaText.getOffset())) { 
    114117                                        result.append(currentMetaText.getText()); 
    115118                                        metaTexts.remove(currentMetaText); 
     
    118121                                        else 
    119122                                                currentMetaText = null; 
    120                                         lastMetaTextBlock = 1; 
     123                                         
     124                                        if ((currentMetaText == null) && (bufferPositionFormattedTextNoWhitespaces != currentMetaText.getOffset())) 
     125                                                lastMetaTextBlock = 1; 
    121126                                } 
    122127 
     
    139144                                } 
    140145 
    141                                 if (lastMetaTextBlock == 1 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) { 
     146                                while ( lastMetaTextBlock == 1 && currentMetaText != null && bufferPositionFormattedTextNoWhitespaces >= currentMetaText.getOffset()) { 
    142147                                        result.append(currentMetaText.getText()); 
    143148                                        metaTexts.remove(currentMetaText); 
    144                                         if (metaTexts.iterator().hasNext()) 
     149                                        if (metaTexts.iterator().hasNext()) { 
    145150                                                currentMetaText = metaTexts.iterator().next(); 
    146                                         else 
     151                                        } else { 
    147152                                                currentMetaText = null; 
    148                                         lastMetaTextBlock = 0; 
     153                                        } 
     154                                         
     155                                        if ((currentMetaText == null) || (bufferPositionFormattedTextNoWhitespaces != currentMetaText.getOffset())) 
     156                                                lastMetaTextBlock = 0; 
    149157                                } 
    150158                        } 
    151159                } 
     160                while ( bufferPositionFormattedTextNoWhitespaces >= formattedTextNoWhitespaces.length()-1 && currentMetaText != null) { 
     161                        result.append(currentMetaText.getText()); 
     162                        metaTexts.remove(currentMetaText); 
     163                        if (metaTexts.iterator().hasNext()) { 
     164                                currentMetaText = metaTexts.iterator().next(); 
     165                        } else { 
     166                                currentMetaText = null; 
     167                        } 
     168                } 
     169 
     170                 
    152171                buf = result; 
    153172        } 
     
    164183                newLineOffsetCounter += original.length(); 
    165184        } 
    166  
     185         
     186        protected void newLine() { 
     187                buf.append("\n"); 
     188                if (!isParagraphOpen) { 
     189                        metaText("\n<p class=PL style='mso-pagination:widow-orphan lines-together;page-break-after: avoid'>\n"); 
     190                        isParagraphOpen = true; 
     191                } else { 
     192                        metaText("\n</p>\n"); 
     193                        isParagraphOpen = false; 
     194                } 
     195                 
     196                if ((ruleSpacingStack != null) && (!ruleSpacingStack.empty())) { 
     197                        newLineOffsetCounter = ruleSpacingStack.peek(); 
     198                } else { 
     199                        newLineOffsetCounter = 0; 
     200                } 
     201        } 
     202         
    167203        // ----------------------------------------------------------------------------- 
    168204         
     205        protected void visitBefore(EtsiBnf node) { 
     206                parserEtsiBnfNode = NodeUtil.getNodeAdapter(node).getParserNode(); 
     207                collectAllComments(parserEtsiBnfNode); 
     208                originalText = NodeUtil.getNodeAdapter(node).getParserNode().serialize(); 
     209                originalTextNoWhitespaces = originalText.replaceAll("[ \t\n\r]", ""); 
     210                 
     211                textTransformed("grammar " + node.getName(),""); 
     212                if (node.getType() != null) 
     213                        textTransformed(node.getType(),""); 
     214                textTransformed(";",""); 
     215                metaText("<body lang=EN-US link=blue vlink=purple style='tab-interval:14.15pt'>\n"); 
     216                metaText("<div class=WordSection1>\n"); 
     217                 
     218//              newLine(); 
     219//              newLine(); 
     220        } 
     221         
    169222        protected void visitAfter(EtsiBnf node) { 
     223                metaText("</div>\n"); 
     224                metaText("</body>\n"); 
     225                metaText("</html>\n"); 
    170226                weaveComments(); 
    171227        } 
    172228 
     229        protected void visitBefore(Import node) { 
     230                textTransformed("import \"" + node.getImportURI() + "\"",""); 
     231                if (node.getGrammarType() != null) { 
     232                        textTransformed("/" + node.getGrammarType(), ""); 
     233                } 
     234                if (node.getLabel() != null) { 
     235                        space(); 
     236                        textTransformed("label: " + node.getLabel(), ""); 
     237                } 
     238                textTransformed(";", ""); 
     239//              text("\n"); 
     240        } 
     241         
    173242        protected void visitBefore(SectionHeading node) { 
    174243                if (!lastWasSectionHeading && !buf.substring(buf.length()-2).equals("\n\n")) 
     
    177246                lastWasSectionHeading=true; 
    178247                 
    179                 metaText("<h1>"); 
    180                 text(node.getSectionHeader().replaceAll("[\n\r]", "")); 
    181                 metaText("</h1>"); 
     248                metaText("<h3><span lang=EN-GB>\n"); 
     249                String text = node.getSectionHeader().replaceAll("[\n\r]", ""); 
     250                textTransformed(text, StringEscapeUtils.escapeHtml(text).replaceAll("[\n\r]", "")); 
     251//              textTransformed(text, text.replaceAll("[\t]", "\\<span style='mso-tab-count:1'\\>")); 
     252                metaText("\n</span></h3>\n"); 
    182253        } 
    183254 
     
    188259                wrap(); 
    189260                 
    190                 metaText("<a href=\"#" + node.getRuleref().getName() + "\">"); 
     261                metaText("<u><span style='color:blue'><a href=\"#T" + node.getRuleref().getName() + "\">"); 
    191262                text(node.getRuleref().getName()); 
    192                 metaText("</a>"); 
     263                metaText("</a></span></u>"); 
    193264        } 
    194265 
     
    197268 
    198269        protected void visitBefore(Rule node) { 
    199                 if (lastWasSectionHeading) 
     270//              if (lastWasSectionHeading) 
    200271                        newLine(); 
    201272                 
     
    206277                if (node.getRulenumber() > 0) 
    207278                        text(node.getRulenumber() + ". "); 
    208                  
    209                 metaText("<a name=\"#" + node.getName() + "\">"); 
    210                 text(node.getName()); 
     279 
     280                metaText("<span lang=EN-GB style='mso-no-proof:no'>\n<a name=\"#T" + node.getName() + "\">"); 
     281                textTransformed(node.getName(), node.getName().replaceAll("[ \t\r\n]", "")); 
    211282                metaText("</a>"); 
    212283                text(" ::= "); 
     
    217288         
    218289        protected void visitAfter(Rule node) { 
    219                 metaText("<br/>"); 
     290                metaText("<o:p></o:p>\n</span>"); 
    220291                text(";"); 
    221292                newLine(); 
     293                text("\n"); 
    222294                ruleSpacingStack.pop(); 
    223295        } 
     
    227299                if (node.getLiteral() != null) { 
    228300//                      text("\"" + node.getLiteral() + "\""); 
    229                         textTransformed("\"" + node.getLiteral() + "\"", StringEscapeUtils.escapeHtml("\"" + node.getLiteral() + "\"")); 
     301                        textTransformed("\"" + node.getLiteral() + "\"", StringEscapeUtils.escapeHtml("\"" + node.getLiteral() + "\"").replaceAll("[ \t\n\r]", "")); 
    230302//                      textTransformed("\"" + node.getLiteral() + "\"", "gnabar"); 
    231303                } else if (node.getColon() != null) { 
    232304//                      text("\"\"\""); 
    233                         textTransformed("\"\"\"", StringEscapeUtils.escapeHtml("\"\"\"")); 
     305                        textTransformed("\"\"\"", StringEscapeUtils.escapeHtml("\"\"\"").replaceAll("[ \t\n\r]", "")); 
    234306//                      textTransformed("\"\"\"", "gnabar"); 
    235307                } 
Note: See TracChangeset for help on using the changeset viewer.