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

Currently, there is no way of enabling debug/verbose error messages
using the goyacc command, despite already having support for them.
This patch adds two flags for enabling both of these during parser
generation.
This commit is contained in:
Andy Yang 2021-04-15 14:17:11 -04:00
Родитель d1362d7aca
Коммит eafb1022cc
1 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -159,6 +159,8 @@ 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() {
@ -166,6 +168,8 @@ func init() {
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
@ -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:], " "))
@ -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)
}
@ -3265,8 +3271,8 @@ var yaccpartext = `
/* parser for yacc output */
var (
$$Debug = 0
$$ErrorVerbose = false
$$Debug = $tflag
$$ErrorVerbose = $eflag
)
type $$Lexer interface {