Skip to content

Commit 7e6d696

Browse files
committed
[EGL] Fix some parse problems reporting incorrect position
1 parent 961692f commit 7e6d696

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

plugins/org.eclipse.epsilon.egl.engine/src/org/eclipse/epsilon/egl/internal/EglModule.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,11 @@ else if (internal instanceof EglRuntimeException) {
206206

207207
@Override
208208
public List<ParseProblem> getParseProblems() {
209-
parseProblems.addAll(eglParser.getParseProblems());
209+
if (!eglParser.getParseProblems().isEmpty()) {
210+
return eglParser.getParseProblems();
211+
}
210212

213+
// If preprocessor has run then replace the problems with ones that are trace aware
211214
for (int index = 0; index < parseProblems.size(); index++) {
212215
final ParseProblem problem = parseProblems.get(index);
213216

tests/org.eclipse.epsilon.egl.engine.test.acceptance/src/org/eclipse/epsilon/egl/test/acceptance/AcceptanceTestUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public static String run(EglTemplateFactory factory, Object program, Model... mo
6464
return run(factory, program, models);
6565
}
6666

67+
public static void parse(Object program) throws Exception {
68+
setup(new EglFileGeneratingTemplateFactory(), program);
69+
}
70+
6771
@SuppressWarnings("restriction")
6872
private static void setup(EglTemplateFactory factory, Object program, IModel... models) throws Exception {
6973
factory.getContext().getModelRepository().addModels(models);

tests/org.eclipse.epsilon.egl.engine.test.acceptance/src/org/eclipse/epsilon/egl/test/acceptance/EglAcceptanceTestSuite.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.eclipse.epsilon.egl.test.acceptance.output.Output;
2424
import org.eclipse.epsilon.egl.test.acceptance.output.lineNumbers.CurrentLineNumber;
2525
import org.eclipse.epsilon.egl.test.acceptance.output.newlines.OutputNewlines;
26+
import org.eclipse.epsilon.egl.test.acceptance.parse.ParseProblemTests;
2627
import org.eclipse.epsilon.egl.test.acceptance.patch.PatchTestSuite;
2728
import org.eclipse.epsilon.egl.test.acceptance.stop.Stop;
2829
import org.eclipse.epsilon.egl.test.acceptance.traceability.Traceability;
@@ -49,7 +50,8 @@
4950
Formatters.class,
5051
PatchTestSuite.class,
5152
OutdentationTests.class,
52-
ImportCachingTests.class})
53+
ImportCachingTests.class,
54+
ParseProblemTests.class})
5355
public class EglAcceptanceTestSuite {
5456

5557
public static Test suite() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 The University of York.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which is available at https://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* Contributors:
8+
* Sam Harris - initial API and implementation
9+
******************************************************************************/
10+
package org.eclipse.epsilon.egl.test.acceptance.parse;
11+
12+
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertFalse;
14+
15+
import java.util.Collection;
16+
17+
import org.eclipse.epsilon.common.parse.problem.ParseProblem;
18+
import org.eclipse.epsilon.egl.test.acceptance.AcceptanceTestUtil;
19+
import org.eclipse.epsilon.egl.util.FileUtil;
20+
import org.junit.Test;
21+
22+
public class ParseProblemTests {
23+
24+
@Test
25+
public void parseProblemReportsCorrectPosition() throws Exception {
26+
final String program = "[*Generate foo*]" + FileUtil.NEWLINE
27+
+ "<h1>[%='foo'[%='foo'%]</h1>";
28+
29+
AcceptanceTestUtil.parse(program);
30+
Collection<ParseProblem> problems = AcceptanceTestUtil.getParseProblems();
31+
32+
assertFalse(problems.isEmpty());
33+
34+
ParseProblem problem = problems.iterator().next();
35+
36+
assertEquals(2, problem.getLine());
37+
assertEquals(13, problem.getColumn());
38+
}
39+
40+
@Test
41+
public void parseProblemReportsCorrectPositionEOF() throws Exception {
42+
final String program = "[*Generate foo*]" + FileUtil.NEWLINE
43+
+ "<h1>[%='foo'%</h1>";
44+
45+
AcceptanceTestUtil.parse(program);
46+
Collection<ParseProblem> problems = AcceptanceTestUtil.getParseProblems();
47+
48+
assertFalse(problems.isEmpty());
49+
50+
ParseProblem problem = problems.iterator().next();
51+
52+
assertEquals(2, problem.getLine());
53+
assertEquals(19, problem.getColumn());
54+
}
55+
}

0 commit comments

Comments
 (0)