-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.go
43 lines (34 loc) · 1.08 KB
/
test.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
package main
import (
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
"os"
"testrig/test"
)
func main() {
testRun("input")
}
func testRun(inf string) {
// Pre-initialize so that we can distinguish this initialization from the lexing nad parsing rules
test.TestLexerInit()
test.TestParserInit()
input, err := antlr.NewFileStream(inf)
if err != nil {
fmt.Println("Error opening file '", inf, "'", err)
os.Exit(1)
}
lexer := test.NewtestLexer(input)
stream := antlr.NewCommonTokenStream(lexer, 0)
p := test.NewtestParser(stream)
// Add a diagnostic listener to get messages about conflicts in the grammar - debug only!
//
p.AddErrorListener(antlr.NewDiagnosticErrorListener(true))
// We want the tree, as we are going to check it for semantics, then execute it
//
p.BuildParseTrees = true
tree := p.Query()
// Perform the semantic checks
//
antlr.ParseTreeWalkerDefault.Walk(test.NewSemanticListener(), tree)
// Here we can execute the tree with a different listener
}