From bddf28b68ff814a74ba465693d2c7b57995e85d1 Mon Sep 17 00:00:00 2001 From: Kyle Xiao Date: Fri, 10 Jan 2025 13:43:24 +0800 Subject: [PATCH] runtime(go): minimum requirement go1.18 golang.org/x/exp, which requires newer go version, is too heavy for previous implementation Signed-off-by: Kyle Xiao --- .github/workflows/hosted.yml | 4 ++-- .../test/org/antlr/v4/test/runtime/go/GoRunner.java | 5 +++++ runtime/Go/antlr/v4/go.mod | 4 +--- runtime/Go/antlr/v4/go.sum | 4 ---- runtime/Go/antlr/v4/lexer_action_executor.go | 11 ++++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/hosted.yml b/.github/workflows/hosted.yml index 49ab9b62f7..5167da7f2c 100644 --- a/.github/workflows/hosted.yml +++ b/.github/workflows/hosted.yml @@ -21,7 +21,7 @@ jobs: fail-fast: false matrix: os: [ - macos-12, + macos-13, ubuntu-20.04, windows-2022 ] @@ -160,7 +160,7 @@ jobs: fail-fast: false matrix: os: [ - macos-12, + macos-13, ubuntu-20.04, windows-2022 ] diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/GoRunner.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/GoRunner.java index 69943126e9..6ffd0a86b1 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/GoRunner.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/GoRunner.java @@ -142,6 +142,11 @@ protected CompiledState compile(RunOptions runOptions, GeneratedState generatedS // Exception ex = null; if (cachedGoSum == null) { + // We need to write an empty go.sum file because `go mod tidy` may not generate it if there is no dependency. + // Or it will casue `java.io.FileNotFoundException` when readFile below + // + writeFile(getTempDirPath(), "go.sum", ""); + try { Processor.run(new String[]{getRuntimeToolPath(), "mod", "tidy"}, getTempDirPath(), environment); } catch (InterruptedException | IOException e) { diff --git a/runtime/Go/antlr/v4/go.mod b/runtime/Go/antlr/v4/go.mod index cc695e09ba..c0a8196b4b 100644 --- a/runtime/Go/antlr/v4/go.mod +++ b/runtime/Go/antlr/v4/go.mod @@ -1,5 +1,3 @@ module github.com/antlr4-go/antlr/v4 -go 1.20 - -require golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc +go 1.18 diff --git a/runtime/Go/antlr/v4/go.sum b/runtime/Go/antlr/v4/go.sum index 5bdfc81b53..e69de29bb2 100644 --- a/runtime/Go/antlr/v4/go.sum +++ b/runtime/Go/antlr/v4/go.sum @@ -1,4 +0,0 @@ -golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= -golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= -golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU= -golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= diff --git a/runtime/Go/antlr/v4/lexer_action_executor.go b/runtime/Go/antlr/v4/lexer_action_executor.go index dfc28c32b3..76f943feb3 100644 --- a/runtime/Go/antlr/v4/lexer_action_executor.go +++ b/runtime/Go/antlr/v4/lexer_action_executor.go @@ -4,8 +4,6 @@ package antlr -import "golang.org/x/exp/slices" - // Represents an executor for a sequence of lexer actions which traversed during // the Matching operation of a lexer rule (token). // @@ -167,7 +165,10 @@ func (l *LexerActionExecutor) Equals(other interface{}) bool { if len(l.lexerActions) != len(othert.lexerActions) { return false } - return slices.EqualFunc(l.lexerActions, othert.lexerActions, func(i, j LexerAction) bool { - return i.Equals(j) - }) + for i, v := range l.lexerActions { + if !v.Equals(othert.lexerActions[i]) { + return false + } + } + return true }