Index: trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfFormatterVisitor.java
===================================================================
--- trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfFormatterVisitor.java	(revision 23)
+++ trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfFormatterVisitor.java	(revision 24)
@@ -154,4 +154,24 @@
 	}
 	
+	private int scanBackNewlinesCount(String str, int position) {
+		int newLinesCount = 0;
+		int currentPosition = position;
+		while ((str.charAt(currentPosition) == '\n') || (str.charAt(currentPosition) == '\r')) {
+			if (str.charAt(currentPosition) == '\n') {
+				if (str.charAt(currentPosition - 1) == '\r') {
+					currentPosition -= 2;
+				} else {
+					currentPosition -= 1;
+				}
+				newLinesCount++;
+			} else if (str.charAt(currentPosition) == '\r') {
+				currentPosition -= 1;
+				newLinesCount++;
+			}
+		}
+		
+		return newLinesCount;
+	}
+	
 	private void weaveComments() {
 		bufferPosition = 0;
@@ -172,10 +192,23 @@
 					if (currentComment.getTotalOffset() == bufferPositionOriginalText) {
 						if (isMultiLineComment(currentComment.getText())) {
-							result.append(currentComment.getText());
-							result.append("\n");
+							int newLinesCount = scanBackNewlinesCount(originalText, bufferPositionOriginalText-1);
+							if (newLinesCount > 0) {
+								result.append(currentComment.getText());
+								result.append("\n");
+							} else {
+								String lastWhiteSpaces = scanBackWhitespaces(result.toString(), result.toString().length()-1);
+								result.delete(result.toString().length() - lastWhiteSpaces.length(), result.toString().length());
+								result.append(" " + stripEndingNewline(currentComment.getText()));
+								result.append(lastWhiteSpaces);
+							}
 						} else if (isSingleLineComment(currentComment.getText())) {
+							int newLinesCount = scanBackNewlinesCount(originalText, bufferPositionOriginalText-1);
 							String lastWhiteSpaces = scanBackWhitespaces(result.toString(), result.toString().length()-1);
 							result.delete(result.toString().length() - lastWhiteSpaces.length(), result.toString().length());
-							result.append(" " + stripEndingNewline(currentComment.getText()));
+							if (newLinesCount > 0) {
+								result.append("\n\n" + stripEndingNewline(currentComment.getText()));
+							} else {
+								result.append(" " + stripEndingNewline(currentComment.getText()));
+							}
 							result.append(lastWhiteSpaces);
 						}
