summaryrefslogtreecommitdiff
path: root/src/cmd/yacc
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2014-06-19 09:22:53 +0200
committerMichael Stapelberg <stapelberg@debian.org>2014-06-19 09:22:53 +0200
commit8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch)
tree4449f2036cccf162e8417cc5841a35815b3e7ac5 /src/cmd/yacc
parentc8bf49ef8a92e2337b69c14b9b88396efe498600 (diff)
downloadgolang-upstream/1.3.tar.gz
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'src/cmd/yacc')
-rw-r--r--src/cmd/yacc/Makefile8
-rw-r--r--src/cmd/yacc/expr.y2
-rw-r--r--src/cmd/yacc/yacc.go15
3 files changed, 21 insertions, 4 deletions
diff --git a/src/cmd/yacc/Makefile b/src/cmd/yacc/Makefile
index 480844805..f8c8169bd 100644
--- a/src/cmd/yacc/Makefile
+++ b/src/cmd/yacc/Makefile
@@ -2,9 +2,11 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-expr: yacc.go expr.y
+TARG=expr$(shell go env GOEXE)
+
+$(TARG): yacc.go expr.y
go run yacc.go -p expr expr.y
- go build -o expr y.go
+ go build -o $(TARG) y.go
clean:
- rm -f y.go y.output expr
+ rm -f y.go y.output $(TARG)
diff --git a/src/cmd/yacc/expr.y b/src/cmd/yacc/expr.y
index 3afffe7ee..77e9259da 100644
--- a/src/cmd/yacc/expr.y
+++ b/src/cmd/yacc/expr.y
@@ -125,7 +125,7 @@ func (x *exprLex) Lex(yylval *exprSymType) int {
case 'รท':
return '/'
- case ' ', '\t', '\n':
+ case ' ', '\t', '\n', '\r':
default:
log.Printf("unrecognized character %q", c)
}
diff --git a/src/cmd/yacc/yacc.go b/src/cmd/yacc/yacc.go
index c53dc3b74..c53403266 100644
--- a/src/cmd/yacc/yacc.go
+++ b/src/cmd/yacc/yacc.go
@@ -49,6 +49,8 @@ import (
"bytes"
"flag"
"fmt"
+ "go/format"
+ "io/ioutil"
"os"
"strings"
"unicode"
@@ -3212,6 +3214,7 @@ func exit(status int) {
if ftable != nil {
ftable.Flush()
ftable = nil
+ gofmt()
}
if foutput != nil {
foutput.Flush()
@@ -3224,6 +3227,18 @@ func exit(status int) {
os.Exit(status)
}
+func gofmt() {
+ src, err := ioutil.ReadFile(oflag)
+ if err != nil {
+ return
+ }
+ src, err = format.Source(src)
+ if err != nil {
+ return
+ }
+ ioutil.WriteFile(oflag, src, 0666)
+}
+
var yaccpar string // will be processed version of yaccpartext: s/$$/prefix/g
var yaccpartext = `
/* parser for yacc output */