Skip to content

cmd/goyacc: add flags for enabling debug and verbose error messages #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions cmd/goyacc/yacc.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,17 @@ var fmtImported bool // output file has recorded an import of "fmt"
var oflag string // -o [y.go] - y.go file
var vflag string // -v [y.output] - y.output file
var lflag bool // -l - disable line directives
var tflag int // -t - set debug message level
var eflag bool // -e - enable verbose error messages
var prefix string // name prefix for identifiers, default yy

func init() {
flag.StringVar(&oflag, "o", "y.go", "parser output")
flag.StringVar(&prefix, "p", "yy", "name prefix to use in generated code")
flag.StringVar(&vflag, "v", "y.output", "create parsing tables")
flag.BoolVar(&lflag, "l", false, "disable line directives")
flag.IntVar(&tflag, "t", 0, "set debug message level")
flag.BoolVar(&eflag, "e", false, "enable verbose error messages")
}

var initialstacksize = 16
Expand Down Expand Up @@ -385,6 +389,8 @@ func setup() {
usage()
}
yaccpar = strings.Replace(yaccpartext, "$$", prefix, -1)
yaccpar = strings.Replace(yaccpar, "$tflag", strconv.Itoa(tflag), 1)
yaccpar = strings.Replace(yaccpar, "$eflag", strconv.FormatBool(eflag), 1)
openup()

fmt.Fprintf(ftable, "// Code generated by goyacc %s. DO NOT EDIT.\n", strings.Join(os.Args[1:], " "))
Expand Down Expand Up @@ -3094,7 +3100,7 @@ func chcopy(q string) string {
}

func usage() {
fmt.Fprintf(stderr, "usage: yacc [-o output] [-v parsetable] input\n")
fmt.Fprintf(stderr, "usage: yacc [-o output] [-v parsetable] [-p prefix] [-l] [-e] [-t debuglevel] input\n")
exit(1)
}

Expand Down Expand Up @@ -3265,8 +3271,8 @@ var yaccpartext = `
/* parser for yacc output */

var (
$$Debug = 0
$$ErrorVerbose = false
$$Debug = $tflag
$$ErrorVerbose = $eflag
)

type $$Lexer interface {
Expand Down