Changeset 28 in default for trunk/de.ugoe.cs.swe.bnftools.ebnf.ui
- Timestamp:
- 11/02/10 16:39:02 (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/EbnfFormatterVisitor.java
r27 r28 2 2 3 3 import java.util.ArrayList; 4 import java.util.Stack; 4 5 5 6 import org.eclipse.emf.ecore.EObject; … … 48 49 private String formattedTextNoWhitespaces; 49 50 private String originalTextNoWhitespaces; 51 private int newLineOffsetCounter = 0; 52 private int rightHandSideRuleOffset = 0; 53 private Stack<Integer> ruleSpacingStack = new Stack<Integer>(); 50 54 51 55 public EbnfFormatterVisitor(EObject rootNode, FormatterConfig config) { … … 263 267 private void text(String str) { 264 268 buf.append(str); 269 newLineOffsetCounter += str.length(); 265 270 } 266 271 267 272 private void space() { 268 273 buf.append(" "); 274 newLineOffsetCounter++; 275 } 276 277 private void spaces(int count) { 278 for (int i=0; i < count; i++) { 279 buf.append(" "); 280 } 269 281 } 270 282 … … 350 362 protected void visitBefore(GroupedSequence node) { 351 363 text("("); 364 ruleSpacingStack.push(newLineOffsetCounter); 352 365 } 353 366 354 367 protected void visitAfter(GroupedSequence node) { 355 368 text(")"); 369 ruleSpacingStack.pop(); 356 370 } 357 371 … … 378 392 protected void visitBefore(OptionalSequence node) { 379 393 text("["); 394 ruleSpacingStack.push(newLineOffsetCounter); 380 395 } 381 396 382 397 protected void visitAfter(OptionalSequence node) { 383 398 text("]"); 399 ruleSpacingStack.pop(); 384 400 } 385 401 386 402 protected void visitBefore(RepeatedSequence node) { 387 403 text("{"); 404 ruleSpacingStack.push(newLineOffsetCounter); 388 405 } 389 406 … … 392 409 if (node.isMorethanonce()) 393 410 text("+"); 411 ruleSpacingStack.pop(); 394 412 } 395 413 … … 400 418 lastWasSectionHeading=false; 401 419 420 newLineOffsetCounter = 0; 421 402 422 if (node.getRulenumber() > 0) 403 423 text(node.getRulenumber() + ". "); 404 424 405 425 text(node.getName() + " ::= "); 426 427 rightHandSideRuleOffset = newLineOffsetCounter; 428 ruleSpacingStack.push(newLineOffsetCounter); 406 429 } 407 430 … … 409 432 text(";"); 410 433 newLine(); 434 ruleSpacingStack.pop(); 411 435 } 412 436 … … 443 467 444 468 protected void visitAfter(SingleDefinition node) { 445 if (!isLastElement()) 469 if (!isLastElement()) { 446 470 text(" | "); 447 471 if (config.isNewLineAfterAlternative()) { 472 if (config.isPreventNewLineAfterAlternativeOnLessThanThreeElements()) { 473 DefinitionList definitionList = (DefinitionList) node.eContainer(); 474 if (definitionList.eContents().size() > 2) { 475 newLine(); 476 spaces(ruleSpacingStack.peek()); 477 } 478 } else { 479 newLine(); 480 spaces(ruleSpacingStack.peek()); 481 } 482 } 483 } 448 484 } 449 485 -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/FormatterConfig.java
r9 r28 2 2 3 3 public class FormatterConfig { 4 private boolean useSpaces = true; // false=tabs, true=whitespaces 5 private int lineWrap = 80; // line in which the output should be wrapped 6 private boolean emptyLineBetweenRules = false; 7 private boolean emptyLineAfterMultiLineRule = false; 8 private boolean emptyLineBeforeSection = true; 9 private boolean emptyLineAfterSection = true; 4 private boolean newLineAfterAlternative = true; 5 private boolean preventNewLineAfterAlternativeOnLessThanThreeElements = true; 10 6 11 public boolean is UseSpaces() {12 return useSpaces;7 public boolean isNewLineAfterAlternative() { 8 return newLineAfterAlternative; 13 9 } 14 10 15 public void set UseSpaces(boolean useSpaces) {16 this. useSpaces = useSpaces;11 public void setNewLineAfterAlternative(boolean newLineAfterAlternative) { 12 this.newLineAfterAlternative = newLineAfterAlternative; 17 13 } 18 14 19 public int getLineWrap() {20 return lineWrap;15 public boolean isPreventNewLineAfterAlternativeOnLessThanThreeElements() { 16 return preventNewLineAfterAlternativeOnLessThanThreeElements; 21 17 } 22 18 23 public void setLineWrap(int lineWrap) { 24 this.lineWrap = lineWrap; 25 } 26 27 public boolean isEmptyLineBetweenRules() { 28 return emptyLineBetweenRules; 29 } 30 31 public void setEmptyLineBetweenRules(boolean emptyLineBetweenRules) { 32 this.emptyLineBetweenRules = emptyLineBetweenRules; 33 } 34 35 public boolean isEmptyLineAfterMultiLineRule() { 36 return emptyLineAfterMultiLineRule; 37 } 38 39 public void setEmptyLineAfterMultiLineRule( 40 boolean emptyLineAfterMultiLineRule) { 41 this.emptyLineAfterMultiLineRule = emptyLineAfterMultiLineRule; 42 } 43 44 public boolean isEmptyLineBeforeSection() { 45 return emptyLineBeforeSection; 46 } 47 48 public void setEmptyLineBeforeSection(boolean emptyLineBeforeSection) { 49 this.emptyLineBeforeSection = emptyLineBeforeSection; 50 } 51 52 public boolean isEmptyLineAfterSection() { 53 return emptyLineAfterSection; 54 } 55 56 public void setEmptyLineAfterSection(boolean emptyLineAfterSection) { 57 this.emptyLineAfterSection = emptyLineAfterSection; 19 public void setPreventNewLineAfterAlternativeOnLessThanThreeElements( 20 boolean preventNewLineAfterAlternativeOnLessThanThreeElements) { 21 this.preventNewLineAfterAlternativeOnLessThanThreeElements = preventNewLineAfterAlternativeOnLessThanThreeElements; 58 22 } 59 23
Note: See TracChangeset
for help on using the changeset viewer.