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 | (importSection=ImportSection)?
|
---|
14 | (bnfEntry+=BnfEntry)+
|
---|
15 | )
|
---|
16 | |
|
---|
17 | ( type='/delta' ';'
|
---|
18 | (importSection=ImportSection)?
|
---|
19 | (deltaEntry+=DeltaEntry)*
|
---|
20 | )
|
---|
21 | |
|
---|
22 | ( type='/merge' ';'
|
---|
23 | (importSection=ImportSection)?
|
---|
24 | (mergeEntry+=MergeEntry)*
|
---|
25 | )
|
---|
26 | ;
|
---|
27 |
|
---|
28 | ImportSection:
|
---|
29 | (imports+=Import)+
|
---|
30 | ;
|
---|
31 |
|
---|
32 | BnfEntry:
|
---|
33 | sectionheader=SectionHeading | rule=Rule
|
---|
34 | ;
|
---|
35 |
|
---|
36 | DeltaEntry:
|
---|
37 | rule=Rule | sectionheader=SectionHeading | extRule=ExtRule
|
---|
38 | ;
|
---|
39 |
|
---|
40 | MergeEntry:
|
---|
41 | sectionheader=SectionHeading | mergeRule=MergeRule
|
---|
42 | ;
|
---|
43 |
|
---|
44 | SectionHeading:
|
---|
45 | {SectionHeading}
|
---|
46 | sectionHeader=SECTIONHEADER
|
---|
47 | ;
|
---|
48 |
|
---|
49 |
|
---|
50 | Import :
|
---|
51 | 'import' importURI=STRING
|
---|
52 | ('/' (grammarType='core' | grammarType='package' | grammarType='update'))?
|
---|
53 | ('label:' label=ID)? ';'
|
---|
54 | ;
|
---|
55 |
|
---|
56 | //Import: 'import' importedNamespace=FqnWithWildCard;
|
---|
57 | //FqnWithWildCard: Fqn('.*')? ';';
|
---|
58 | //Fqn:ID('.'ID)*;
|
---|
59 |
|
---|
60 |
|
---|
61 | Rule:
|
---|
62 | (rulenumber=INT (rulevariant=ID)? '.')? name=ID '::=' (definitionList=DefinitionList)? ';'?
|
---|
63 | ;
|
---|
64 |
|
---|
65 | ExtRule:
|
---|
66 | (rulenumber=INT (rulevariant=ID)? '.')? name=ID ('(' ruleext=INT ')') '<-'
|
---|
67 | (elements+=Atom | ')' | ']' | '}' | '|' | '(' | '[' | '{' | '*' | '+')* ';'?
|
---|
68 | ;
|
---|
69 |
|
---|
70 | MergeRule:
|
---|
71 | GlobalCombinator
|
---|
72 | | RuleCombinator
|
---|
73 | | HookCombinator
|
---|
74 | ;
|
---|
75 |
|
---|
76 | GlobalCombinator:
|
---|
77 | ('global' 'combinator:') logic=LOGIC ';'?
|
---|
78 | ;
|
---|
79 |
|
---|
80 | RuleCombinator:
|
---|
81 | ('rule' 'combinator:' name=ID ) logic=LOGIC ('(' LABEL+=STRING ')')* ';'?
|
---|
82 | ;
|
---|
83 |
|
---|
84 | HookCombinator:
|
---|
85 | 'hook' 'combinator:' name=ID '(' ruleext=INT ')' (logic=LOGIC)? ('(' LABEL+=STRING ')')+ ';'?
|
---|
86 | ;
|
---|
87 |
|
---|
88 | DefinitionList:
|
---|
89 | singleDefinition+=SingleDefinition ('|' singleDefinition+=SingleDefinition)*
|
---|
90 | ;
|
---|
91 |
|
---|
92 | SingleDefinition:
|
---|
93 | (terms+=Term)+
|
---|
94 | ;
|
---|
95 |
|
---|
96 | Term:
|
---|
97 | termAtom=Atom
|
---|
98 | | termGroupedSequence=GroupedSequence
|
---|
99 | | termOptionalSequence=OptionalSequence
|
---|
100 | | termRepeatedSequence=RepeatedSequence
|
---|
101 | ;
|
---|
102 |
|
---|
103 | Atom:
|
---|
104 | atomStringRule=StringRule
|
---|
105 | | atomRuleReference=RuleReference
|
---|
106 | ;
|
---|
107 |
|
---|
108 | RuleReference:
|
---|
109 | ruleref=[Rule]
|
---|
110 | ;
|
---|
111 |
|
---|
112 | StringRule:
|
---|
113 | literal=STRING
|
---|
114 | | colon=COLON
|
---|
115 | ;
|
---|
116 |
|
---|
117 | GroupedSequence:
|
---|
118 | '(' definitionList+=DefinitionList ')'
|
---|
119 | ;
|
---|
120 |
|
---|
121 | OptionalSequence:
|
---|
122 | '[' definitionList+=DefinitionList ']'
|
---|
123 | ;
|
---|
124 |
|
---|
125 | RepeatedSequence:
|
---|
126 | '{' definitions+=DefinitionList '}' morethanonce?='+'?
|
---|
127 | ;
|
---|
128 |
|
---|
129 | // -----------------------------------------------------------------------------------------------
|
---|
130 | // Lexer Rules
|
---|
131 | // -----------------------------------------------------------------------------------------------
|
---|
132 |
|
---|
133 | terminal ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
|
---|
134 | terminal INT returns ecore::EInt: ('0'..'9')+;
|
---|
135 | terminal WS : (' '|'\t'|'\r'? '\n')+;
|
---|
136 | terminal COLON : '"' '"' '"';
|
---|
137 | terminal STRING : '"' !('"')* '"' | "'" !("'")*"'";
|
---|
138 | terminal SECTIONHEADER: ('a'..'z'|'A'..'Z') ('.'|('0'..'9'))+ (' '|'\t') !('\n'|'\r')* '\r'? '\n';
|
---|
139 | terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?;
|
---|
140 | terminal ML_COMMENT : '/*' -> '*/';
|
---|
141 | //TODO: a more intuitive notation
|
---|
142 | terminal LOGIC : '/and' | '/or' | '/andr' | '/orr' | '/any' | '/together' ;
|
---|