Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 13 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
.PHONY: all parser clean

ARCH:="`uname -s`"
MAC:="Darwin"
LINUX:="Linux"
all: fmt parser

all: fmt parser.go

test: fmt parser.go
test: fmt parser
sh test.sh

parser.go: parser.y
make parser

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
parser: parser.go hintparser.go

@if [ $(ARCH) = $(LINUX) ]; \
then \
sed -i -e 's|//line.*||' -e 's/yyEofCode/yyEOFCode/' parser.go; \
elif [ $(ARCH) = $(MAC) ]; \
then \
/usr/bin/sed -i "" 's|//line.*||' parser.go; \
/usr/bin/sed -i "" 's/yyEofCode/yyEOFCode/' parser.go; \
fi
%arser.go: prefix = $(@:parser.go=)
%arser.go: %arser.y bin/goyacc
@echo "bin/goyacc -o $@ -p yy$(prefix) -t $(prefix)Parser $<"
@bin/goyacc -o $@ -p yy$(prefix) -t $(prefix)Parser $< || ( rm -f $@ && echo 'Please check y.output for more information' && exit 1 )
@rm -f y.output

@awk 'BEGIN{print "// Code generated by goyacc DO NOT EDIT."} {print $0}' parser.go > tmp_parser.go && mv tmp_parser.go parser.go;
%arser_golden.y: %arser.y
@bin/goyacc -fmt -fmtout $@ $<
@(git diff --no-index --exit-code $< $@ && rm $@) || (mv $@ $< && >&2 echo "formatted $<" && exit 1)

bin/goyacc: goyacc/main.go goyacc/format_yacc.go
GO111MODULE=on go build -o bin/goyacc goyacc/main.go goyacc/format_yacc.go

fmt: bin/goyacc
fmt: bin/goyacc parser_golden.y hintparser_golden.y
@echo "gofmt (simplify)"
@gofmt -s -l -w . 2>&1 | awk '{print} END{if(NR>0) {exit 1}}'
@bin/goyacc -fmt -fmtout parser_golden.y parser.y
@(git diff --no-index --exit-code parser.y parser_golden.y && rm parser_golden.y) || (mv parser_golden.y parser.y && >&2 echo "formatted parser.y" && exit 1)

clean:
go clean -i ./...
rm -rf *.out
rm parser.go
rm -f parser.go hintparser.go
5 changes: 5 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
codecov:
require_ci_to_pass: no
notify:
wait_for_ci: no

coverage:
status:
project:
Expand Down
12 changes: 1 addition & 11 deletions digester.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,7 @@ func (d *sqlDigester) normalize(sql string) {

func (d *sqlDigester) reduceOptimizerHint(tok *token) (reduced bool) {
// ignore /*+..*/
if tok.tok == hintBegin {
for {
tok, _, _ := d.lexer.scan()
if tok == 0 || (tok == unicode.ReplacementChar && d.lexer.r.eof()) {
break
}
if tok == hintEnd {
reduced = true
break
}
}
if tok.tok == hintComment {
return
}

Expand Down
9 changes: 5 additions & 4 deletions goyacc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ var (
oXErrorsGen = flag.String("xegen", "", "generate error from examples source file automatically from the grammar")
oFormat = flag.Bool("fmt", false, "format the yacc file")
oFormatOut = flag.String("fmtout", "golden.y", "yacc formatter output")
oParserType = flag.String("t", "Parser", "name of the parser in the generated yyParse() function")
)

func main() {
Expand Down Expand Up @@ -309,7 +310,7 @@ func main1(in string) (err error) {

p, err := y.ProcessFile(token.NewFileSet(), in, &y.Options{
//NoDefault: *oNoDefault,
AllowConflicts: true,
AllowConflicts: false,
Closures: *oClosures,
LA: *oLA,
Reducible: *oReducible,
Expand Down Expand Up @@ -373,7 +374,7 @@ func main1(in string) (err error) {

// ----------------------------------------------------------- Prologue
f := strutil.IndentFormatter(out, "\t")
mustFormat(f, "// CAUTION: Generated file - DO NOT EDIT.\n\n")
mustFormat(f, "// Code generated by goyacc DO NOT EDIT.\n\n")
mustFormat(f, "%s", injectImport(p.Prologue))
mustFormat(f, `
type %[1]sSymType %i%s%u
Expand Down Expand Up @@ -555,7 +556,7 @@ func %[1]slex1(yylex %[1]sLexer, lval *%[1]sSymType) (n int) {
return n
}

func %[1]sParse(yylex %[1]sLexer, parser *Parser) int {
func %[1]sParse(yylex %[1]sLexer, parser *%[5]s) int {
const yyError = %[2]d

yyEx, _ := yylex.(%[1]sLexerEx)
Expand Down Expand Up @@ -732,7 +733,7 @@ yynewstate:

switch r {%i
`,
*oPref, errSym, *oDlvalf, *oDlval)
*oPref, errSym, *oDlvalf, *oDlval, *oParserType)
for r, rule := range p.Rules {
if rule.Action == nil {
continue
Expand Down
Loading