source: default/trunk/de.ugoe.cs.swe.bnftools.ebnf.generator/src/templates/Antlr3.xpt @ 5

Last change on this file since 5 was 5, checked in by zeiss, 14 years ago
File size: 3.1 KB
Line 
1«IMPORT ebnf»
2«EXTENSION org::eclipse::xtend::util::stdlib::globalvar»
3
4«REM» ========================================================================== «ENDREM»
5
6«DEFINE Root FOR EtsiBnf-»
7        «FOREACH rule AS r-»
8                «EXPAND check(r.name) FOR r-»
9        «ENDFOREACH-»
10       
11        «FILE name+".g"-»
12                grammar «name»;
13               
14                options {
15                        backtrack = true;
16                        memoize = true;
17                }
18               
19                «FOREACH rule AS r-»
20                        «IF (getGlobalVar(r.name.toLowerCase()) != null)-»
21                                «IF r.name.toLowerCase() == "final"»
22                                        finalRule:
23                                «ELSE»
24                                        «r.name.toLowerCase()-»:
25                                «ENDIF»
26                        «ELSE-»
27                                «r.name.toUpperCase()-»:
28                        «ENDIF-»
29                        «EXPAND DefStart FOR r.definitionList-»
30                                ;
31
32                «ENDFOREACH-»
33        «ENDFILE-»
34«ENDDEFINE»
35
36«REM» ========================================================================== «ENDREM»
37
38«DEFINE check(String name) FOR emf::EObject»
39        «IF (this.metaType == RuleReference)-»
40                «storeGlobalVar(name.toLowerCase(), name.toLowerCase())»
41        «ELSEIF this.eContents.size != 0-»
42                «EXPAND check(name) FOREACH this.eContents-»
43        «ENDIF-»
44«ENDDEFINE»
45
46«REM» ========================================================================== «ENDREM»
47
48«DEFINE OptionalSequenceStart FOR OptionalSequence-»
49        («EXPAND DefStart FOREACH definitionList-»)?
50«ENDDEFINE»
51
52«REM» ========================================================================== «ENDREM»
53
54«DEFINE GroupedSequenceStart FOR GroupedSequence-»
55        («EXPAND DefStart FOREACH this.definitionList-»)
56«ENDDEFINE»
57
58«REM» ========================================================================== «ENDREM»
59
60«DEFINE RepeatedSequenceStart FOR RepeatedSequence-»
61        (
62        «EXPAND DefStart FOREACH definitions-»
63        «IF this.morethanonce==true-»
64                )+
65        «ELSE-»
66                )*
67        «ENDIF-»
68«ENDDEFINE»
69
70«REM» ========================================================================== «ENDREM»
71
72«DEFINE DefStart FOR DefinitionList-»
73        «FOREACH singleDefinition AS singleDef ITERATOR iter-»
74                «IF !iter.firstIteration-» | «ENDIF-»
75               
76                «FOREACH singleDef.terms AS t-»
77                        «IF t.termAtom != null-»
78                                «IF t.termAtom.atomStringRule != null-»
79                                        «IF t.termAtom.atomStringRule.colon.length > 0-»
80                                        '\"'
81                                        «ELSE»
82                                                «IF t.termAtom.atomStringRule.literal == "\\"-»
83                                                        '\\'
84                                                «ELSEIF t.termAtom.atomStringRule.literal == "'"-»
85                                                        '\''
86                                                «ELSE»
87                                                        '«t.termAtom.atomStringRule.literal-»'
88                                                «ENDIF»
89                                        «ENDIF»
90                                «ELSEIF t.termAtom.atomRuleReference != null-»
91                                        «IF (getGlobalVar(t.termAtom.atomRuleReference.ruleref.name.toLowerCase()) != null)-»
92                                                «IF t.termAtom.atomRuleReference.ruleref.name.toLowerCase() == "final"»
93                                                        finalRule
94                                                «ELSE»
95                                                        «t.termAtom.atomRuleReference.ruleref.name.toLowerCase()-»
96                                                «ENDIF»
97                                        «ELSE-»
98                                                «t.termAtom.atomRuleReference.ruleref.name.toUpperCase()-»
99                                        «ENDIF-»
100                                «ENDIF-»
101                        «ELSEIF t.termGroupedSequence != null-»
102                                «EXPAND GroupedSequenceStart FOR t.termGroupedSequence-»
103                        «ELSEIF t.termOptionalSequence != null-»
104                                «EXPAND OptionalSequenceStart FOR t.termOptionalSequence-»
105                        «ELSEIF t.termRepeatedSequence != null-»
106                                «EXPAND RepeatedSequenceStart FOR t.termRepeatedSequence-»
107                        «ENDIF-»
108                «ENDFOREACH-»
109        «ENDFOREACH-»
110«ENDDEFINE»
Note: See TracBrowser for help on using the repository browser.