Skip to content

Commit acd7411

Browse files
committed
Add debug-ability to yacc code
1 parent 431305f commit acd7411

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

parser/lexer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,11 @@ func (x *yyLex) Error(s string) {
650650
log.Printf("State %#v", x)
651651
}
652652

653+
// Set the debug level 0 = off, 4 = max
654+
func SetDebug(level int) {
655+
yyDebug = level
656+
}
657+
653658
// Parse a file
654659
func Parse(in io.Reader) {
655660
yyParse(NewLex(in))

parser/testparser/testparser.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010
)
1111

1212
var (
13-
lex = flag.Bool("l", false, "Lex the file only")
13+
lex = flag.Bool("l", false, "Lex the file only")
14+
debugLevel = flag.Int("d", 0, "Debug level 0-4")
1415
)
1516

1617
func main() {
1718
flag.Parse()
19+
parser.SetDebug(*debugLevel)
1820
for _, path := range flag.Args() {
1921
if *lex {
2022
fmt.Printf("Lexing %q\n", path)

0 commit comments

Comments
 (0)