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 | Rule:
|
---|
57 | (rulenumber=INT (rulevariant=ID)? '.')? name=ID '::=' (definitionList=DefinitionList)? ';'?
|
---|
58 | ;
|
---|
59 |
|
---|
60 | ExtRule:
|
---|
61 | (rulenumber=INT (rulevariant=ID)? '.')? name=ID ('(' ruleext=INT ')') '<-'
|
---|
62 | (elements+=Atom | ')' | ']' | '}' | '|' | '(' | '[' | '{' | '*' | '+')* ';'?
|
---|
63 | ;
|
---|
64 |
|
---|
65 | MergeRule:
|
---|
66 | GlobalCombinator
|
---|
67 | | RuleCombinator
|
---|
68 | | HookCombinator
|
---|
69 | ;
|
---|
70 |
|
---|
71 | GlobalCombinator:
|
---|
72 | ('global' 'combinator:') logic=LOGIC ';'?
|
---|
73 | ;
|
---|
74 |
|
---|
75 | RuleCombinator:
|
---|
76 | ('rule' 'combinator:' name=ID ) logic=LOGIC ('(' LABEL+=STRING ')')* ';'?
|
---|
77 | ;
|
---|
78 |
|
---|
79 | HookCombinator:
|
---|
80 | 'hook' 'combinator:' name=ID '(' ruleext=INT ')' (logic=LOGIC)? ('(' LABEL+=STRING ')')+ ';'?
|
---|
81 | ;
|
---|
82 |
|
---|
83 | DefinitionList:
|
---|
84 | singleDefinition+=SingleDefinition ('|' singleDefinition+=SingleDefinition)*
|
---|
85 | ;
|
---|
86 |
|
---|
87 | SingleDefinition:
|
---|
88 | (terms+=Term)+
|
---|
89 | ;
|
---|
90 |
|
---|
91 | Term:
|
---|
92 | termAtom=Atom
|
---|
93 | | termGroupedSequence=GroupedSequence
|
---|
94 | | termOptionalSequence=OptionalSequence
|
---|
95 | | termRepeatedSequence=RepeatedSequence
|
---|
96 | ;
|
---|
97 |
|
---|
98 | Atom:
|
---|
99 | atomStringRule=StringRule
|
---|
100 | | atomRuleReference=RuleReference
|
---|
101 | ;
|
---|
102 |
|
---|
103 | RuleReference:
|
---|
104 | ruleref=[Rule]
|
---|
105 | ;
|
---|
106 |
|
---|
107 | StringRule:
|
---|
108 | literal=STRING
|
---|
109 | | colon=COLON
|
---|
110 | ;
|
---|
111 |
|
---|
112 | GroupedSequence:
|
---|
113 | '(' definitionList+=DefinitionList ')'
|
---|
114 | ;
|
---|
115 |
|
---|
116 | OptionalSequence:
|
---|
117 | '[' definitionList+=DefinitionList ']'
|
---|
118 | ;
|
---|
119 |
|
---|
120 | RepeatedSequence:
|
---|
121 | '{' definitions+=DefinitionList '}' morethanonce?='+'?
|
---|
122 | ;
|
---|
123 |
|
---|
124 | // -----------------------------------------------------------------------------------------------
|
---|
125 | // Lexer Rules
|
---|
126 | // -----------------------------------------------------------------------------------------------
|
---|
127 |
|
---|
128 | terminal ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
|
---|
129 | terminal INT returns ecore::EInt: ('0'..'9')+;
|
---|
130 | terminal WS : (' '|'\t'|'\r'? '\n')+;
|
---|
131 | terminal COLON : '"' '"' '"';
|
---|
132 | terminal STRING : '"' !('"')* '"' | "'" !("'")*"'";
|
---|
133 | terminal SECTIONHEADER: ('a'..'z'|'A'..'Z') ('.'|('0'..'9'))+ (' '|'\t') !('\n'|'\r')* '\r'? '\n';
|
---|
134 | terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?;
|
---|
135 | terminal ML_COMMENT : '/*' -> '*/';
|
---|
136 | //TODO: a more intuitive notation
|
---|
137 | terminal LOGIC : '/and' | '/or' | '/andr' | '/orr' | '/any' | '/together' ;
|
---|