- Timestamp:
- 11/02/10 18:29:57 (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
r30 r31 8 8 import org.eclipse.xtext.parsetree.CompositeNode; 9 9 import org.eclipse.xtext.parsetree.LeafNode; 10 import org.eclipse.xtext.parsetree.NodeAdapter;11 10 import org.eclipse.xtext.parsetree.NodeUtil; 12 11 … … 181 180 182 181 private void weaveComments() { 183 // if (true) {184 // StringBuffer result = new StringBuffer();185 // result.append(buf.toString());186 // buf = result;187 // return;188 // }189 190 182 bufferPositionOriginalText = 0; 191 183 bufferPositionFormattedTextNoWhitespaces = 0; … … 248 240 } 249 241 } else { // disaster handling: return original unformatted text! 242 System.err.println("Disaster Recovery: returning original text!!"); 250 243 buf = new StringBuffer(); 251 244 buf.append(originalText); … … 287 280 } 288 281 282 private boolean lastIsClosingParentheses() { 283 char ch = buf.toString().charAt(buf.toString().length()-1); 284 if ((ch == ')') || (ch == ']') || (ch == '}')) 285 return true; 286 return false; 287 } 288 289 private void wrap() { 290 if ((config.isWrapAfterThreshold()) && (newLineOffsetCounter > config.getWrapThreshold())) { 291 newLine(); 292 if (ruleSpacingStack.size() > 1) 293 spaces(ruleSpacingStack.peek() + 1); 294 else 295 spaces(ruleSpacingStack.peek()); 296 } 297 } 298 289 299 // ----------------------------------------------------------------------------- 290 300 … … 372 382 } 373 383 374 protected void visitBefore(GroupedSequence node) {375 text("(");376 ruleSpacingStack.push(newLineOffsetCounter);377 }378 379 protected void visitAfter(GroupedSequence node) {380 text(")");381 ruleSpacingStack.pop();382 }383 384 384 protected void visitBefore(HookCombinator node) { 385 385 } … … 402 402 } 403 403 404 protected void visitBefore(GroupedSequence node) { 405 wrap(); 406 text("("); 407 ruleSpacingStack.push(newLineOffsetCounter-1); 408 } 409 410 protected void visitAfter(GroupedSequence node) { 411 // if ((config.isAlignParentheses() && (node.eContents().get(0).eContents().size() >= config.getAlignParenthesesElementCountThreshold())) || (lastIsClosingParentheses())) { 412 if (config.isAlignParentheses() && (node.eContents().get(0).eContents().size() >= config.getAlignParenthesesElementCountThreshold())) { 413 newLine(); 414 spaces(ruleSpacingStack.peek()); 415 } 416 417 text(")"); 418 ruleSpacingStack.pop(); 419 } 420 404 421 protected void visitBefore(OptionalSequence node) { 422 wrap(); 405 423 text("["); 406 ruleSpacingStack.push(newLineOffsetCounter );424 ruleSpacingStack.push(newLineOffsetCounter-1); 407 425 } 408 426 409 427 protected void visitAfter(OptionalSequence node) { 428 // if ((config.isAlignParentheses() && (node.eContents().get(0).eContents().size() >= config.getAlignParenthesesElementCountThreshold())) || (lastIsClosingParentheses())) { 429 if (config.isAlignParentheses() && (node.eContents().get(0).eContents().size() >= config.getAlignParenthesesElementCountThreshold())) { 430 newLine(); 431 spaces(ruleSpacingStack.peek()); 432 } 433 410 434 text("]"); 411 435 ruleSpacingStack.pop(); … … 413 437 414 438 protected void visitBefore(RepeatedSequence node) { 439 wrap(); 415 440 text("{"); 416 ruleSpacingStack.push(newLineOffsetCounter );441 ruleSpacingStack.push(newLineOffsetCounter-1); 417 442 } 418 443 419 444 protected void visitAfter(RepeatedSequence node) { 445 // if ((config.isAlignParentheses() && (node.eContents().get(0).eContents().size() >= config.getAlignParenthesesElementCountThreshold())) || (lastIsClosingParentheses())) { 446 if (config.isAlignParentheses() && (node.eContents().get(0).eContents().size() >= config.getAlignParenthesesElementCountThreshold())) { 447 newLine(); 448 spaces(ruleSpacingStack.peek()); 449 } 450 420 451 text("}"); 421 452 if (node.isMorethanonce()) … … 454 485 455 486 protected void visitBefore(RuleReference node) { 487 wrap(); 456 488 text(node.getRuleref().getName()); 457 489 } … … 482 514 if (config.isPreventNewLineAfterAlternativeOnLessThanThreeElements()) { 483 515 DefinitionList definitionList = (DefinitionList) node.eContainer(); 484 485 516 if ((definitionList.eContents().size() > 2) && (!preventAlternativeBreakShortAlternatives)) { 486 517 newLine(); 487 spaces(ruleSpacingStack.peek()); 518 if (ruleSpacingStack.size() > 1) 519 spaces(ruleSpacingStack.peek() + 1); 520 else 521 spaces(ruleSpacingStack.peek()); 488 522 } 489 523 } else { 490 524 if (!preventAlternativeBreakShortAlternatives) { 491 525 newLine(); 492 spaces(ruleSpacingStack.peek()); 526 if (ruleSpacingStack.size() > 1) 527 spaces(ruleSpacingStack.peek() + 1); 528 else 529 spaces(ruleSpacingStack.peek()); 493 530 } 494 531 } … … 498 535 499 536 protected void visitBefore(StringRule node) { 537 wrap(); 500 538 if (node.getLiteral() != null) 501 539 text("\"" + node.getLiteral() + "\""); -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/FormatterConfig.java
r30 r31 6 6 private boolean preventNewLineAfterAlternativeOnShortAlternatives = true; 7 7 private double shortAlternativeThreshold = 3.0; 8 private boolean alignParentheses = true; 9 private int alignParenthesesElementCountThreshold = 3; 10 private boolean wrapAfterThreshold = true; 11 private int wrapThreshold = 80; 8 12 9 13 public boolean isNewLineAfterAlternative() { … … 41 45 } 42 46 47 public boolean isAlignParentheses() { 48 return alignParentheses; 49 } 50 51 public void setAlignParentheses(boolean alignParentheses) { 52 this.alignParentheses = alignParentheses; 53 } 54 55 public int getAlignParenthesesElementCountThreshold() { 56 return alignParenthesesElementCountThreshold; 57 } 58 59 public void setAlignParenthesesElementCountThreshold( 60 int alignParenthesesElementCountThreshold) { 61 this.alignParenthesesElementCountThreshold = alignParenthesesElementCountThreshold; 62 } 63 64 public boolean isWrapAfterThreshold() { 65 return wrapAfterThreshold; 66 } 67 68 public void setWrapAfterThreshold(boolean wrapAfterThreshold) { 69 this.wrapAfterThreshold = wrapAfterThreshold; 70 } 71 72 public int getWrapThreshold() { 73 return wrapThreshold; 74 } 75 76 public void setWrapThreshold(int wrapThreshold) { 77 this.wrapThreshold = wrapThreshold; 78 } 79 43 80 }
Note: See TracChangeset
for help on using the changeset viewer.