Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4651bdd85e0c9e50ad8a838d76311507d836db5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*******************************************************************************
 * Copyright (c) 2005, 2007 committers of openArchitectureWare and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     committers of openArchitectureWare - initial API and implementation
 *******************************************************************************/
package org.eclipse.internal.xpand2.parser;

import org.antlr.runtime.CommonToken;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.TokenStream;
import org.eclipse.internal.xpand2.ast.Advice;
import org.eclipse.internal.xpand2.ast.Definition;
import org.eclipse.internal.xpand2.ast.ErrorStatement;
import org.eclipse.internal.xpand2.ast.ExpandStatement;
import org.eclipse.internal.xpand2.ast.ExpressionStatement;
import org.eclipse.internal.xpand2.ast.FileStatement;
import org.eclipse.internal.xpand2.ast.ForEachStatement;
import org.eclipse.internal.xpand2.ast.IfStatement;
import org.eclipse.internal.xpand2.ast.ImportDeclaration;
import org.eclipse.internal.xpand2.ast.LetStatement;
import org.eclipse.internal.xpand2.ast.ProtectStatement;
import org.eclipse.internal.xpand2.ast.Statement;
import org.eclipse.internal.xpand2.ast.Template;
import org.eclipse.internal.xtend.expression.ast.DeclaredParameter;
import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.expression.ast.FeatureCall;
import org.eclipse.internal.xtend.expression.ast.GlobalVarExpression;
import org.eclipse.internal.xtend.expression.ast.SyntaxElement;

public class XpandLocationAddingParser extends XpandParser {

	XpandLocationAddingParser(TokenStream stream) {
		super(stream, new XpandFactory("nofile"));
	}

	XpandLocationAddingParser(TokenStream stream, String fileName) {
		super(stream, new XpandFactory(fileName));
	}

	private static <T extends SyntaxElement> T addLocation(int[] startAndLine,
			T ele, int end) {
		if (ele != null) {
			ele.setStart(startAndLine[0]);
			ele.setLine(startAndLine[1]);
			ele.setEnd(end);
		}
		return ele;
	}

	private int[] start() {
		CommonToken t = (CommonToken) input.LT(1);
		if (t == null) {
			return new int[] { 0, 0 };
		}
		return new int[] { t.getStartIndex(), t.getLine() };
	}

	private int end() {
		CommonToken t = (CommonToken) input.LT(-1);
		if (t == null) {
			return -1;
		}
		return t.getStopIndex() + 1;
	}

	@Override
	public void reportError(RecognitionException e) {
		System.out.println(super.getErrorMessage(e, tokenNames));
		throw new RuntimeException(e);
	}

	@Override
	public Expression additiveExpression() throws RecognitionException {
		return addLocation(start(), super.additiveExpression(), end());
	}

	@Override
	public Expression andExpression() throws RecognitionException {
		return addLocation(start(), super.andExpression(), end());
	}

	@Override
	public ImportDeclaration anExtensionImport() throws RecognitionException {
		return addLocation(start(), super.anExtensionImport(), end());
	}

	@Override
	public ImportDeclaration anImport() throws RecognitionException {
		return addLocation(start(), super.anImport(), end());
	}

	@Override
	public Advice around() throws RecognitionException {
		return addLocation(start(), super.around(), end());
	}

	@Override
	public Expression booleanLiteral() throws RecognitionException {
		return addLocation(start(), super.booleanLiteral(), end());
	}

	@Override
	public Expression castedExpression() throws RecognitionException {
		return addLocation(start(), super.castedExpression(), end());
	}

	@Override
	public Expression chainExpression() throws RecognitionException {
		return addLocation(start(), super.chainExpression(), end());
	}

	@Override
	public FeatureCall collectionExpression() throws RecognitionException {
		return addLocation(start(), super.collectionExpression(), end());
	}

	@Override
	public org.eclipse.internal.xtend.expression.ast.Identifier collectionType()
			throws RecognitionException {
		return addLocation(start(), super.collectionType(), end());
	}

	@Override
	public Expression constructorCall() throws RecognitionException {
		return addLocation(start(), super.constructorCall(), end());
	}

	@Override
	public DeclaredParameter declaredParameter() throws RecognitionException {
		return addLocation(start(), super.declaredParameter(), end());
	}

	@Override
	public Definition define() throws RecognitionException {
		return addLocation(start(), super.define(), end());
	}

	@Override
	public org.eclipse.internal.xtend.expression.ast.Identifier definitionName()
			throws RecognitionException {
		return addLocation(start(), super.definitionName(), end());
	}

	@Override
	public IfStatement elseIfStatement() throws RecognitionException {
		return addLocation(start(), super.elseIfStatement(), end());
	}

	@Override
	public IfStatement elseStatement() throws RecognitionException {
		return addLocation(start(), super.elseStatement(), end());
	}

	@Override
	public ErrorStatement errorStatement() throws RecognitionException {
		return addLocation(start(), super.errorStatement(), end());
	}

	@Override
	public ExpandStatement expandStatement() throws RecognitionException {
		return addLocation(start(), super.expandStatement(), end());
	}

	@Override
	public Expression expression() throws RecognitionException {
		return addLocation(start(), super.expression(), end());
	}

	@Override
	public ExpressionStatement expressionStmt() throws RecognitionException {
		return addLocation(start(), super.expressionStmt(), end());
	}

	@Override
	public FeatureCall featureCall() throws RecognitionException {
		return addLocation(start(), super.featureCall(), end());
	}

	@Override
	public FileStatement fileStatement() throws RecognitionException {
		return addLocation(start(), super.fileStatement(), end());
	}

	@Override
	public ForEachStatement foreachStatement() throws RecognitionException {
		return addLocation(start(), super.foreachStatement(), end());
	}

	@Override
	public GlobalVarExpression globalVarExpression()
			throws RecognitionException {
		return addLocation(start(), super.globalVarExpression(), end());
	}

	@Override
	public org.eclipse.internal.xtend.expression.ast.Identifier identifier()
			throws RecognitionException {
		return addLocation(start(), super.identifier(), end());
	}

	@Override
	public Expression ifExpression() throws RecognitionException {
		return addLocation(start(), super.ifExpression(), end());
	}

	@Override
	public IfStatement ifStatement() throws RecognitionException {
		return addLocation(start(), super.ifStatement(), end());
	}

	@Override
	public Expression impliesExpression() throws RecognitionException {
		return addLocation(start(), super.impliesExpression(), end());
	}

	@Override
	public Expression infixExpression() throws RecognitionException {
		return addLocation(start(), super.infixExpression(), end());
	}

	@Override
	public Expression letExpression() throws RecognitionException {
		return addLocation(start(), super.letExpression(), end());
	}

	@Override
	public LetStatement letStatement() throws RecognitionException {
		return addLocation(start(), super.letStatement(), end());
	}

	@Override
	public Expression listLiteral() throws RecognitionException {
		return addLocation(start(), super.listLiteral(), end());
	}

	@Override
	public Expression multiplicativeExpression() throws RecognitionException {
		return addLocation(start(), super.multiplicativeExpression(), end());
	}

	@Override
	public Expression nullLiteral() throws RecognitionException {
		return addLocation(start(), super.nullLiteral(), end());
	}

	@Override
	public Expression numberLiteral() throws RecognitionException {
		return addLocation(start(), super.numberLiteral(), end());
	}

	@Override
	public Expression orExpression() throws RecognitionException {
		return addLocation(start(), super.orExpression(), end());
	}

	@Override
	public Expression paranthesizedExpression() throws RecognitionException {
		return addLocation(start(), super.paranthesizedExpression(), end());
	}

	@Override
	public org.eclipse.internal.xtend.expression.ast.Identifier pointcut()
			throws RecognitionException {
		return addLocation(start(), super.pointcut(), end());
	}

	@Override
	public Expression primaryExpression() throws RecognitionException {
		return addLocation(start(), super.primaryExpression(), end());
	}

	@Override
	public ProtectStatement protectStatement() throws RecognitionException {
		return addLocation(start(), super.protectStatement(), end());
	}

	@Override
	public Expression relationalExpression() throws RecognitionException {
		return addLocation(start(), super.relationalExpression(), end());
	}

	@Override
	public Statement simpleStatement() throws RecognitionException {
		return addLocation(start(), super.simpleStatement(), end());
	}

	@Override
	public org.eclipse.internal.xtend.expression.ast.Identifier simpleType()
			throws RecognitionException {
		return addLocation(start(), super.simpleType(), end());
	}

	@Override
	public Statement statement() throws RecognitionException {
		return addLocation(start(), super.statement(), end());
	}

	@Override
	public Expression switchExpression() throws RecognitionException {
		return addLocation(start(), super.switchExpression(), end());
	}

	@Override
	public Template template() throws RecognitionException {
		return addLocation(start(), super.template(), end());
	}

	@Override
	public Statement text() throws RecognitionException {
		return addLocation(start(), super.text(), end());
	}

	@Override
	public org.eclipse.internal.xtend.expression.ast.Identifier type()
			throws RecognitionException {
		return addLocation(start(), super.type(), end());
	}

	@Override
	public Expression unaryExpression() throws RecognitionException {
		return addLocation(start(), super.unaryExpression(), end());
	}

}

Back to the top