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

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