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'? ';' (imports+=Import)* (rule+=Rule | sectionheader+=SectionHeading)+ ) | ( type='/delta' ';' (imports+=Import)* (rule+=Rule | sectionheader+=SectionHeading | extRule+=ExtRule)* ) | ( type='/merge' ';' (imports+=Import)* (sectionheader+=SectionHeading | mergeRule+=MergeRule)* ) ; SectionHeading: {SectionHeading} sectionHeader=SECTIONHEADER ; Import : 'import' importURI=STRING ('/' (grammarType='core' | grammarType='package' | grammarType='update'))? ('label:' label=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?='+'? ; // ----------------------------------------------------------------------------------------------- // 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' ;