import ebnf; import emf; create List transform(List s): this.addAll(s.typeSelect(EtsiBnf).createEtsiBnf()) ; create EtsiBnf createEtsiBnf(EtsiBnf bnf): // corebnf.addAll(bnf.corebnf)-> //TODO: checken, ob auskommentierung sinnvoll war extRule.addAll(bnf.extRule)-> imports.addAll(bnf.imports)-> mergeRule.addAll(bnf.mergeRule)-> // package.addAll(bnf.package)-> //TODO: checken, ob auskommentierung sinnvoll war rule.addAll(bnf.rule.createRule(this))-> setName(bnf.name) ; create Rule createRule(Rule r, EtsiBnf bnf): setName(r.name)-> r.definitionList.singleDefinition.size > 0 ? setDefinitionList(r.definitionList.createDefinitionList(bnf, this)) : null-> setRulenumber(r.rulenumber)-> setRulevariant(r.rulevariant) ; create DefinitionList createDefinitionList(DefinitionList d, EtsiBnf bnf, Rule refRule): setSingleDefinition(d.singleDefinition.createSingleDefinition(bnf, refRule)) ; create SingleDefinition createSingleDefinition(SingleDefinition s, EtsiBnf bnf, Rule refRule): let termsList = {}: s.terms.processTerms(termsList, bnf, refRule)-> setTerms(termsList) ; create SingleDefinition createSingleDefinitionLeftRepetition(SingleDefinition s, Rule repeatRule, EtsiBnf bnf, Rule refRule, String id): let termsList = {}: termsList.add(createRuleReferenceTerm(repeatRule, id))-> s.terms.processTerms(termsList, bnf, refRule)-> setTerms(termsList) ; create Atom createAtom(Atom a, EtsiBnf bnf, Rule refRule): a.atomStringRule != null ? setAtomStringRule(a.atomStringRule) : null-> a.atomRuleReference != null ? setAtomRuleReference(a.atomRuleReference) : null ; create GroupedSequence createGroupedSequence(GroupedSequence g, EtsiBnf bnf, Rule refRule): setDefinitionList(g.definitionList) ; create OptionalSequence createOptionalSequence(OptionalSequence g, EtsiBnf bnf, Rule refRule): setDefinitionList(g.definitionList) ; create RepeatedSequence createRepeatedSequence(RepeatedSequence r, EtsiBnf bnf, Rule refRule): setDefinitions(r.definitions)-> setMorethanonce(r.morethanonce) ; // ---------------------------------------------------------------------------------------------------- // non-create rules // ---------------------------------------------------------------------------------------------------- Term processTerms(Term t, List termsList, EtsiBnf bnf, Rule refRule): let newTerm = new Term: t.termAtom != null ? newTerm.setTermAtom(t.termAtom.createAtom(bnf, refRule)) : null-> t.termAtom != null ? termsList.add(newTerm) : null-> t.termGroupedSequence != null ? processGroupedSequence(t.termGroupedSequence, bnf, refRule, termsList) : null-> t.termOptionalSequence != null ? processOptionalSequence(t.termOptionalSequence, bnf, refRule, termsList) : null-> t.termRepeatedSequence != null ? processRepeatedSequence(t.termRepeatedSequence, bnf, refRule, termsList) : null ; GroupedSequence processGroupedSequence(GroupedSequence o, EtsiBnf bnf, Rule refRule, List termsList): listToHash(o.definitionList).existsRule() ? insertRuleReferenceInTermsList(getReplacementRule(refRule, o, bnf), termsList) : insertRuleReferenceInTermsList(addGroupedSequenceReplacementRule(refRule, o, bnf), termsList) ; OptionalSequence processOptionalSequence(OptionalSequence o, EtsiBnf bnf, Rule refRule, List termsList): listToHash(o.definitionList).existsRule() ? insertRuleReferenceInTermsList(getReplacementRule(refRule, o, bnf), termsList) : insertRuleReferenceInTermsList(addOptionalSequenceReplacementRule(refRule, o, bnf), termsList) ; OptionalSequence processRepeatedSequence(RepeatedSequence o, EtsiBnf bnf, Rule refRule, List termsList): listToHash(o.definitions).existsRule() ? insertRuleReferenceInTermsList(getReplacementRule(refRule, o, bnf), termsList) : insertRuleReferenceInTermsList(addRepeatedSequenceReplacementRule(refRule, o, bnf), termsList) ; Rule getReplacementRule(Rule superRule, GroupedSequence o, EtsiBnf bnf): getRule(listToHash(o.definitionList)) ; Rule getReplacementRule(Rule superRule, OptionalSequence o, EtsiBnf bnf): getRule(listToHash(o.definitionList)) ; Rule getReplacementRule(Rule superRule, RepeatedSequence o, EtsiBnf bnf): getRule(listToHash(o.definitions)) ; Rule addRepeatedSequenceReplacementRule(Rule superRule, RepeatedSequence o, EtsiBnf bnf): let repetitionRule = addRepeatedSequenceReplacementRuleWithRepetition(superRule, o, bnf): let plainRule = addRepeatedSequenceReplacementRuleWithoutRepetition(superRule, o, bnf): let mainRule = addRepeatedSequenceReplacementRuleMain(superRule, plainRule, repetitionRule, o, bnf): let hashValue = listToHash(o.definitions): o.morethanonce ? addMoreThanOnceRepetitionRules(repetitionRule, plainRule, mainRule, bnf, hashValue): addNormalRepetitionRule(repetitionRule, bnf, hashValue) ; Rule addNormalRepetitionRule(Rule repetitionRule, EtsiBnf bnf, String hashValue): bnf.rule.add(repetitionRule)-> storeRule(hashValue, repetitionRule)-> repetitionRule ; Rule addMoreThanOnceRepetitionRules(Rule repetitionRule, Rule plainRule, Rule mainRule, EtsiBnf bnf, String hashValue): bnf.rule.add(repetitionRule)-> bnf.rule.add(plainRule)-> bnf.rule.add(mainRule)-> storeRule(hashValue, mainRule)-> mainRule ; create Rule addRepeatedSequenceReplacementRuleWithRepetition(Rule superRule, RepeatedSequence o, EtsiBnf bnf): let emptySingleDefinition = new SingleDefinition: let newDefinitionList = new DefinitionList: let singleDefinitions = {}: let hashValue = listToHash(o.definitions): let rsCopy = new RepeatedSequence: rsCopy.setDefinitions(copyEObjectList(o.definitions))-> rsCopy.setMorethanonce(o.morethanonce)-> setName(superRule.name + "_gen_" + hashValue + "_rep")-> singleDefinitions.addAll(rsCopy.definitions.singleDefinition.createSingleDefinitionLeftRepetition(this, bnf, superRule, this.name))-> singleDefinitions.add(emptySingleDefinition)-> newDefinitionList.setSingleDefinition(singleDefinitions)-> setDefinitionList(newDefinitionList) ; create Rule addRepeatedSequenceReplacementRuleWithoutRepetition(Rule superRule, RepeatedSequence o, EtsiBnf bnf): let singleDefinitions = {}: let newDefinitionList = new DefinitionList: let hashValue = listToHash(o.definitions): let rsCopy = new RepeatedSequence: rsCopy.setDefinitions(copyEObjectList(o.definitions))-> rsCopy.setMorethanonce(o.morethanonce)-> setName(superRule.name + "_gen_" + hashValue + "_plain")-> singleDefinitions.addAll(rsCopy.definitions.singleDefinition.createSingleDefinition(bnf, superRule))-> newDefinitionList.setSingleDefinition(singleDefinitions)-> setDefinitionList(newDefinitionList) ; create Rule this addRepeatedSequenceReplacementRuleMain(Rule superRule, Rule plainRule, Rule repetitionRule, RepeatedSequence o, EtsiBnf bnf): let newDefinitionList = new DefinitionList: let singleDefinitionList = {}: let singleDefinition = new SingleDefinition: let definitionsList = {}: let hashValue = listToHash(o.definitions): this.setName(superRule.name + "_gen_" + hashValue + "_main")-> singleDefinition.terms.add(plainRule.createRuleReferenceTerm(this.name))-> singleDefinition.terms.add(repetitionRule.createRuleReferenceTerm(this.name))-> newDefinitionList.singleDefinition.add(singleDefinition)-> this.setDefinitionList(newDefinitionList) ; create Term this createRuleReferenceTerm(Rule rule, String id): let newAtom = new Atom: let newRuleReference = new RuleReference: newRuleReference.setRuleref(rule)-> newAtom.setAtomRuleReference(newRuleReference)-> this.setTermAtom(newAtom) ; create SingleDefinition createRuleReferenceSingleDefinition(Rule rule, String id): let newTerms = {}: newTerms.add(createRuleReferenceTerm(rule, id))-> setTerms(newTerms) ; create Rule addGroupedSequenceReplacementRule(Rule superRule, GroupedSequence o, EtsiBnf bnf): let newDefinitionList = new DefinitionList: let singleDefinitions = {}: let hashValue = listToHash(o.definitionList): setName(superRule.name + "_gen_" + hashValue + "_group")-> singleDefinitions.addAll(o.definitionList.singleDefinition.createSingleDefinition(bnf, superRule))-> newDefinitionList.setSingleDefinition(singleDefinitions)-> setDefinitionList(newDefinitionList)-> storeRule(hashValue, this)-> bnf.rule.add(this) ; create Rule addOptionalSequenceReplacementRule(Rule superRule, OptionalSequence o, EtsiBnf bnf): let newDefinitionList = new DefinitionList: let emptySingleDefinition = new SingleDefinition: let singleDefinitions = {}: let hashValue = listToHash(o.definitionList): setName(superRule.name + "_gen_" + hashValue + "_opt")-> singleDefinitions.addAll(o.definitionList.singleDefinition.createSingleDefinition(bnf, superRule))-> singleDefinitions.add(emptySingleDefinition)-> newDefinitionList.setSingleDefinition(singleDefinitions)-> setDefinitionList(newDefinitionList)-> storeRule(hashValue, this)-> bnf.rule.add(this) ; Void insertRuleReferenceInTermsList(Rule refRule, List termsList): let newTerm = new Term: let newRuleRef = new RuleReference: let newAtom = new Atom: newRuleRef.setRuleref(refRule)-> newAtom.setAtomRuleReference(newRuleRef)-> newTerm.setTermAtom(newAtom)-> termsList.add(newTerm) ; // ---------------------------------------------------------------------------------------------------- // Java Extensions // ---------------------------------------------------------------------------------------------------- Void dump(String s): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.dump(java.lang.String) ; String definitionListToString(DefinitionList l): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.definitionListToString(de.ugoe.cs.swe.bnftools.ebnf.DefinitionList) ; String listToString(List l): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.listToString(java.util.List) ; String listToString(EObject l): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.eobjectToString(org.eclipse.emf.ecore.EObject) ; String listToHash(List l): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.listToHash(java.util.List) ; Void storeRule(String k, Rule r): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.storeRule(java.lang.String, de.ugoe.cs.swe.bnftools.ebnf.Rule) ; Boolean existsRule(String s): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.existsRule(java.lang.String) ; Rule getRule(String s): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.getRule(java.lang.String) ; EObject copyEObject(EObject o): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.copyEObject(org.eclipse.emf.ecore.EObject) ; List copyEObjectList(List l): JAVA de.ugoe.cs.swe.bnftools.ebnf.javaextensions.SimpleBNFHelper.copyEObjectList(java.util.List) ; // ---------------------------------------------------------------------------------------------------- // duplication rules // ---------------------------------------------------------------------------------------------------- create DefinitionList duplicateDefinitionList(DefinitionList d, EtsiBnf bnf, Rule refRule): setSingleDefinition(d.singleDefinition.duplicateSingleDefinition(bnf, refRule)) ; create SingleDefinition duplicateSingleDefinition(SingleDefinition s, EtsiBnf bnf, Rule refRule): setTerms(s.terms.duplicateTerms(bnf, refRule)) ; create Term duplicateTerms(Term t, EtsiBnf bnf, Rule refRule): t.termAtom != null ? setTermAtom(t.termAtom.duplicateAtom(bnf, refRule)) : null-> t.termGroupedSequence != null ? setTermGroupedSequence(t.termGroupedSequence.duplicateGroupedSequence(bnf, refRule)) : null-> t.termOptionalSequence != null ? setTermOptionalSequence(t.termOptionalSequence.duplicateOptionalSequence(bnf, refRule)) : null-> t.termRepeatedSequence != null ? setTermRepeatedSequence(t.termRepeatedSequence.duplicateRepeatedSequence(bnf, refRule)) : null ; create GroupedSequence duplicateGroupedSequence(GroupedSequence g, EtsiBnf bnf, Rule refRule): setDefinitionList(g.definitionList) ; create OptionalSequence duplicateOptionalSequence(OptionalSequence g, EtsiBnf bnf, Rule refRule): setDefinitionList(g.definitionList) ; create RepeatedSequence duplicateRepeatedSequence(RepeatedSequence r, EtsiBnf bnf, Rule refRule): setDefinitions(r.definitions)-> setMorethanonce(r.morethanonce) ; create Atom duplicateAtom(Atom a, EtsiBnf bnf, Rule refRule): a.atomStringRule != null ? setAtomStringRule(a.atomStringRule) : null-> a.atomRuleReference != null ? setAtomRuleReference(a.atomRuleReference) : null ; // ---------------------------------------------------------------------------------------------------- // Extensions for templates // ---------------------------------------------------------------------------------------------------- Rule firstNonGeneratedRule(EtsiBnf bnf): bnf.rule.selectFirst(e|!e.name.contains("_gen_") ) ;