[9] | 1 | package de.ugoe.cs.swe.bnftools.visitor;
|
---|
| 2 |
|
---|
[12] | 3 | import java.util.Stack;
|
---|
| 4 |
|
---|
[9] | 5 | import org.eclipse.emf.ecore.EObject;
|
---|
| 6 |
|
---|
| 7 | import de.ugoe.cs.swe.bnftools.ebnf.Atom;
|
---|
[13] | 8 | import de.ugoe.cs.swe.bnftools.ebnf.BnfEntry;
|
---|
[9] | 9 | import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList;
|
---|
[13] | 10 | import de.ugoe.cs.swe.bnftools.ebnf.DeltaEntry;
|
---|
[9] | 11 | import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf;
|
---|
| 12 | import de.ugoe.cs.swe.bnftools.ebnf.ExtRule;
|
---|
| 13 | import de.ugoe.cs.swe.bnftools.ebnf.GlobalCombinator;
|
---|
| 14 | import de.ugoe.cs.swe.bnftools.ebnf.GroupedSequence;
|
---|
| 15 | import de.ugoe.cs.swe.bnftools.ebnf.HookCombinator;
|
---|
[12] | 16 | import de.ugoe.cs.swe.bnftools.ebnf.Import;
|
---|
[13] | 17 | import de.ugoe.cs.swe.bnftools.ebnf.ImportSection;
|
---|
| 18 | import de.ugoe.cs.swe.bnftools.ebnf.MergeEntry;
|
---|
[9] | 19 | import de.ugoe.cs.swe.bnftools.ebnf.MergeRule;
|
---|
| 20 | import de.ugoe.cs.swe.bnftools.ebnf.OptionalSequence;
|
---|
| 21 | import de.ugoe.cs.swe.bnftools.ebnf.RepeatedSequence;
|
---|
| 22 | import de.ugoe.cs.swe.bnftools.ebnf.Rule;
|
---|
| 23 | import de.ugoe.cs.swe.bnftools.ebnf.RuleCombinator;
|
---|
| 24 | import de.ugoe.cs.swe.bnftools.ebnf.RuleReference;
|
---|
| 25 | import de.ugoe.cs.swe.bnftools.ebnf.SectionHeading;
|
---|
| 26 | import de.ugoe.cs.swe.bnftools.ebnf.SingleDefinition;
|
---|
| 27 | import de.ugoe.cs.swe.bnftools.ebnf.StringRule;
|
---|
| 28 | import de.ugoe.cs.swe.bnftools.ebnf.Term;
|
---|
| 29 |
|
---|
| 30 | public abstract class EbnfVisitor {
|
---|
[11] | 31 |
|
---|
[9] | 32 | protected EObject rootNode = null;
|
---|
[12] | 33 | protected Stack<Boolean> lastElementStack = new Stack<Boolean>();
|
---|
| 34 |
|
---|
[9] | 35 | public EbnfVisitor() {
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public EbnfVisitor(EObject rootNode) {
|
---|
| 39 | this.rootNode = rootNode;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public void accept() {
|
---|
| 43 | if (rootNode != null)
|
---|
| 44 | accept(rootNode);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public void accept(EObject node) {
|
---|
[11] | 48 | dispatcherBefore(node);
|
---|
| 49 | acceptInner(node);
|
---|
| 50 | dispatcherAfter(node);
|
---|
| 51 | }
|
---|
[9] | 52 |
|
---|
[11] | 53 | private void acceptInner(EObject node) {
|
---|
[12] | 54 | Boolean lastElement = false;
|
---|
| 55 | if (node.eContents().size() == 0)
|
---|
| 56 | lastElement = true;
|
---|
| 57 | lastElementStack.push(lastElement);
|
---|
[11] | 58 | for (int i=0; i < node.eContents().size(); i++) {
|
---|
| 59 | EObject currentNode = (EObject) node.eContents().get(i);
|
---|
[12] | 60 | if (i == node.eContents().size()-1) {
|
---|
| 61 | lastElement = true;
|
---|
| 62 | lastElementStack.pop();
|
---|
| 63 | lastElementStack.push(lastElement);
|
---|
| 64 | }
|
---|
[11] | 65 | dispatcherBefore(currentNode);
|
---|
| 66 | acceptInner(currentNode);
|
---|
| 67 | dispatcherAfter(currentNode);
|
---|
[9] | 68 | }
|
---|
[12] | 69 | lastElementStack.pop();
|
---|
[9] | 70 | }
|
---|
[11] | 71 |
|
---|
[12] | 72 | protected boolean isLastElement() {
|
---|
| 73 | return lastElementStack.peek();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[11] | 76 | protected void dispatcherBefore(EObject node) {
|
---|
[9] | 77 | // ugly, but no time to find a prettier solution
|
---|
| 78 | if (node instanceof EtsiBnf) {
|
---|
[11] | 79 | visitBefore((EtsiBnf) node);
|
---|
[13] | 80 | } else if (node instanceof ImportSection) {
|
---|
| 81 | visitBefore((ImportSection) node);
|
---|
| 82 | } else if (node instanceof BnfEntry) {
|
---|
| 83 | visitBefore((BnfEntry) node);
|
---|
| 84 | } else if (node instanceof DeltaEntry) {
|
---|
| 85 | visitBefore((DeltaEntry) node);
|
---|
| 86 | } else if (node instanceof MergeEntry) {
|
---|
| 87 | visitBefore((MergeEntry) node);
|
---|
[9] | 88 | } else if (node instanceof Atom) {
|
---|
[11] | 89 | visitBefore((Atom) node);
|
---|
[9] | 90 | } else if (node instanceof DefinitionList) {
|
---|
[11] | 91 | visitBefore((DefinitionList) node);
|
---|
[9] | 92 | } else if (node instanceof ExtRule) {
|
---|
[11] | 93 | visitBefore((ExtRule) node);
|
---|
[9] | 94 | } else if (node instanceof GlobalCombinator) {
|
---|
[11] | 95 | visitBefore((GlobalCombinator) node);
|
---|
[9] | 96 | } else if (node instanceof GroupedSequence) {
|
---|
[11] | 97 | visitBefore((GroupedSequence) node);
|
---|
[9] | 98 | } else if (node instanceof HookCombinator) {
|
---|
[11] | 99 | visitBefore((HookCombinator) node);
|
---|
[9] | 100 | } else if (node instanceof Import) {
|
---|
[11] | 101 | visitBefore((Import) node);
|
---|
[9] | 102 | } else if (node instanceof MergeRule) {
|
---|
[11] | 103 | visitBefore((MergeRule) node);
|
---|
[9] | 104 | } else if (node instanceof OptionalSequence) {
|
---|
[11] | 105 | visitBefore((OptionalSequence) node);
|
---|
[9] | 106 | } else if (node instanceof RepeatedSequence) {
|
---|
[11] | 107 | visitBefore((RepeatedSequence) node);
|
---|
[9] | 108 | } else if (node instanceof Rule) {
|
---|
[11] | 109 | visitBefore((Rule) node);
|
---|
[9] | 110 | } else if (node instanceof RuleCombinator) {
|
---|
[11] | 111 | visitBefore((RuleCombinator) node);
|
---|
[9] | 112 | } else if (node instanceof RuleReference) {
|
---|
[11] | 113 | visitBefore((RuleReference) node);
|
---|
[9] | 114 | } else if (node instanceof SectionHeading) {
|
---|
[11] | 115 | visitBefore((SectionHeading) node);
|
---|
[9] | 116 | } else if (node instanceof SingleDefinition) {
|
---|
[11] | 117 | visitBefore((SingleDefinition) node);
|
---|
[9] | 118 | } else if (node instanceof StringRule) {
|
---|
[11] | 119 | visitBefore((StringRule) node);
|
---|
[9] | 120 | } else if (node instanceof Term) {
|
---|
[11] | 121 | visitBefore((Term) node);
|
---|
[9] | 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[11] | 125 | protected void dispatcherAfter(EObject node) {
|
---|
| 126 | // ugly, but no time to find a prettier solution
|
---|
| 127 | if (node instanceof EtsiBnf) {
|
---|
| 128 | visitAfter((EtsiBnf) node);
|
---|
[13] | 129 | } else if (node instanceof ImportSection) {
|
---|
| 130 | visitAfter((ImportSection) node);
|
---|
| 131 | } else if (node instanceof BnfEntry) {
|
---|
| 132 | visitAfter((BnfEntry) node);
|
---|
| 133 | } else if (node instanceof DeltaEntry) {
|
---|
| 134 | visitAfter((DeltaEntry) node);
|
---|
| 135 | } else if (node instanceof MergeEntry) {
|
---|
| 136 | visitAfter((MergeEntry) node);
|
---|
[11] | 137 | } else if (node instanceof Atom) {
|
---|
| 138 | visitAfter((Atom) node);
|
---|
| 139 | } else if (node instanceof DefinitionList) {
|
---|
| 140 | visitAfter((DefinitionList) node);
|
---|
| 141 | } else if (node instanceof ExtRule) {
|
---|
| 142 | visitAfter((ExtRule) node);
|
---|
| 143 | } else if (node instanceof GlobalCombinator) {
|
---|
| 144 | visitAfter((GlobalCombinator) node);
|
---|
| 145 | } else if (node instanceof GroupedSequence) {
|
---|
| 146 | visitAfter((GroupedSequence) node);
|
---|
| 147 | } else if (node instanceof HookCombinator) {
|
---|
| 148 | visitAfter((HookCombinator) node);
|
---|
| 149 | } else if (node instanceof Import) {
|
---|
| 150 | visitAfter((Import) node);
|
---|
| 151 | } else if (node instanceof MergeRule) {
|
---|
| 152 | visitAfter((MergeRule) node);
|
---|
| 153 | } else if (node instanceof OptionalSequence) {
|
---|
| 154 | visitAfter((OptionalSequence) node);
|
---|
| 155 | } else if (node instanceof RepeatedSequence) {
|
---|
| 156 | visitAfter((RepeatedSequence) node);
|
---|
| 157 | } else if (node instanceof Rule) {
|
---|
| 158 | visitAfter((Rule) node);
|
---|
| 159 | } else if (node instanceof RuleCombinator) {
|
---|
| 160 | visitAfter((RuleCombinator) node);
|
---|
| 161 | } else if (node instanceof RuleReference) {
|
---|
| 162 | visitAfter((RuleReference) node);
|
---|
| 163 | } else if (node instanceof SectionHeading) {
|
---|
| 164 | visitAfter((SectionHeading) node);
|
---|
| 165 | } else if (node instanceof SingleDefinition) {
|
---|
| 166 | visitAfter((SingleDefinition) node);
|
---|
| 167 | } else if (node instanceof StringRule) {
|
---|
| 168 | visitAfter((StringRule) node);
|
---|
| 169 | } else if (node instanceof Term) {
|
---|
| 170 | visitAfter((Term) node);
|
---|
| 171 | }
|
---|
[9] | 172 | }
|
---|
| 173 |
|
---|
[11] | 174 | protected void visitBefore(EtsiBnf node) {
|
---|
[9] | 175 | }
|
---|
| 176 |
|
---|
[11] | 177 | protected void visitAfter(EtsiBnf node) {
|
---|
[9] | 178 | }
|
---|
| 179 |
|
---|
[13] | 180 | protected void visitBefore(ImportSection node) {
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | protected void visitAfter(ImportSection node) {
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | protected void visitBefore(BnfEntry node) {
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | protected void visitAfter(BnfEntry node) {
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | protected void visitBefore(DeltaEntry node) {
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | protected void visitAfter(DeltaEntry node) {
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | protected void visitBefore(MergeEntry node) {
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | protected void visitAfter(MergeEntry node) {
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[11] | 204 | protected void visitBefore(Atom node) {
|
---|
[9] | 205 | }
|
---|
| 206 |
|
---|
[11] | 207 | protected void visitAfter(Atom node) {
|
---|
[9] | 208 | }
|
---|
| 209 |
|
---|
[11] | 210 | protected void visitBefore(Term node) {
|
---|
[9] | 211 | }
|
---|
| 212 |
|
---|
[11] | 213 | protected void visitAfter(Term node) {
|
---|
[9] | 214 | }
|
---|
| 215 |
|
---|
[11] | 216 | protected void visitBefore(DefinitionList node) {
|
---|
[9] | 217 | }
|
---|
| 218 |
|
---|
[11] | 219 | protected void visitAfter(DefinitionList node) {
|
---|
[9] | 220 | }
|
---|
| 221 |
|
---|
[11] | 222 | protected void visitBefore(ExtRule node) {
|
---|
[9] | 223 | }
|
---|
| 224 |
|
---|
[11] | 225 | protected void visitAfter(ExtRule node) {
|
---|
[9] | 226 | }
|
---|
| 227 |
|
---|
[11] | 228 | protected void visitBefore(GlobalCombinator node) {
|
---|
[9] | 229 | }
|
---|
| 230 |
|
---|
[11] | 231 | protected void visitAfter(GlobalCombinator node) {
|
---|
[9] | 232 | }
|
---|
| 233 |
|
---|
[11] | 234 | protected void visitBefore(GroupedSequence node) {
|
---|
[9] | 235 | }
|
---|
| 236 |
|
---|
[11] | 237 | protected void visitAfter(GroupedSequence node) {
|
---|
[9] | 238 | }
|
---|
| 239 |
|
---|
[11] | 240 | protected void visitBefore(HookCombinator node) {
|
---|
[9] | 241 | }
|
---|
| 242 |
|
---|
[11] | 243 | protected void visitAfter(HookCombinator node) {
|
---|
[9] | 244 | }
|
---|
| 245 |
|
---|
[11] | 246 | protected void visitBefore(Import node) {
|
---|
[9] | 247 | }
|
---|
| 248 |
|
---|
[11] | 249 | protected void visitAfter(Import node) {
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | protected void visitBefore(MergeRule node) {
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | protected void visitAfter(MergeRule node) {
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | protected void visitBefore(OptionalSequence node) {
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | protected void visitAfter(OptionalSequence node) {
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | protected void visitBefore(RepeatedSequence node) {
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | protected void visitAfter(RepeatedSequence node) {
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | protected void visitBefore(Rule node) {
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | protected void visitAfter(Rule node) {
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | protected void visitBefore(RuleCombinator node) {
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | protected void visitAfter(RuleCombinator node) {
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | protected void visitBefore(RuleReference node) {
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | protected void visitAfter(RuleReference node) {
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | protected void visitBefore(SectionHeading node) {
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | protected void visitAfter(SectionHeading node) {
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | protected void visitBefore(SingleDefinition node) {
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | protected void visitAfter(SingleDefinition node) {
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | protected void visitBefore(StringRule node) {
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | protected void visitAfter(StringRule node) {
|
---|
| 304 | }
|
---|
| 305 |
|
---|
[9] | 306 | }
|
---|