From 8d248aade4194fdf75fd71761dac5fc688d5ec17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 18 May 2026 12:12:13 +0200 Subject: [PATCH 1/4] go.mod: add ourself as a tool go get -tool . About tools, see https://go.dev/doc/modules/gomod-ref#tool --- go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.mod b/go.mod index f657da0..f563cba 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/pointlander/peg go 1.25 + +tool github.com/pointlander/peg From 051eba3b4e0f323ab61cb1a6214892ffda50fe4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 18 May 2026 12:15:37 +0200 Subject: [PATCH 2/4] Use "go tool peg" in "//go:generate" lines in grammars Now that that 'peg' itself is registered as a tool in go.mod we can call it directly via 'go tool peg' in '//go:generate' lines (in grammars): peg will be automatically built (and cached) as necessary. --- grammars/c/c_test.go | 2 +- grammars/calculator/calculator_test.go | 2 +- grammars/calculatorast/calculator_test.go | 2 +- grammars/fexl/fexl_test.go | 2 +- grammars/java/java_test.go | 2 +- grammars/longtest/long_test.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/grammars/c/c_test.go b/grammars/c/c_test.go index 1d93a9b..a5a8422 100644 --- a/grammars/c/c_test.go +++ b/grammars/c/c_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:generate ../../peg -switch -inline c.peg +//go:generate go tool peg -switch -inline c.peg package c diff --git a/grammars/calculator/calculator_test.go b/grammars/calculator/calculator_test.go index 7d87775..eff4f39 100644 --- a/grammars/calculator/calculator_test.go +++ b/grammars/calculator/calculator_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:generate ../../peg -switch -inline calculator.peg +//go:generate go tool peg -switch -inline calculator.peg package calculator diff --git a/grammars/calculatorast/calculator_test.go b/grammars/calculatorast/calculator_test.go index da586b0..0bd3015 100644 --- a/grammars/calculatorast/calculator_test.go +++ b/grammars/calculatorast/calculator_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:generate ../../peg -switch -inline calculator.peg +//go:generate go tool peg -switch -inline calculator.peg package calculatorast diff --git a/grammars/fexl/fexl_test.go b/grammars/fexl/fexl_test.go index 8b4cdf6..7c226c4 100644 --- a/grammars/fexl/fexl_test.go +++ b/grammars/fexl/fexl_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:generate ../../peg -switch -inline fexl.peg +//go:generate go tool peg -switch -inline fexl.peg package fexl diff --git a/grammars/java/java_test.go b/grammars/java/java_test.go index ea6b3a7..20d7838 100644 --- a/grammars/java/java_test.go +++ b/grammars/java/java_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:generate ../../peg -switch -inline java_1_7.peg +//go:generate go tool peg -switch -inline java_1_7.peg package java diff --git a/grammars/longtest/long_test.go b/grammars/longtest/long_test.go index fc36e87..506656e 100644 --- a/grammars/longtest/long_test.go +++ b/grammars/longtest/long_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:generate ../../peg -switch -inline long.peg +//go:generate go tool peg -switch -inline long.peg package longtest From b2d54e227f98f2fe42dc57ee1aec50d7882319a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 18 May 2026 12:28:26 +0200 Subject: [PATCH 3/4] generate-grammars.bash: simplify * Simplify generate-grammars.bash using Go package patterns. * Forward flags to 'go generate' Example: $ ./generate-grammars.bash -n go tool peg -switch -inline c.peg go tool peg -switch -inline calculator.peg go tool peg -switch -inline calculator.peg go tool peg -switch -inline fexl.peg go tool peg -switch -inline java_1_7.peg go tool peg -switch -inline long.peg --- generate-grammars.bash | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/generate-grammars.bash b/generate-grammars.bash index 092d50e..97b4e61 100755 --- a/generate-grammars.bash +++ b/generate-grammars.bash @@ -1,10 +1,3 @@ #!/bin/bash -set -Eeuo pipefail - -(cd grammars/c/ && go generate) -(cd grammars/calculator/ && go generate) -(cd grammars/calculatorast/ && go generate) -(cd grammars/fexl/ && go generate) -(cd grammars/java/ && go generate) -(cd grammars/longtest/ && go generate) +exec go generate "$@" ./grammars/... From 1a1f508592331ac1ea354a60b52fd6dc5b2c2990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 18 May 2026 15:06:03 +0200 Subject: [PATCH 4/4] bootstrap.bash: use 'go tool peg' to run peg Use 'go tool peg' (instead of 'go build && ./peg') to run peg for regenerating peg.peg.go. --- bootstrap.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bootstrap.bash b/bootstrap.bash index 5fcc9c9..b9799f9 100755 --- a/bootstrap.bash +++ b/bootstrap.bash @@ -36,5 +36,4 @@ rm -f peg-bootstrap.peg.go # Build peg cd ../.. ./cmd/peg-bootstrap/peg-bootstrap < peg.peg > peg.peg.go -go build -./peg -inline -switch peg.peg +go tool peg -inline -switch peg.peg