- Timestamp:
- 10/22/10 14:53:37 (14 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfFormatterVisitor.java
r10 r11 1 1 package de.ugoe.cs.swe.bnftools.ui.formatter; 2 2 3 import org.eclipse.emf.common.util.EList; 3 4 import org.eclipse.emf.ecore.EObject; 4 5 … … 45 46 // ----------------------------------------------------------------------------- 46 47 47 protected void visit (EtsiBnf node) {48 protected void visitBefore(EtsiBnf node) { 48 49 buf.append("grammar " + node.getName()); 49 50 if (node.getType() != null) 50 51 buf.append(node.getType()); 51 52 buf.append(";"); 53 buf.append("\n\n"); 52 54 } 53 55 54 protected void visit (Atomnode) {56 protected void visitAfter(EtsiBnf node) { 55 57 } 56 58 57 protected void visit (DefinitionListnode) {59 protected void visitBefore(Atom node) { 58 60 } 59 61 60 protected void visit (ExtRulenode) {62 protected void visitAfter(Atom node) { 61 63 } 62 64 63 protected void visit (GlobalCombinatornode) {65 protected void visitBefore(Term node) { 64 66 } 65 67 66 protected void visit(GroupedSequence node) { 68 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)) 72 buf.append(" "); 67 73 } 68 74 69 protected void visit (HookCombinatornode) {75 protected void visitBefore(DefinitionList node) { 70 76 } 71 77 72 protected void visit (Import node) {78 protected void visitAfter(DefinitionList node) { 73 79 } 74 80 75 protected void visit (MergeRule node) {81 protected void visitBefore(ExtRule node) { 76 82 } 77 83 78 protected void visit (OptionalSequence node) {84 protected void visitAfter(ExtRule node) { 79 85 } 80 86 81 protected void visit (RepeatedSequencenode) {87 protected void visitBefore(GlobalCombinator node) { 82 88 } 83 89 84 protected void visit (Rulenode) {90 protected void visitAfter(GlobalCombinator node) { 85 91 } 86 92 87 protected void visit(RuleCombinator node) { 93 protected void visitBefore(GroupedSequence node) { 94 buf.append("("); 88 95 } 89 96 90 protected void visit(RuleReference node) { 97 protected void visitAfter(GroupedSequence node) { 98 buf.append(")"); 91 99 } 92 100 93 protected void visit (SectionHeadingnode) {101 protected void visitBefore(HookCombinator node) { 94 102 } 95 103 96 protected void visit (SingleDefinitionnode) {104 protected void visitAfter(HookCombinator node) { 97 105 } 98 106 99 protected void visit (StringRulenode) {107 protected void visitBefore(Import node) { 100 108 } 101 109 102 protected void visit (Termnode) {110 protected void visitAfter(Import node) { 103 111 } 104 112 113 protected void visitBefore(MergeRule node) { 114 } 115 116 protected void visitAfter(MergeRule node) { 117 } 118 119 protected void visitBefore(OptionalSequence node) { 120 } 121 122 protected void visitAfter(OptionalSequence node) { 123 } 124 125 protected void visitBefore(RepeatedSequence node) { 126 } 127 128 protected void visitAfter(RepeatedSequence node) { 129 } 130 131 protected void visitBefore(Rule node) { 132 if (node.getRulenumber() > 0) 133 buf.append(node.getRulenumber() + ". "); 134 135 buf.append(node.getName() + " ::= "); 136 } 137 138 protected void visitAfter(Rule node) { 139 buf.append(";\n"); 140 } 141 142 protected void visitBefore(RuleCombinator node) { 143 } 144 145 protected void visitAfter(RuleCombinator node) { 146 } 147 148 protected void visitBefore(RuleReference node) { 149 } 150 151 protected void visitAfter(RuleReference node) { 152 } 153 154 protected void visitBefore(SectionHeading node) { 155 } 156 157 protected void visitAfter(SectionHeading node) { 158 } 159 160 protected void visitBefore(SingleDefinition node) { 161 } 162 163 protected void visitAfter(SingleDefinition node) { 164 } 165 166 protected void visitBefore(StringRule node) { 167 if (node.getLiteral() != null) 168 buf.append("\"" + node.getLiteral() + "\""); 169 else if (node.getColon() != null) 170 buf.append(" " + node.getColon()); 171 } 172 173 protected void visitAfter(StringRule node) { 174 } 175 176 177 105 178 } -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/FormatterProcessor.java
r9 r11 104 104 105 105 FormatterConfig config = new FormatterConfig(); 106 EbnfFormatterVisitor visitor = new EbnfFormatterVisitor( rootNode.getElement(),config);107 visitor.accept( );106 EbnfFormatterVisitor visitor = new EbnfFormatterVisitor(config); 107 visitor.accept(rootNode.getElement()); 108 108 109 109 ReplaceEdit replaceEdit = new ReplaceEdit(0, document.getLength(), visitor.getBuf().toString()); -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/visitor/EbnfVisitor.java
r9 r11 1 1 package de.ugoe.cs.swe.bnftools.visitor; 2 2 3 import java.util.Collections;4 5 import org.eclipse.emf.common.util.TreeIterator;6 3 import org.eclipse.emf.ecore.EObject; 7 import org.eclipse.emf.ecore.util.EcoreUtil;8 4 9 5 import com.sun.xml.internal.bind.v2.schemagen.xmlschema.Import; … … 28 24 29 25 public abstract class EbnfVisitor { 26 30 27 protected EObject rootNode = null; 31 28 … … 43 40 44 41 public void accept(EObject node) { 45 TreeIterator<Object> it = EcoreUtil.getAllContents(Collections 46 .singleton(node)); 47 48 while (it.hasNext()) { 49 EObject currentNode = (EObject) it.next(); 50 dispatcher(currentNode); 42 dispatcherBefore(node); 43 acceptInner(node); 44 dispatcherAfter(node); 45 } 46 47 private void acceptInner(EObject node) { 48 for (int i=0; i < node.eContents().size(); i++) { 49 EObject currentNode = (EObject) node.eContents().get(i); 50 dispatcherBefore(currentNode); 51 acceptInner(currentNode); 52 dispatcherAfter(currentNode); 51 53 } 52 54 } 53 54 protected void dispatcher (EObject node) {55 56 protected void dispatcherBefore(EObject node) { 55 57 // ugly, but no time to find a prettier solution 56 58 if (node instanceof EtsiBnf) { 57 visit ((EtsiBnf) node);59 visitBefore((EtsiBnf) node); 58 60 } else if (node instanceof Atom) { 59 visit ((Atom) node);61 visitBefore((Atom) node); 60 62 } else if (node instanceof DefinitionList) { 61 visit ((DefinitionList) node);63 visitBefore((DefinitionList) node); 62 64 } else if (node instanceof ExtRule) { 63 visit ((ExtRule) node);65 visitBefore((ExtRule) node); 64 66 } else if (node instanceof GlobalCombinator) { 65 visit ((GlobalCombinator) node);67 visitBefore((GlobalCombinator) node); 66 68 } else if (node instanceof GroupedSequence) { 67 visit ((GroupedSequence) node);69 visitBefore((GroupedSequence) node); 68 70 } else if (node instanceof HookCombinator) { 69 visit ((HookCombinator) node);71 visitBefore((HookCombinator) node); 70 72 } else if (node instanceof Import) { 71 visit ((Import) node);73 visitBefore((Import) node); 72 74 } else if (node instanceof MergeRule) { 73 visit ((MergeRule) node);75 visitBefore((MergeRule) node); 74 76 } else if (node instanceof OptionalSequence) { 75 visit ((OptionalSequence) node);77 visitBefore((OptionalSequence) node); 76 78 } else if (node instanceof RepeatedSequence) { 77 visit ((RepeatedSequence) node);79 visitBefore((RepeatedSequence) node); 78 80 } else if (node instanceof Rule) { 79 visit ((Rule) node);81 visitBefore((Rule) node); 80 82 } else if (node instanceof RuleCombinator) { 81 visit ((RuleCombinator) node);83 visitBefore((RuleCombinator) node); 82 84 } else if (node instanceof RuleReference) { 83 visit ((RuleReference) node);85 visitBefore((RuleReference) node); 84 86 } else if (node instanceof SectionHeading) { 85 visit ((SectionHeading) node);87 visitBefore((SectionHeading) node); 86 88 } else if (node instanceof SingleDefinition) { 87 visit ((SingleDefinition) node);89 visitBefore((SingleDefinition) node); 88 90 } else if (node instanceof StringRule) { 89 visit ((StringRule) node);91 visitBefore((StringRule) node); 90 92 } else if (node instanceof Term) { 91 visit ((Term) node);93 visitBefore((Term) node); 92 94 } 93 95 } 94 96 95 protected void visit(EtsiBnf node) { 96 } 97 98 protected void visit(Atom node) { 99 } 100 101 protected void visit(DefinitionList node) { 102 } 103 104 protected void visit(ExtRule node) { 105 } 106 107 protected void visit(GlobalCombinator node) { 108 } 109 110 protected void visit(GroupedSequence node) { 111 } 112 113 protected void visit(HookCombinator node) { 114 } 115 116 protected void visit(Import node) { 117 } 118 119 protected void visit(MergeRule node) { 120 } 121 122 protected void visit(OptionalSequence node) { 123 } 124 125 protected void visit(RepeatedSequence node) { 126 } 127 128 protected void visit(Rule node) { 129 } 130 131 protected void visit(RuleCombinator node) { 132 } 133 134 protected void visit(RuleReference node) { 135 } 136 137 protected void visit(SectionHeading node) { 138 } 139 140 protected void visit(SingleDefinition node) { 141 } 142 143 protected void visit(StringRule node) { 144 } 145 146 protected void visit(Term node) { 147 } 148 97 protected void dispatcherAfter(EObject node) { 98 // ugly, but no time to find a prettier solution 99 if (node instanceof EtsiBnf) { 100 visitAfter((EtsiBnf) node); 101 } else if (node instanceof Atom) { 102 visitAfter((Atom) node); 103 } else if (node instanceof DefinitionList) { 104 visitAfter((DefinitionList) node); 105 } else if (node instanceof ExtRule) { 106 visitAfter((ExtRule) node); 107 } else if (node instanceof GlobalCombinator) { 108 visitAfter((GlobalCombinator) node); 109 } else if (node instanceof GroupedSequence) { 110 visitAfter((GroupedSequence) node); 111 } else if (node instanceof HookCombinator) { 112 visitAfter((HookCombinator) node); 113 } else if (node instanceof Import) { 114 visitAfter((Import) node); 115 } else if (node instanceof MergeRule) { 116 visitAfter((MergeRule) node); 117 } else if (node instanceof OptionalSequence) { 118 visitAfter((OptionalSequence) node); 119 } else if (node instanceof RepeatedSequence) { 120 visitAfter((RepeatedSequence) node); 121 } else if (node instanceof Rule) { 122 visitAfter((Rule) node); 123 } else if (node instanceof RuleCombinator) { 124 visitAfter((RuleCombinator) node); 125 } else if (node instanceof RuleReference) { 126 visitAfter((RuleReference) node); 127 } else if (node instanceof SectionHeading) { 128 visitAfter((SectionHeading) node); 129 } else if (node instanceof SingleDefinition) { 130 visitAfter((SingleDefinition) node); 131 } else if (node instanceof StringRule) { 132 visitAfter((StringRule) node); 133 } else if (node instanceof Term) { 134 visitAfter((Term) node); 135 } 136 } 137 138 protected void visitBefore(EtsiBnf node) { 139 } 140 141 protected void visitAfter(EtsiBnf node) { 142 } 143 144 protected void visitBefore(Atom node) { 145 } 146 147 protected void visitAfter(Atom node) { 148 } 149 150 protected void visitBefore(Term node) { 151 } 152 153 protected void visitAfter(Term node) { 154 } 155 156 protected void visitBefore(DefinitionList node) { 157 } 158 159 protected void visitAfter(DefinitionList node) { 160 } 161 162 protected void visitBefore(ExtRule node) { 163 } 164 165 protected void visitAfter(ExtRule node) { 166 } 167 168 protected void visitBefore(GlobalCombinator node) { 169 } 170 171 protected void visitAfter(GlobalCombinator node) { 172 } 173 174 protected void visitBefore(GroupedSequence node) { 175 } 176 177 protected void visitAfter(GroupedSequence node) { 178 } 179 180 protected void visitBefore(HookCombinator node) { 181 } 182 183 protected void visitAfter(HookCombinator node) { 184 } 185 186 protected void visitBefore(Import node) { 187 } 188 189 protected void visitAfter(Import node) { 190 } 191 192 protected void visitBefore(MergeRule node) { 193 } 194 195 protected void visitAfter(MergeRule node) { 196 } 197 198 protected void visitBefore(OptionalSequence node) { 199 } 200 201 protected void visitAfter(OptionalSequence node) { 202 } 203 204 protected void visitBefore(RepeatedSequence node) { 205 } 206 207 protected void visitAfter(RepeatedSequence node) { 208 } 209 210 protected void visitBefore(Rule node) { 211 } 212 213 protected void visitAfter(Rule node) { 214 } 215 216 protected void visitBefore(RuleCombinator node) { 217 } 218 219 protected void visitAfter(RuleCombinator node) { 220 } 221 222 protected void visitBefore(RuleReference node) { 223 } 224 225 protected void visitAfter(RuleReference node) { 226 } 227 228 protected void visitBefore(SectionHeading node) { 229 } 230 231 protected void visitAfter(SectionHeading node) { 232 } 233 234 protected void visitBefore(SingleDefinition node) { 235 } 236 237 protected void visitAfter(SingleDefinition node) { 238 } 239 240 protected void visitBefore(StringRule node) { 241 } 242 243 protected void visitAfter(StringRule node) { 244 } 245 149 246 } -
trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/GenerateEbnf.mwe2
r5 r11 76 76 //fragment = exporting.QualifiedNamesFragment {} 77 77 78 // formatter API 79 fragment = formatting.FormatterFragment {} 78 // formatter API 79 // skip it as it is not sufficient for our case... 80 // fragment = formatting.FormatterFragment {} 80 81 81 82 // labeling API -
trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/formatting/EbnfFormatter.java
r5 r11 19 19 @Override 20 20 protected void configureFormatting(FormattingConfig c) { 21 de.ugoe.cs.swe.bnftools.services.EbnfGrammarAccess f = (de.ugoe.cs.swe.bnftools.services.EbnfGrammarAccess) getGrammarAccess();22 23 c.setIndentationSpace(" ");24 c.setNoLinewrap();25 c.setAutoLinewrap(10000000);26 c.setLinewrap(2).before(f.getSectionHeadingRule());27 c.setLinewrap(2).after(f.getSectionHeadingRule());28 29 30 c.setNoSpace().after(f.getRuleAccess().getRulenumberINTTerminalRuleCall_0_0_0());31 c.setNoSpace().after(f.getRuleAccess().getRulevariantIDTerminalRuleCall_0_1_0());32 33 c.setLinewrap().before(f.getRuleAccess().getRulenumberINTTerminalRuleCall_0_0_0());34 c.setNoSpace().before(f.getRuleAccess().getSemicolonKeyword_4());35 // c.setNoSpace().before(f.getRuleAccess().getNameIDTerminalRuleCall_1_0());36 37 // c.setLinewrap().after(f.getRuleAccess().getDefinitionListDefinitionListParserRuleCall_3_0());38 c.setLinewrap().after(f.getRuleAccess().getDefinitionListAssignment_3());39 40 c.setLinewrap(2).before(f.getSL_COMMENTRule());41 c.setNoLinewrap().after(f.getSL_COMMENTRule());42 c.setLinewrap(2).before(f.getML_COMMENTRule());21 // de.ugoe.cs.swe.bnftools.services.EbnfGrammarAccess f = (de.ugoe.cs.swe.bnftools.services.EbnfGrammarAccess) getGrammarAccess(); 22 // 23 // c.setIndentationSpace(" "); 24 // c.setNoLinewrap(); 25 // c.setAutoLinewrap(10000000); 26 // c.setLinewrap(2).before(f.getSectionHeadingRule()); 27 // c.setLinewrap(2).after(f.getSectionHeadingRule()); 28 // 29 // 30 // c.setNoSpace().after(f.getRuleAccess().getRulenumberINTTerminalRuleCall_0_0_0()); 31 // c.setNoSpace().after(f.getRuleAccess().getRulevariantIDTerminalRuleCall_0_1_0()); 32 // 33 // c.setLinewrap().before(f.getRuleAccess().getRulenumberINTTerminalRuleCall_0_0_0()); 34 // c.setNoSpace().before(f.getRuleAccess().getSemicolonKeyword_4()); 35 //// c.setNoSpace().before(f.getRuleAccess().getNameIDTerminalRuleCall_1_0()); 36 // 37 //// c.setLinewrap().after(f.getRuleAccess().getDefinitionListDefinitionListParserRuleCall_3_0()); 38 // c.setLinewrap().after(f.getRuleAccess().getDefinitionListAssignment_3()); 39 // 40 // c.setLinewrap(2).before(f.getSL_COMMENTRule()); 41 // c.setNoLinewrap().after(f.getSL_COMMENTRule()); 42 // c.setLinewrap(2).before(f.getML_COMMENTRule()); 43 43 } 44 44
Note: See TracChangeset
for help on using the changeset viewer.