«IMPORT ebnf» «EXTENSION org::eclipse::xtend::util::stdlib::globalvar» «REM» ========================================================================== «ENDREM» «DEFINE Root FOR EtsiBnf-» «FOREACH rule AS r-» «EXPAND check(r.name) FOR r-» «ENDFOREACH-» «FILE name+".g"-» grammar «name»; options { backtrack = true; memoize = true; } «FOREACH rule AS r-» «IF (getGlobalVar(r.name.toLowerCase()) != null)-» «IF r.name.toLowerCase() == "final"» finalRule: «ELSE» «r.name.toLowerCase()-»: «ENDIF» «ELSE-» «r.name.toUpperCase()-»: «ENDIF-» «EXPAND DefStart FOR r.definitionList-» ; «ENDFOREACH-» «ENDFILE-» «ENDDEFINE» «REM» ========================================================================== «ENDREM» «DEFINE check(String name) FOR emf::EObject» «IF (this.metaType == RuleReference)-» «storeGlobalVar(name.toLowerCase(), name.toLowerCase())» «ELSEIF this.eContents.size != 0-» «EXPAND check(name) FOREACH this.eContents-» «ENDIF-» «ENDDEFINE» «REM» ========================================================================== «ENDREM» «DEFINE OptionalSequenceStart FOR OptionalSequence-» («EXPAND DefStart FOREACH definitionList-»)? «ENDDEFINE» «REM» ========================================================================== «ENDREM» «DEFINE GroupedSequenceStart FOR GroupedSequence-» («EXPAND DefStart FOREACH this.definitionList-») «ENDDEFINE» «REM» ========================================================================== «ENDREM» «DEFINE RepeatedSequenceStart FOR RepeatedSequence-» ( «EXPAND DefStart FOREACH definitions-» «IF this.morethanonce==true-» )+ «ELSE-» )* «ENDIF-» «ENDDEFINE» «REM» ========================================================================== «ENDREM» «DEFINE DefStart FOR DefinitionList-» «FOREACH singleDefinition AS singleDef ITERATOR iter-» «IF !iter.firstIteration-» | «ENDIF-» «FOREACH singleDef.terms AS t-» «IF t.termAtom != null-» «IF t.termAtom.atomStringRule != null-» «IF t.termAtom.atomStringRule.colon.length > 0-» '\"' «ELSE» «IF t.termAtom.atomStringRule.literal == "\\"-» '\\' «ELSEIF t.termAtom.atomStringRule.literal == "'"-» '\'' «ELSE» '«t.termAtom.atomStringRule.literal-»' «ENDIF» «ENDIF» «ELSEIF t.termAtom.atomRuleReference != null-» «IF (getGlobalVar(t.termAtom.atomRuleReference.ruleref.name.toLowerCase()) != null)-» «IF t.termAtom.atomRuleReference.ruleref.name.toLowerCase() == "final"» finalRule «ELSE» «t.termAtom.atomRuleReference.ruleref.name.toLowerCase()-» «ENDIF» «ELSE-» «t.termAtom.atomRuleReference.ruleref.name.toUpperCase()-» «ENDIF-» «ENDIF-» «ELSEIF t.termGroupedSequence != null-» «EXPAND GroupedSequenceStart FOR t.termGroupedSequence-» «ELSEIF t.termOptionalSequence != null-» «EXPAND OptionalSequenceStart FOR t.termOptionalSequence-» «ELSEIF t.termRepeatedSequence != null-» «EXPAND RepeatedSequenceStart FOR t.termRepeatedSequence-» «ENDIF-» «ENDFOREACH-» «ENDFOREACH-» «ENDDEFINE»