1 | grammar de.ugoe.cs.swe.bnftools.Ebnf hidden(WS, ML_COMMENT, SL_COMMENT)
|
---|
2 |
|
---|
3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore
|
---|
4 |
|
---|
5 | generate ebnf "http://www.ugoe.de/cs/swe/bnftools/Ebnf"
|
---|
6 |
|
---|
7 | // -----------------------------------------------------------------------------------------------
|
---|
8 | // Parser Rules
|
---|
9 | // -----------------------------------------------------------------------------------------------
|
---|
10 | EtsiBnf:
|
---|
11 | 'grammar' name=ID
|
---|
12 | ( type='/bnf'? ';'
|
---|
13 | (imports+=Import)*
|
---|
14 | (rule+=Rule | sectionheader+=SectionHeading)+
|
---|
15 | )
|
---|
16 | |
|
---|
17 | ( type='/delta' ';'
|
---|
18 | (imports+=Import)*
|
---|
19 | (rule+=Rule | sectionheader+=SectionHeading | extRule+=ExtRule)*
|
---|
20 | )
|
---|
21 | |
|
---|
22 | ( type='/merge' ';'
|
---|
23 | (imports+=Import)*
|
---|
24 | (sectionheader+=SectionHeading | mergeRule+=MergeRule)*
|
---|
25 | )
|
---|
26 | ;
|
---|
27 |
|
---|
28 |
|
---|
29 | SectionHeading:
|
---|
30 | {SectionHeading}
|
---|
31 | sectionHeader=SECTIONHEADER
|
---|
32 | ;
|
---|
33 |
|
---|
34 |
|
---|
35 | Import :
|
---|
36 | 'import' importURI=STRING
|
---|
37 | ('/' (grammarType='core' | grammarType='package' | grammarType='update'))?
|
---|
38 | ('label:' label=ID)? ';'
|
---|
39 | ;
|
---|
40 |
|
---|
41 | Rule:
|
---|
42 | (rulenumber=INT (rulevariant=ID)? '.')? name=ID '::=' (definitionList=DefinitionList)? ';'?
|
---|
43 | ;
|
---|
44 |
|
---|
45 | ExtRule:
|
---|
46 | (rulenumber=INT (rulevariant=ID)? '.')? name=ID ('(' ruleext=INT ')') '<-'
|
---|
47 | (elements+=Atom | ')' | ']' | '}' | '|' | '(' | '[' | '{' | '*' | '+')* ';'?
|
---|
48 | ;
|
---|
49 |
|
---|
50 | MergeRule:
|
---|
51 | GlobalCombinator
|
---|
52 | | RuleCombinator
|
---|
53 | | HookCombinator
|
---|
54 | ;
|
---|
55 |
|
---|
56 | GlobalCombinator:
|
---|
57 | ('global' 'combinator:') logic=LOGIC ';'?
|
---|
58 | ;
|
---|
59 |
|
---|
60 | RuleCombinator:
|
---|
61 | ('rule' 'combinator:' name=ID ) logic=LOGIC ('(' LABEL+=STRING ')')* ';'?
|
---|
62 | ;
|
---|
63 |
|
---|
64 | HookCombinator:
|
---|
65 | 'hook' 'combinator:' name=ID '(' ruleext=INT ')' (logic=LOGIC)? ('(' LABEL+=STRING ')')+ ';'?
|
---|
66 | ;
|
---|
67 |
|
---|
68 | DefinitionList:
|
---|
69 | singleDefinition+=SingleDefinition ('|' singleDefinition+=SingleDefinition)*
|
---|
70 | ;
|
---|
71 |
|
---|
72 | SingleDefinition:
|
---|
73 | (terms+=Term)+
|
---|
74 | ;
|
---|
75 |
|
---|
76 | Term:
|
---|
77 | termAtom=Atom
|
---|
78 | | termGroupedSequence=GroupedSequence
|
---|
79 | | termOptionalSequence=OptionalSequence
|
---|
80 | | termRepeatedSequence=RepeatedSequence
|
---|
81 | ;
|
---|
82 |
|
---|
83 | Atom:
|
---|
84 | atomStringRule=StringRule
|
---|
85 | | atomRuleReference=RuleReference
|
---|
86 | ;
|
---|
87 |
|
---|
88 | RuleReference:
|
---|
89 | ruleref=[Rule]
|
---|
90 | ;
|
---|
91 |
|
---|
92 | StringRule:
|
---|
93 | literal=STRING
|
---|
94 | | colon=COLON
|
---|
95 | ;
|
---|
96 |
|
---|
97 | GroupedSequence:
|
---|
98 | '(' definitionList+=DefinitionList ')'
|
---|
99 | ;
|
---|
100 |
|
---|
101 | OptionalSequence:
|
---|
102 | '[' definitionList+=DefinitionList ']'
|
---|
103 | ;
|
---|
104 |
|
---|
105 | RepeatedSequence:
|
---|
106 | '{' definitions+=DefinitionList '}' morethanonce?='+'?
|
---|
107 | ;
|
---|
108 |
|
---|
109 | // -----------------------------------------------------------------------------------------------
|
---|
110 | // Lexer Rules
|
---|
111 | // -----------------------------------------------------------------------------------------------
|
---|
112 |
|
---|
113 | terminal ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
|
---|
114 | terminal INT returns ecore::EInt: ('0'..'9')+;
|
---|
115 | terminal WS : (' '|'\t'|'\r'? '\n')+;
|
---|
116 | terminal COLON : '"' '"' '"';
|
---|
117 | terminal STRING : '"' !('"')* '"' | "'" !("'")*"'";
|
---|
118 | terminal SECTIONHEADER: ('a'..'z'|'A'..'Z') ('.'|('0'..'9'))+ (' '|'\t') !('\n'|'\r')* '\r'? '\n';
|
---|
119 | terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?;
|
---|
120 | terminal ML_COMMENT : '/*' -> '*/';
|
---|
121 | //TODO: a more intuitive notation
|
---|
122 | terminal LOGIC : '/and' | '/or' | '/andr' | '/orr' | '/any' | '/together' ;
|
---|