grammar de.ugoe.cs.swe.bnftools.Ebnf hidden(WS, ML_COMMENT, SL_COMMENT) import "http://www.eclipse.org/emf/2002/Ecore" as ecore generate ebnf "http://www.ugoe.de/cs/swe/bnftools/Ebnf" // ----------------------------------------------------------------------------------------------- // Parser Rules // ----------------------------------------------------------------------------------------------- EtsiBnf: 'grammar' name=ID ( type='/bnf'? ';' (importSection=ImportSection)? (bnfEntry+=BnfEntry)+ ) | ( type='/delta' ';' (importSection=ImportSection)? (deltaEntry+=DeltaEntry)* ) | ( type='/merge' ';' (importSection=ImportSection)? (mergeEntry+=MergeEntry)* ) ; ImportSection: (imports+=Import)+ ; BnfEntry: sectionheader=SectionHeading | rule=Rule ; DeltaEntry: rule=Rule | sectionheader=SectionHeading | extRule=ExtRule ; MergeEntry: sectionheader=SectionHeading | mergeRule=MergeRule ; SectionHeading: {SectionHeading} sectionHeader=SECTIONHEADER ; Import : 'import' importURI=STRING ('/' (grammarType='core' | grammarType='package' | grammarType='update'))? ('label:' label=ID)? ';' ; //Import: 'import' importedNamespace=FqnWithWildCard; //FqnWithWildCard: Fqn('.*')? ';'; //Fqn:ID('.'ID)*; Rule: (rulenumber=INT (rulevariant=ID)? '.')? name=ID '::=' (definitionList=DefinitionList)? ';'? ; ExtRule: (rulenumber=INT (rulevariant=ID)? '.')? name=ID ('(' ruleext=INT ')') '<-' (elements+=Atom | ')' | ']' | '}' | '|' | '(' | '[' | '{' | '*' | '+')* ';'? ; MergeRule: GlobalCombinator | RuleCombinator | HookCombinator ; GlobalCombinator: ('global' 'combinator:') logic=LOGIC ';'? ; RuleCombinator: ('rule' 'combinator:' name=ID ) logic=LOGIC ('(' LABEL+=STRING ')')* ';'? ; HookCombinator: 'hook' 'combinator:' name=ID '(' ruleext=INT ')' (logic=LOGIC)? ('(' LABEL+=STRING ')')+ ';'? ; DefinitionList: singleDefinition+=SingleDefinition ('|' singleDefinition+=SingleDefinition)* ; SingleDefinition: (terms+=Term)+ ; Term: termAtom=Atom | termGroupedSequence=GroupedSequence | termOptionalSequence=OptionalSequence | termRepeatedSequence=RepeatedSequence ; Atom: atomStringRule=StringRule | atomRuleReference=RuleReference ; RuleReference: ruleref=[Rule] ; StringRule: literal=STRING | colon=COLON ; GroupedSequence: '(' definitionList+=DefinitionList ')' ; OptionalSequence: '[' definitionList+=DefinitionList ']' ; RepeatedSequence: '{' definitions+=DefinitionList '}' (morethanonce?='+'? | range=RepeatRange?) ; RepeatRange: '#' '(' from=INT ',' to=INT ')' ; // ----------------------------------------------------------------------------------------------- // Lexer Rules // ----------------------------------------------------------------------------------------------- terminal ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ; terminal INT returns ecore::EInt: ('0'..'9')+; terminal WS : (' '|'\t'|'\r'? '\n')+; terminal COLON : '"' '"' '"'; terminal STRING : '"' !('"')* '"' | "'" !("'")*"'"; terminal SECTIONHEADER: ('a'..'z'|'A'..'Z') ('.'|('0'..'9'))+ (' '|'\t') !('\n'|'\r')* '\r'? '\n'; terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?; terminal ML_COMMENT : '/*' -> '*/'; //TODO: a more intuitive notation terminal LOGIC : '/and' | '/or' | '/andr' | '/orr' | '/any' | '/together' ;