source: default/v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/EBNF.xtext @ 98

Last change on this file since 98 was 98, checked in by phdmakk, 8 years ago

+ added support for opaque comments in grammar

File size: 3.4 KB
Line 
1grammar de.ugoe.cs.swe.bnftools.Ebnf hidden(WS, SL_COMMENT)
2
3import "http://www.eclipse.org/emf/2002/Ecore" as ecore
4
5generate ebnf "http://www.ugoe.de/cs/swe/bnftools/Ebnf"
6
7// -----------------------------------------------------------------------------------------------
8// Parser Rules
9// -----------------------------------------------------------------------------------------------
10EtsiBnf:
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
28ImportSection:
29        (imports+=Import)+
30;
31
32BnfEntry:
33        sectionheader=SectionHeading | rule=Rule | comment=Comment
34;
35
36DeltaEntry:
37        rule=Rule | sectionheader=SectionHeading | extRule=ExtRule
38;
39
40MergeEntry:
41        sectionheader=SectionHeading | mergeRule=MergeRule
42;
43
44SectionHeading:
45        {SectionHeading}
46        sectionHeader=SECTIONHEADER
47;
48
49Comment:
50        {Comment}
51        content=ML_COMMENT
52;
53
54
55Import :
56        'import' importURI=STRING
57        ('/' (grammarType='core' | grammarType='package' | grammarType='update'))?
58        ('label:' label=ID)? ';'
59;
60
61//Import: 'import' importedNamespace=FqnWithWildCard;
62//FqnWithWildCard: Fqn('.*')? ';';
63//Fqn:ID('.'ID)*;
64
65
66Rule:
67        (rulenumber=INT (rulevariant=ID)? '.')?  name=ID  '::=' (definitionList=DefinitionList)? ';'?
68;
69
70ExtRule:
71        (rulenumber=INT (rulevariant=ID)? '.')?  name=ID ('(' ruleext=INT ')') '<-'
72        (elements+=Atom | ')' | ']' | '}' | '|' | '(' | '[' | '{' | '*' | '+')* ';'?
73;
74
75MergeRule:
76        GlobalCombinator
77        | RuleCombinator
78        | HookCombinator
79;
80       
81GlobalCombinator:
82('global' 'combinator:') logic=LOGIC ';'?
83;       
84
85RuleCombinator:
86('rule' 'combinator:' name=ID ) logic=LOGIC ('(' LABEL+=STRING ')')* ';'?
87;
88
89HookCombinator:
90'hook' 'combinator:' name=ID '(' ruleext=INT ')' (logic=LOGIC)? ('(' LABEL+=STRING ')')+ ';'?
91;
92
93DefinitionList:
94        singleDefinition+=SingleDefinition ('|' singleDefinition+=SingleDefinition)*
95;
96
97SingleDefinition:
98        (terms+=Term)+
99;
100
101Term:
102        termAtom=Atom
103        | termGroupedSequence=GroupedSequence
104        | termOptionalSequence=OptionalSequence
105        | termRepeatedSequence=RepeatedSequence
106;
107
108Atom:
109        atomStringRule=StringRule
110        | atomRuleReference=RuleReference
111;
112
113RuleReference:
114        ruleref=[Rule]
115;
116
117StringRule:
118        literal=STRING
119        | colon=COLON
120;
121
122GroupedSequence:
123        '(' definitionList+=DefinitionList ')'
124;
125
126OptionalSequence:
127        '[' definitionList+=DefinitionList ']'
128;
129
130RepeatedSequence:
131        '{' definitions+=DefinitionList '}' (morethanonce?='+'? | range=RepeatRange?)
132;
133
134RepeatRange:
135        '#' '(' from=INT ',' to=INT ')'
136;
137
138// -----------------------------------------------------------------------------------------------
139// Lexer Rules
140// -----------------------------------------------------------------------------------------------
141
142terminal ID             : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
143terminal INT            returns ecore::EInt: ('0'..'9')+;
144terminal WS                     : (' '|'\t'|'\r'? '\n')+;
145terminal COLON          : '"' '"' '"';
146terminal STRING         : '"' !('"')* '"' | "'" !("'")*"'";
147terminal SECTIONHEADER: ('a'..'z'|'A'..'Z') ('.'|('0'..'9'))+ (' '|'\t') !('\n'|'\r')* '\r'? '\n';
148terminal SL_COMMENT     : '//' !('\n'|'\r')* ('\r'? '\n')?;
149terminal ML_COMMENT     : '/*' -> '*/';
150//TODO: a more intuitive notation
151terminal LOGIC          : '/and' | '/or' | '/andr' | '/orr' | '/any' | '/together' ;
Note: See TracBrowser for help on using the repository browser.