]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/yacc: remove Makefile and build expr using go generate
authorRob Pike <r@golang.org>
Sun, 24 Aug 2014 18:34:45 +0000 (11:34 -0700)
committerRob Pike <r@golang.org>
Sun, 24 Aug 2014 18:34:45 +0000 (11:34 -0700)
It now serves as an example for go generate as well as for yacc.

NOTE: Depends on go generate, which is not yet checked in.
This is a proof of concept of the approach.
That is https://golang.org/cl/125580044.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/125620044

src/cmd/yacc/Makefile [deleted file]
src/cmd/yacc/expr/README [new file with mode: 0644]
src/cmd/yacc/expr/expr.y [moved from src/cmd/yacc/expr.y with 96% similarity]
src/cmd/yacc/expr/main.go [new file with mode: 0644]

diff --git a/src/cmd/yacc/Makefile b/src/cmd/yacc/Makefile
deleted file mode 100644 (file)
index f8c8169..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright 2009 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-TARG=expr$(shell go env GOEXE)
-
-$(TARG): yacc.go expr.y
-       go run yacc.go -p expr expr.y
-       go build -o $(TARG) y.go
-
-clean:
-       rm -f y.go y.output $(TARG)
diff --git a/src/cmd/yacc/expr/README b/src/cmd/yacc/expr/README
new file mode 100644 (file)
index 0000000..302ef57
--- /dev/null
@@ -0,0 +1,20 @@
+This directory contains a simple program demonstrating how to use
+the Go version of yacc.
+
+To build it:
+
+       $ go generate
+       $ go build
+
+or
+
+       $ go generate
+       $ go run expr.go
+
+The file main.go contains the "go generate" command to run yacc to
+create expr.go from expr.y. It also has the package doc comment,
+as godoc will not scan the .y file.
+
+The actual implementation is in expr.y.
+
+The program is not installed in the binary distributions of Go.
similarity index 96%
rename from src/cmd/yacc/expr.y
rename to src/cmd/yacc/expr/expr.y
index 77e9259daedf026771d35cc7fab258561339114f..09451949ff8a49ddae9ac99adce436ad3d78a98a 100644 (file)
 
 %{
 
-// This tag will be copied to the generated file to prevent that file
-// confusing a future build.
-
-// +build ignore
-
 package main
 
 import (
diff --git a/src/cmd/yacc/expr/main.go b/src/cmd/yacc/expr/main.go
new file mode 100644 (file)
index 0000000..8d5b691
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file holds the go generate command to run yacc on the grammar in expr.y.
+// To build expr:
+//     % go generate
+//     % go build
+
+//go:generate -command yacc go tool yacc
+//go:generate yacc -o expr.go -p "expr" expr.y
+
+// Expr is a simple expression evaluator that serves as a working example of
+// how to use Go's yacc implemenation.
+package main