-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug.go
71 lines (57 loc) · 1.52 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"github.com/mbStavola/slydes/pkg/lang"
"github.com/mbStavola/slydes/pkg/types"
"io"
)
// Wrap the provided stages with verbose loggers
func debugSly(sly lang.Sly) lang.Sly {
return lang.Sly{
Lexer: debugLexer{Lexer: sly.Lexer},
Parser: debugParser{Parser: sly.Parser},
Compiler: debugCompiler{Compiler: sly.Compiler},
}
}
type debugLexer struct {
Lexer lang.Lexer
}
func (l debugLexer) Lex(reader io.Reader) ([]lang.Token, error) {
tokens, err := l.Lexer.Lex(reader)
if err != nil {
return tokens, err
}
fmt.Println("==================================")
fmt.Println("Lexing Stage")
fmt.Println("==================================")
fmt.Printf("%v\n\n", tokens)
return tokens, nil
}
type debugParser struct {
Parser lang.Parser
}
func (p debugParser) Parse(tokens []lang.Token) ([]lang.Statement, error) {
statements, err := p.Parser.Parse(tokens)
if err != nil {
return statements, err
}
fmt.Println("==================================")
fmt.Println("Parsing Stage")
fmt.Println("==================================")
fmt.Printf("%v\n\n", statements)
return statements, nil
}
type debugCompiler struct {
Compiler lang.Compiler
}
func (c debugCompiler) Compile(statements []lang.Statement) (types.Show, error) {
show, err := c.Compiler.Compile(statements)
if err != nil {
return show, err
}
fmt.Println("==================================")
fmt.Println("Compilation Stage")
fmt.Println("==================================")
fmt.Printf("%v\n\n", show)
return show, nil
}