source: default/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/Ebnf.xtext @ 13

Last change on this file since 13 was 13, checked in by zeiss, 14 years ago
File size: 3.2 KB
Line 
1grammar de.ugoe.cs.swe.bnftools.Ebnf hidden(WS, ML_COMMENT, 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
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
49
50Import :
51        'import' importURI=STRING
52        ('/' (grammarType='core' | grammarType='package' | grammarType='update'))?
53        ('label:' label=ID)? ';'
54;
55
56Rule:
57        (rulenumber=INT (rulevariant=ID)? '.')?  name=ID  '::=' (definitionList=DefinitionList)? ';'?
58;
59
60ExtRule:
61        (rulenumber=INT (rulevariant=ID)? '.')?  name=ID ('(' ruleext=INT ')') '<-'
62        (elements+=Atom | ')' | ']' | '}' | '|' | '(' | '[' | '{' | '*' | '+')* ';'?
63;
64
65MergeRule:
66        GlobalCombinator
67        | RuleCombinator
68        | HookCombinator
69;
70       
71GlobalCombinator:
72('global' 'combinator:') logic=LOGIC ';'?
73;       
74
75RuleCombinator:
76('rule' 'combinator:' name=ID ) logic=LOGIC ('(' LABEL+=STRING ')')* ';'?
77;
78
79HookCombinator:
80'hook' 'combinator:' name=ID '(' ruleext=INT ')' (logic=LOGIC)? ('(' LABEL+=STRING ')')+ ';'?
81;
82
83DefinitionList:
84        singleDefinition+=SingleDefinition ('|' singleDefinition+=SingleDefinition)*
85;
86
87SingleDefinition:
88        (terms+=Term)+
89;
90
91Term:
92        termAtom=Atom
93        | termGroupedSequence=GroupedSequence
94        | termOptionalSequence=OptionalSequence
95        | termRepeatedSequence=RepeatedSequence
96;
97
98Atom:
99        atomStringRule=StringRule
100        | atomRuleReference=RuleReference
101;
102
103RuleReference:
104        ruleref=[Rule]
105;
106
107StringRule:
108        literal=STRING
109        | colon=COLON
110;
111
112GroupedSequence:
113        '(' definitionList+=DefinitionList ')'
114;
115
116OptionalSequence:
117        '[' definitionList+=DefinitionList ']'
118;
119
120RepeatedSequence:
121        '{' definitions+=DefinitionList '}' morethanonce?='+'?
122;
123
124// -----------------------------------------------------------------------------------------------
125// Lexer Rules
126// -----------------------------------------------------------------------------------------------
127
128terminal ID             : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
129terminal INT            returns ecore::EInt: ('0'..'9')+;
130terminal WS                     : (' '|'\t'|'\r'? '\n')+;
131terminal COLON          : '"' '"' '"';
132terminal STRING         : '"' !('"')* '"' | "'" !("'")*"'";
133terminal SECTIONHEADER: ('a'..'z'|'A'..'Z') ('.'|('0'..'9'))+ (' '|'\t') !('\n'|'\r')* '\r'? '\n';
134terminal SL_COMMENT     : '//' !('\n'|'\r')* ('\r'? '\n')?;
135terminal ML_COMMENT     : '/*' -> '*/';
136//TODO: a more intuitive notation
137terminal LOGIC          : '/and' | '/or' | '/andr' | '/orr' | '/any' | '/together' ;
Note: See TracBrowser for help on using the repository browser.