Skip to content

Commit

Permalink
Feature/gotestfix (antlr#4168)
Browse files Browse the repository at this point in the history
* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Cater for the fact that some test rules use start as a label or rule name

As a fix for other cvode gen errors when start, end, or exception are used as
label names, they are now translated to have a suffix of `_` at code gen time.
However, the runtime tests sometimes use start as a rule name and so we must now
cater for this in the tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
  • Loading branch information
2 people authored and jimidle committed Mar 10, 2023
1 parent 0067337 commit 4cc4b4a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions runtime-testsuite/test/org/antlr/v4/test/runtime/go/GoRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ protected void initRuntime(RunOptions runOptions) throws Exception {
if (goModFile.exists())
if (!goModFile.delete())
throw new IOException("Can't delete " + goModFile);
Processor.run(new String[] {runtimeToolPath, "mod", "init", "test"}, cachePath, environment);
Processor.run(new String[] {runtimeToolPath, "mod", "edit",
Processor.run(new String[]{runtimeToolPath, "mod", "init", "test"}, cachePath, environment);
Processor.run(new String[]{runtimeToolPath, "mod", "edit",
"-replace=" + GoRuntimeImportPath + "=" + runtimeFilesPath}, cachePath, environment);
cachedGoMod = readFile(cachePath + FileSeparator, "go.mod");
}
Expand All @@ -97,7 +97,18 @@ protected String grammarParseRuleToRecognizerName(String startRuleName) {
return null;
}

return startRuleName.substring(0, 1).toUpperCase() + startRuleName.substring(1);
// The rule name start is now translated to Start_ at runtime to avoid clashes with labels.
// Some tests use start as the first rule name, and we must cater for that
//
String rn = startRuleName.substring(0, 1).toUpperCase() + startRuleName.substring(1);
switch (rn) {
case "Start":
case "End":
case "Exception":
rn += "_";
default:
}
return rn;
}

@Override
Expand Down Expand Up @@ -126,7 +137,7 @@ protected CompiledState compile(RunOptions runOptions, GeneratedState generatedS
writeFile(tempDirPath, "go.mod", cachedGoMod);
Exception ex = null;
try {
Processor.run(new String[] {getRuntimeToolPath(), "mod", "tidy"}, tempDirPath, environment);
Processor.run(new String[]{getRuntimeToolPath(), "mod", "tidy"}, tempDirPath, environment);
} catch (InterruptedException | IOException e) {
ex = e;
}
Expand Down

0 comments on commit 4cc4b4a

Please sign in to comment.