Changeset 39 in default for trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src
- Timestamp:
- 11/04/10 17:43:06 (14 years ago)
- Location:
- trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfHtmlFormatterVisitor.java
r38 r39 4 4 import java.util.Iterator; 5 5 6 import org.apache.commons.lang.StringEscapeUtils; 7 import org.apache.commons.lang.StringUtils; 6 8 import org.eclipse.emf.ecore.EObject; 7 9 import org.eclipse.xtext.parsetree.LeafNode; … … 11 13 import de.ugoe.cs.swe.bnftools.ebnf.RuleReference; 12 14 import de.ugoe.cs.swe.bnftools.ebnf.SectionHeading; 15 import de.ugoe.cs.swe.bnftools.ebnf.StringRule; 13 16 14 17 public class EbnfHtmlFormatterVisitor extends EbnfFormatterVisitor { 15 18 16 19 private ArrayList<MetaTextEntry> metaTexts = new ArrayList<MetaTextEntry>(); 20 private ArrayList<MetaTextEntry> transformedTexts = new ArrayList<MetaTextEntry>(); 17 21 18 22 public EbnfHtmlFormatterVisitor(EObject rootNode, FormatterConfig config) { … … 35 39 currentMetaText = metaTexts.iterator().next(); 36 40 41 MetaTextEntry currentTransformedText = null; 42 if (transformedTexts.iterator().hasNext()) 43 currentTransformedText = transformedTexts.iterator().next(); 44 37 45 while (bufferPositionFormattedTextNoWhitespaces <= formattedTextNoWhitespaces.length()) { 38 46 skipWhitespacesOriginalText(); … … 51 59 52 60 if (formattedPositionNoWhitespaces != originalPosition) { 61 // if ((currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) { 62 // result.append(currentMetaText.getText()); 63 // metaTexts.remove(currentMetaText); 64 // if (metaTexts.iterator().hasNext()) 65 // currentMetaText = metaTexts.iterator().next(); 66 // else 67 // currentMetaText = null; 68 // } 69 53 70 if (formattedPositionNoWhitespaces == ';') { // formatted text always outputs the optional semicolon, skip it if necessary 54 71 bufferPositionFormattedTextNoWhitespaces++; … … 93 110 } 94 111 } else { 95 if ((currentMetaText != null) && (bufferPositionFormattedText >= currentMetaText.getOffset())) {112 if ((currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) { 96 113 result.append(currentMetaText.getText()); 97 114 metaTexts.remove(currentMetaText); … … 101 118 currentMetaText = null; 102 119 } 103 104 result.append(formattedText.substring(bufferPositionFormattedText, bufferPositionFormattedText+1)); 105 bufferPositionOriginalText++; 106 bufferPositionFormattedText++; 107 bufferPositionFormattedTextNoWhitespaces++; 108 109 if ((currentMetaText != null) && (bufferPositionFormattedText >= currentMetaText.getOffset())) { 110 result.append(currentMetaText.getText()); 111 metaTexts.remove(currentMetaText); 112 if (metaTexts.iterator().hasNext()) 113 currentMetaText = metaTexts.iterator().next(); 114 else 115 currentMetaText = null; 120 121 if (currentTransformedText != null && currentTransformedText.getOffset() == bufferPositionFormattedTextNoWhitespaces) { 122 result.append(currentTransformedText.getTransformedText()); 123 bufferPositionOriginalText += currentTransformedText.getText().length(); 124 bufferPositionFormattedText += currentTransformedText.getText().length(); 125 bufferPositionFormattedTextNoWhitespaces += currentTransformedText.getText().replaceAll("[ \t\r\n]", "").length(); 126 transformedTexts.remove(currentTransformedText); 127 currentTransformedText = null; 128 129 if (transformedTexts.iterator().hasNext()) 130 currentTransformedText = transformedTexts.iterator().next(); 131 } else { 132 String text = formattedText.substring(bufferPositionFormattedText, bufferPositionFormattedText+1); 133 result.append(text); 134 bufferPositionOriginalText++; 135 bufferPositionFormattedText++; 136 bufferPositionFormattedTextNoWhitespaces++; 116 137 } 138 139 // if ((currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) { 140 // result.append(currentMetaText.getText()); 141 // metaTexts.remove(currentMetaText); 142 // if (metaTexts.iterator().hasNext()) 143 // currentMetaText = metaTexts.iterator().next(); 144 // else 145 // currentMetaText = null; 146 // } 147 148 // } 117 149 } 118 150 } … … 121 153 122 154 protected void metaText(String str) { 123 MetaTextEntry metaTextEntry = new MetaTextEntry(str, buf. length());155 MetaTextEntry metaTextEntry = new MetaTextEntry(str, buf.toString().replaceAll("[ \t\n\r]", "").length()); 124 156 metaTexts.add(metaTextEntry); 157 } 158 159 protected void textTransformed(String original, String transformed) { 160 MetaTextEntry metaText = new MetaTextEntry(original, transformed, buf.toString().replaceAll("[ \t\n\r]", "").length()); 161 transformedTexts.add(metaText); 162 buf.append(original); 163 newLineOffsetCounter += original.length(); 125 164 } 126 165 … … 182 221 ruleSpacingStack.pop(); 183 222 } 223 224 protected void visitBefore(StringRule node) { 225 wrap(); 226 if (node.getLiteral() != null) { 227 // text("\"" + node.getLiteral() + "\""); 228 textTransformed("\"" + node.getLiteral() + "\"", StringEscapeUtils.escapeHtml("\"" + node.getLiteral() + "\"")); 229 // textTransformed("\"" + node.getLiteral() + "\"", "gnabar"); 230 } else if (node.getColon() != null) { 231 // text("\"\"\""); 232 textTransformed("\"\"\"", StringEscapeUtils.escapeHtml("\"\"\"")); 233 // textTransformed("\"\"\"", "gnabar"); 234 } 235 } 236 237 protected void visitAfter(StringRule node) { 238 } 184 239 } -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/MetaTextEntry.java
r37 r39 3 3 public class MetaTextEntry { 4 4 private String text; 5 private String transformedText = null; 5 6 private int offset; 6 7 7 8 public MetaTextEntry(String text, int offset) { 8 9 this.text = text; 10 this.offset = offset; 11 } 12 13 public MetaTextEntry(String text, String transformedText, int offset) { 14 this.text = text; 15 this.transformedText = transformedText; 9 16 this.offset = offset; 10 17 } … … 31 38 } 32 39 40 public String getTransformedText() { 41 return transformedText; 42 } 43 44 public void setTransformedText(String transformedText) { 45 this.transformedText = transformedText; 46 } 47 33 48 }
Note: See TracChangeset
for help on using the changeset viewer.