Changeset 12 in default for trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools
- Timestamp:
- 10/22/10 15:45:35 (14 years ago)
- Location:
- trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools
- 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
r11 r12 3 3 import org.eclipse.emf.common.util.EList; 4 4 import org.eclipse.emf.ecore.EObject; 5 6 import com.sun.xml.internal.bind.v2.schemagen.xmlschema.Import;7 5 8 6 import de.ugoe.cs.swe.bnftools.ebnf.Atom; … … 13 11 import de.ugoe.cs.swe.bnftools.ebnf.GroupedSequence; 14 12 import de.ugoe.cs.swe.bnftools.ebnf.HookCombinator; 13 import de.ugoe.cs.swe.bnftools.ebnf.Import; 15 14 import de.ugoe.cs.swe.bnftools.ebnf.MergeRule; 16 15 import de.ugoe.cs.swe.bnftools.ebnf.OptionalSequence; … … 29 28 private FormatterConfig config; 30 29 30 int ruleCounter = 0; 31 31 32 public EbnfFormatterVisitor(EObject rootNode, FormatterConfig config) { 32 33 super(rootNode); … … 67 68 68 69 protected void visitAfter(Term node) { 69 SingleDefinition parent = (SingleDefinition) node.eContainer(); 70 int index = parent.getTerms().indexOf(node); 71 if ((parent.getTerms().size() > 0) && (index < parent.getTerms().size()-1)) 70 if (!isLastElement()) 72 71 buf.append(" "); 73 72 } … … 106 105 107 106 protected void visitBefore(Import node) { 107 buf.append("import \"" + node.getImportURI() + "\";\n"); 108 108 } 109 109 … … 118 118 119 119 protected void visitBefore(OptionalSequence node) { 120 buf.append("["); 120 121 } 121 122 122 123 protected void visitAfter(OptionalSequence node) { 124 buf.append("]"); 123 125 } 124 126 125 127 protected void visitBefore(RepeatedSequence node) { 128 buf.append("{"); 126 129 } 127 130 128 131 protected void visitAfter(RepeatedSequence node) { 132 buf.append("}"); 133 if (node.isMorethanonce()) 134 buf.append("+"); 129 135 } 130 136 131 137 protected void visitBefore(Rule node) { 138 if (ruleCounter == 0) 139 buf.append("\n"); 140 141 ruleCounter++; 132 142 if (node.getRulenumber() > 0) 133 143 buf.append(node.getRulenumber() + ". "); … … 147 157 148 158 protected void visitBefore(RuleReference node) { 159 buf.append(node.getRuleref().getName()); 149 160 } 150 161 … … 162 173 163 174 protected void visitAfter(SingleDefinition node) { 175 if (!isLastElement()) 176 buf.append(" | "); 177 164 178 } 165 179 … … 168 182 buf.append("\"" + node.getLiteral() + "\""); 169 183 else if (node.getColon() != null) 170 buf.append(" " + node.getColon());184 buf.append("\"\"\""); 171 185 } 172 186 -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/visitor/EbnfVisitor.java
r11 r12 1 1 package de.ugoe.cs.swe.bnftools.visitor; 2 2 3 import java.util.Stack; 4 3 5 import org.eclipse.emf.ecore.EObject; 4 5 import com.sun.xml.internal.bind.v2.schemagen.xmlschema.Import;6 6 7 7 import de.ugoe.cs.swe.bnftools.ebnf.Atom; … … 12 12 import de.ugoe.cs.swe.bnftools.ebnf.GroupedSequence; 13 13 import de.ugoe.cs.swe.bnftools.ebnf.HookCombinator; 14 import de.ugoe.cs.swe.bnftools.ebnf.Import; 14 15 import de.ugoe.cs.swe.bnftools.ebnf.MergeRule; 15 16 import de.ugoe.cs.swe.bnftools.ebnf.OptionalSequence; … … 26 27 27 28 protected EObject rootNode = null; 28 29 protected Stack<Boolean> lastElementStack = new Stack<Boolean>(); 30 29 31 public EbnfVisitor() { 30 32 } … … 46 48 47 49 private void acceptInner(EObject node) { 50 Boolean lastElement = false; 51 if (node.eContents().size() == 0) 52 lastElement = true; 53 lastElementStack.push(lastElement); 48 54 for (int i=0; i < node.eContents().size(); i++) { 49 55 EObject currentNode = (EObject) node.eContents().get(i); 56 if (i == node.eContents().size()-1) { 57 lastElement = true; 58 lastElementStack.pop(); 59 lastElementStack.push(lastElement); 60 } 50 61 dispatcherBefore(currentNode); 51 62 acceptInner(currentNode); 52 63 dispatcherAfter(currentNode); 53 64 } 65 lastElementStack.pop(); 66 } 67 68 protected boolean isLastElement() { 69 return lastElementStack.peek(); 54 70 } 55 71
Note: See TracChangeset
for help on using the changeset viewer.