Skip to content

Commit

Permalink
[parser] goyacc: fix unstability of generated parser.go (pingcap#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm authored and zz-jason committed Nov 5, 2018
1 parent 19c3ed6 commit 8d7e40b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions parser/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all parser goyacc clean
.PHONY: all parser clean

ARCH:="`uname -s`"
MAC:="Darwin"
Expand All @@ -9,7 +9,7 @@ all: parser.go
parser.go: parser.y
make parser

parser: goyacc
parser: bin/goyacc
bin/goyacc -o /dev/null parser.y
bin/goyacc -o parser.go parser.y 2>&1 | egrep "(shift|reduce)/reduce" | awk '{print} END {if (NR > 0) {print "Find conflict in parser.y. Please check y.output for more information."; exit 1;}}'
rm -f y.output
Expand All @@ -23,9 +23,9 @@ parser: goyacc
/usr/bin/sed -i "" 's/yyEofCode/yyEOFCode/' parser.go; \
fi

@awk 'BEGIN{print "// Code generated by goyacc"} {print $0}' parser.go > tmp_parser.go && mv tmp_parser.go parser.go;
@awk 'BEGIN{print "// Code generated by goyacc DO NOT EDIT."} {print $0}' parser.go > tmp_parser.go && mv tmp_parser.go parser.go;

goyacc:
bin/goyacc: goyacc/main.go
go build -o bin/goyacc goyacc/main.go

clean:
Expand Down
10 changes: 9 additions & 1 deletion parser/goyacc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,15 @@ func (s symsUsed) Less(i, j int) bool {
return false
}

return strings.ToLower(s[i].sym.Name) < strings.ToLower(s[j].sym.Name)
caseFoldedCompare := strings.Compare(strings.ToLower(s[i].sym.Name), strings.ToLower(s[j].sym.Name))
if caseFoldedCompare < 0 {
return true
}
if caseFoldedCompare > 0 {
return false
}

return s[i].sym.Name < s[j].sym.Name
}

func main1(in string) (err error) {
Expand Down
16 changes: 8 additions & 8 deletions parser/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d7e40b

Please sign in to comment.